56

Don’t Put All Your Eggs in One Basket

 4 years ago
source link: https://www.tuicool.com/articles/7nMBR3f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The Model

The purpose is to determine what fraction of a portfolio to invest in each of several possible assets with the goal of minimizing the volatility of the portfolio, subject to a target return.

To frame the question mathematically, suppose f is an n -dimensional vector of the fractions that I’ll invest in each of n financial assets. And let C denote the covariance matrix of the daily returns of the assets, an n x n matrix. Let r be the n- dimensional vector of the expected returns of each of the assets. The target return is determined by r*.

The optimization problem to solve is:

UrQZziE.png!web

Since we want to minimize the function for the volatility of the portfolio (the risk level), the three constraints of the problem are:

  • The sum of the fractions should add up to one.
  • The portfolio should attain the target return, r* .
  • Each stock’s fraction should be less than 100%.

Because the objective function that we want to minimize is a quadratic, this class of problem is called a quadratic program in the operations research and numerical optimization community. It’s important to note that because it’s a convex function , there’s always a unique solution.

The Data

I used a dataset ² of stock prices between February 20 and April 18, 2019. I selected a few stocks in the tech industry — AMZN, GOOGL, MSFT, IBM, FB and NFLX (Amazon, Google, Microsoft, IBM, Facebook and Netflix) — and created a chart to visualize their correlation:

MfaqQr2.png!webRV367nf.png!web

Most of the stocks are strongly correlated, with the exception of Netflix (NFLX), but remember this is only a 2-month period.

The Optimal Portfolio Allocation

To solve the problem, I needed to compute the covariance matrix C of the daily returns and the estimate returns r for each of the stocks in the S&P500 index. I decided to use 9% as my target return.

Once I computed the expected returns and the expected volatilities (and covariances) of the daily returns, I was ready to solve the optimization problem.

Visit this repo to see my Python code, which will run as-is on Watson Studio Desktop. (You will just need to get the dataset into your project.) Here’s a snippet:

uy22uuB.jpg!web

The optimization model chose a total of 28 stocks out of the 500 stocks in the S&P500 index, including these as the top 3:

  1. COTY — 11.14%
  2. SRE — 9.14%
  3. CHD — 8.74%
M7Jf63f.png!webMn6RJrA.png!web
Portfolio Optimal Allocation

To solve the optimization problem, I used the decision optimization tool CPLEX from Python, inspired on a notebook from the CPLEX github repo³.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK