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":3413,"date":"2011-06-14T20:46:05","date_gmt":"2011-06-15T01:46:05","guid":{"rendered":"http:\/\/www.calculatinginvestor.com\/?p=3413"},"modified":"2011-09-22T13:21:29","modified_gmt":"2011-09-22T18:21:29","slug":"efficient-frontier-part-2","status":"publish","type":"post","link":"https:\/\/www.calculatinginvestor.com\/2011\/06\/14\/efficient-frontier-part-2\/","title":{"rendered":"Calculating the Efficient Frontier: Part 2"},"content":{"rendered":"
A Matrix Based Approach for Calculating Portfolio Weights<\/h6>\n

In a previous post, I showed how to calculate and plot the efficient frontier for a set of risky assets<\/a>.\u00a0In this post, I extend the previous example and show how to use Octave or Matlab to calculate the portfolio\u00a0weights\u00a0for each of\u00a0the various risky assets for\u00a0any point on the efficient frontier.<\/p>\n

In my next post, I’ll conclude this series on the efficient frontier by adding a risk free asset, \u00a0showing the calculation for the\u00a0tangency portfolio, and demonstrating how this creates a new frontier.<\/p>\n

Calculating the Weights for Key Points on the Efficient Frontier<\/h6>\n

We can calculate the weights for any point on the efficient frontier\u00a0once we\u00a0know the weights for any two points on the efficient frontier.<\/p>\n

Two easy points to calculate are the global minimum variance portfolio and the tangency portfolio for the case where\u00a0the risk free rate is assumed to be zero.<\/p>\n

Global Minimum Variance Portfolio<\/strong><\/p>\n

A point of particular interest on the efficient frontier is the “global minimum variance portfolio”.\u00a0 This portfolio is the point on the efficient frontier which has the minimum variance or standard deviation.<\/p>\n

We can solve for the mean and variance of the global minimum variance portfolio by setting the derivative of the equation for the variance to zero and solving for \"\mu\".\u00a0 The equations for calculating the A,B,C and \"\Delta\" values\u00a0are given in the previous post<\/a>.<\/p>\n

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

Setting the derivative with respect to \"\mu\" to zero gives:<\/p>\n

\"0=\frac{2A\mu-2B}{\Delta}\"<\/p>\n

Running through all the algebra gives:<\/p>\n

\"\mu_{g}=\frac{B}{A}\"<\/p>\n

\"\sigma^{2}_{g}=\frac{1}{A}\"<\/p>\n

Finally, the portfolio weights for the global minimum variance portfolio are given by:<\/p>\n

\"\mathbf{w_{g}}=\frac{\mathbf{S^{-1}1}}{A}\"<\/p>\n

Calculating a Second Point on Efficient Frontier (Tangency Portfolio with R=0%)<\/strong><\/p>\n

We need two points on the efficient frontier to calculate any other point. \u00a0We have the global minimum variance portfolio as a first point, and a second easy point to calculate is the tangency portfolio for the case where the risk-free rate is set to zero.<\/p>\n

The equations for the expected return, standard deviations, and weights for this portfolio are given below:<\/p>\n

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

\"\mu_{d}=\mathbf{w_{d}^{'}\bar{z}}\"<\/p>\n

\"\sigma_{d}^{2}=\mathbf{w_{d}^{'}Sw_d}\"<\/p>\n

The Two-Fund Separation Theorem<\/h6>\n

The two fund separation theorem states that all minimum variance portfolios on the efficient frontier \u00a0are combinations of only two distinct portfolios.\u00a0 So, any two points on the mean variance frontier will span the set.<\/p>\n

To calculate any point on the frontier, we can use the minimum variance portfolio and the tangency portfolio when R=0, but as a first step we need to calculate two intermediate values using the target expected return or \"\mu\":<\/p>\n

\"\lambda=\frac{C-\mu B}{\Delta}\"<\/p>\n

\"\gamma=\frac{\mu A-B}{\Delta}\"<\/p>\n

With these values, and the portfolio weights for the two portfolios calculated above, we can find the weights for any point on the efficient frontier.<\/p>\n

\"\mathbf{w^{*}}=\left ( \lambda A \right )\mathbf{w_{g}} + \left (\gamma B \right )\mathbf{w_d}\"<\/p>\n

Portfolio Weights Example<\/h6>\n

As an example, we can use the four assets which I used for the example in the previous post.\u00a0 As a reminder, the expected\u00a0returns and covariance matrix for these assets are shown below:<\/p>\n

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

\"<\/p>\n

Using\u00a0these assets, we can use the equations shown above to calculate the portfolio weights for the two reference portfolios, and we can then\u00a0use these two portfolios to calculate portfolio weights for any point on the efficient frontier.<\/p>\n

Global Minimum Variance Portfolio:<\/strong><\/p>\n

The equations presented above are implemented in an Octave script, and the portfolio weights, standard deviation, and expected return for the Global Minimum Variance Portfolio are shown below.\u00a0 Note that a negative portfolio weight indicates a short position in that security.<\/p>\n

\"\mathbf{w_{g}}=\begin{bmatrix}<\/p>\n

