Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 580

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 583

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 586

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 589

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php on line 592

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673

Warning: Cannot modify header information - headers already sent by (output started at /home/calcul9/public_html/wp-content/themes/suffusion/functions/media.php:580) in /home/calcul9/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1673
{"id":3297,"date":"2011-06-07T17:14:50","date_gmt":"2011-06-07T22:14:50","guid":{"rendered":"http:\/\/www.calculatinginvestor.com\/?p=3297"},"modified":"2011-06-07T17:14:51","modified_gmt":"2011-06-07T22:14:51","slug":"efficient-frontier-1","status":"publish","type":"post","link":"https:\/\/www.calculatinginvestor.com\/2011\/06\/07\/efficient-frontier-1\/","title":{"rendered":"Calculating the Efficient Frontier: Part 1"},"content":{"rendered":"
<\/a>A Matrix Based\u00a0Example of\u00a0 Mean-Variance Optimization using Octave<\/h6>\n

The concept of\u00a0 an “efficient frontier” was developed by Harry Markowitz in the 1950s.\u00a0 The efficient frontier shows us the minimum risk (i.e. standard deviation) that can be achieved at each level of expected return for a given set of risky securities.<\/p>\n

Of course, to calculate the efficient frontier, we need to have an estimate of the expected returns and the covariance matrix for the set of risky securities which will used to build the optimal portfolio.\u00a0 These parameters are difficult (impossible) to\u00a0forecast, and the optimal\u00a0portfolio\u00a0calculation is\u00a0extremely sensitive to these parameters.\u00a0 For this reason, an efficient frontier based portfolio is difficult to successfully implement in practice.\u00a0 However, a familiarity with the concept is still very useful and will help to develop intuition about diversification and the relationship between risk and return.<\/p>\n

Calculating the Efficient Frontier<\/strong><\/h6>\n

In this post, I’ll demonstrate how to calculate and plot\u00a0the efficient frontier using the expected returns and covariance matrix for a set of securities.<\/p>\n

In a future post, I’ll demonstrate how to calculate the security\u00a0weights for\u00a0various points on this efficient frontier using the two-fund separation theorem.<\/p>\n

Calculations<\/strong><\/h6>\n

In order to calculate the efficient frontier using n assets, we need two inputs.\u00a0 First, we need the expected returns of each asset.\u00a0 The vector of expected returns will be designated \"\bar{\mathbf{z}}\".\u00a0 The second input is the variance-covariance matrix for the n\u00a0assets.\u00a0 This covariance matrix will be designated as \"\mathbf{S}\".\u00a0 We also need a unity vector (\"\mathbf{1}\")\u00a0with the same length as the vector \"\bar{\mathbf{z}}\".<\/p>\n

Once we have this information, we can run the following calculations using a matrix based mathematical program such as Octave or Matlab.<\/p>\n

\"A=\mathbf{{1}'S^{-1}1}>0\"<\/p>\n

\"B=\mathbf{{1}'S^{-1}\bar{z}}\"<\/p>\n

\"C=\mathbf{{\bar{z}}'S^{-1}\bar{z}}\"<\/p>\n

\"\Delta =AC-B^{2}>0\"<\/p>\n

Using these values, the variance (\"\sigma^2\") at each level of expected return (\"\mu\") is given by this equation:<\/p>\n

\"\sigma^2=\frac{A\mu^2-2B\mu+C}{\Delta}\"<\/p>\n

You can see from the equation, that the efficient frontier is a parabola in mean-variance space.<\/p>\n

Using the standard deviation (\"\sigma\") rather than the variance, we have:<\/p>\n

\"\sigma=\sqrt{\frac{A\mu^2-2B\mu+C}{\Delta}}\"<\/p>\n

Example using Octave Script<\/h6>\n

As an example, lets consider four securities, A,B,C and D, with expected returns of 14%, 12%, 15%, and 7%.\u00a0 The expected return vector is:<\/p>\n

\"\mathbf{\bar{z}}=\begin{bmatrix}<\/p>\n

The covariance matrix for our example is shown below.\u00a0 In practice, the historical covariance matrix can be calculated by reading the historical returns into Octave or Matlab and using the cov(X)<\/em> command.\u00a0Note that the diagonal of the matrix is the variance of our four securities.\u00a0 So, if we take the square root of the diagonal, we can calculate the standard deviation of each asset (13.6%, 14%, 20.27%, and 5%).<\/p>\n

\"<\/p>\n

The example script for computing the efficient frontier from these inputs is shown at the end of this post. \u00a0It can be modified for any number of assets by updating the expected return vector and the covariance matrix.<\/p>\n

The\u00a0plot\u00a0of the efficient frontier for our four assets is shown here:<\/p>\n

\"\"<\/a><\/p>\n

Derivation and References<\/h6>\n

Deriving the approach I have shown is beyond the scope of this post.\u00a0 However, for those who want to dive into the linear algebra, there are several excellent examples available\u00a0online.<\/p>\n

Derivation of Mean-Variance Frontier Equation using the Lagrangian <\/a>(The Appendix B\u00a0result is identical to what I show above, but the notation is a little different)<\/p>\n

Old school derivation by a young professor who later went on to win a Nobel prize<\/a><\/p>\n

Octave Code:<\/strong><\/p>\n

This script\u00a0will also work in Matlab, but I’ve chosen to use Octave since it is opensource and available for free.<\/p>\n

\r\n% Mean Variance Optimizer\r\n\r\n% S is matrix of security covariances\r\nS = [185 86.5 80 20; 86.5 196 76 13.5; 80 76 411 -19; 20 13.5 -19 25]\r\n\r\n% Vector of security expected returns\r\nzbar = [14; 12; 15; 7]\r\n\r\n% Unity vector..must have same length as zbar\r\nunity = ones(length(zbar),1)\r\n\r\n% Vector of security standard deviations\r\nstdevs = sqrt(diag(S))\r\n\r\n% Calculate Efficient Frontier\r\nA = unity'*S^-1*unity\r\nB = unity'*S^-1*zbar\r\nC = zbar'*S^-1*zbar\r\nD = A*C-B^2\r\n\r\n% Efficient Frontier\r\nmu = (1:300)\/10;\r\n\r\n% Plot Efficient Frontier\r\nminvar = ((A*mu.^2)-2*B*mu+C)\/D;\r\nminstd = sqrt(minvar);\r\n\r\nplot(minstd,mu,stdevs,zbar,'*')\r\ntitle('Efficient Frontier with Individual Securities','fontsize',18)\r\nylabel('Expected Return (%)','fontsize',18)\r\nxlabel('Standard Deviation (%)','fontsize',18)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

A Matrix Based\u00a0Example of\u00a0 Mean-Variance Optimization using Octave The concept of\u00a0 an “efficient frontier” was developed by Harry Markowitz in the 1950s.\u00a0 The efficient frontier shows us the minimum risk (i.e. standard deviation) that can be achieved at each level of expected return for a given set of risky securities. Of course, to calculate the […]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/posts\/3297"}],"collection":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/comments?post=3297"}],"version-history":[{"count":113,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/posts\/3297\/revisions"}],"predecessor-version":[{"id":3412,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/posts\/3297\/revisions\/3412"}],"wp:attachment":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/media?parent=3297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/categories?post=3297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/tags?post=3297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}