\"\mu_{g}=7.60\%\"<\/p>\n

\"\sigma^{2}_{g}=20.69\"<\/p>\n

\"\sigma_{g}=4.55\%\"<\/p>\n

Note that this standard deviation is the minimum standard deviation for any point on the efficient frontier.<\/p>\n

Tangency Portfolio when R=0:<\/strong><\/p>\n

The portfolio weights, standard deviation, and expected return for the\u00a0tangency portfolio when the risk free rate (R) is assumed to be zero\u00a0are shown here.<\/p>\n

\"\mathbf{w_{d}}=\begin{bmatrix}<\/p>\n

\"\mu_{d}=8.51\%\"<\/p>\n

\"\sigma^{2}_{d}=23.16\"<\/p>\n

\"\sigma_{d}=4.81\%\"<\/p>\n

Calculating Portfolio Weights for an Arbitrary Expected Return:<\/strong><\/p>\n

For this example, we\u00a0will assume that our target portfolio return is 14%.<\/p>\n

Using this target return, the target portfolio weights can be calculated.\u00a0 \u00a0Again, remember that a negative portfolio weight indicates a short position in that security.<\/p>\n

\"\mathbf{w^{*}}=\begin{bmatrix}<\/p>\n

\"\mu^{*}=14.00\%\"<\/p>\n

\"\sigma_{*}^{2}=143.72\"<\/p>\n

\"\sigma^{*}=11.99\%\"<\/p>\n

Plot of Efficient Frontier with Key Points:<\/strong><\/p>\n

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

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

The script below can be run in Matlab or Octave to calculate, plot, and\u00a0determine\u00a0portfolio weights for any point on the efficient frontier.<\/p>\n

By updating the expected returns (‘zbar’) and covariance matrix (‘S”), the script\u00a0can be used to\u00a0compute and plot the efficient frontier for any desired set of assets.\u00a0 It\u00a0will\u00a0also calculate the portfolio weights for a point on the efficient frontier with a specified target return (‘mu_tar’).\u00a0 The portfolio weights will be returned in the variable ‘w_s’.<\/p>\n

\r\nclear all;\r\nclose all;\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Mean Variance Optimizer Inputs (Update this section with your own inputs)\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\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% Target Return\r\nmu_tar = 14\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Calculating Variables\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\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\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% Calculate Lambda and Gamma\r\nlambda_target = (C - mu_tar*B)\/D;\r\ngamma_target =  (mu_tar*A-B)\/D;\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Efficient Frontier\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\nmu = 1:200;\r\nmu = mu\/10;\r\n\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\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Global Minimum Variance Portfolio\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n% Mean and Variance of Global Minimum Variance Portfolio\r\nmu_g = B\/A\r\nvar_g = 1\/A\r\nstd_g = sqrt(var_g)\r\n\r\n% Minimum Variance Portfolio Weights\r\nw_g = (S^-1*unity)\/A\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Tangency Portfolio with a Risk Free Rate = 0\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n% Weights for Tangency Portfolio, R=0\r\nw_d = (S^-1*zbar)\/B;\r\n\r\n% Expected Return of Tangency Portfolio\r\nmu_d = w_d'*zbar;\r\n\r\n% Variance and Standard Deviation of Tangency Portfolio\r\nvar_d = w_d'*S*w_d;\r\nstd_d = sqrt(var_d);\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Portfolio with Expected Return = 14%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n% Weights for portfolio with target return = 14%\r\n\r\nw_s = (lambda_target*A)*w_g + (gamma_target*B)*w_d;\r\n\r\n% Expected Return of Target Portfolio (should match target)\r\nmu_s = w_s'*zbar;\r\n\r\n% Variance and Standard Deviation of target portfolio\r\nvar_s = w_s'*S*w_s;\r\nstd_s = sqrt(var_s);\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n% Plot Efficient Frontier and Key Points\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\nfigure\r\nplot(minstd,mu,'linewidth',2,std_d,mu_d,'*','linewidth',2,std_g,mu_g,'x','linewidth',2,std_s,mu_s,'o','linewidth',2)\r\ntext(0.5+std_g,mu_g,'Global Minimum Variance Portfolio','fontsize',14);\r\ntext(0.5+std_d,mu_d,'Tangency Portfolio when R=0','fontsize',14);\r\ntext(0.5+std_s,mu_s,'Portfolio with Target Return of 14%','fontsize',14);\r\ntitle('Efficient Frontier with Selected Portfolios','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 Approach for Calculating Portfolio Weights In a previous post, I showed how to calculate and plot the efficient frontier for a set of risky assets.\u00a0In this post, I extend the previous example and show how to use Octave or Matlab to calculate the portfolio\u00a0weights\u00a0for each of\u00a0the various risky assets for\u00a0any point on […]<\/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\/3413"}],"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=3413"}],"version-history":[{"count":130,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/posts\/3413\/revisions"}],"predecessor-version":[{"id":3775,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/posts\/3413\/revisions\/3775"}],"wp:attachment":[{"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/media?parent=3413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/categories?post=3413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.calculatinginvestor.com\/wp-json\/wp\/v2\/tags?post=3413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}