









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The monthly means and covariance matrix of the returns are computed and these are referenced as the input data on the portfolio tab as ...
Typology: Study notes
1 / 16
This page cannot be seen from the preview
Don't miss anything!
This note outlines how to use the solver and matrix algebra in Excel to compute efficient portfolios. The example used in this note is in the spreadsheet 3firmExample.xlsx, and is the same example used in the lecture notes titled “Portfolio Theory with Matrix Algebra”. Last updated: November 24, 2009
The solver is an Excel Add‐In created by Frontline Systems (www.solver.com) that can be used to solve general optimization problems that may be subject to certain kinds of constraints. In this note we show how it can be used to find portfolios that minimize risk subject to certain constraints. The solver add‐in must be activated before it can be used within Excel. In Excel 2007, you activate add‐ ins by clicking on the office button and then clicking on the Excel Options box at the bottom of the menu.
This opens the Excel options dialogue box. Click Add‐Ins, which displays the available Add‐Ins for Excel. Make sure the Solver Add‐In is an Active Application Add‐In.
Excel has several built‐in array formulas that can perform basic matrix algebra operations. The main functions are listed in table below Array Function Description MINVERSE Compute inverse of matrix MMULT Matrix multiplication TRANSPOSE Compute transpose of matrix To evaluate an array function in Excel, you must use the magic key stoke combination:
In the Data tab of the spreadsheet 3firmExample.xls is the example monthly return data on three assets: Microsoft, Nordstrom and Starbucks. The monthly means and covariance matrix of the returns are computed and these are referenced as the input data on the portfolio tab as illustrated in the screen shot below.
The range of cells D10:D12 is called mvec and will contain the weights in the minimum variance portfolio once the solver is run and the solution to the optimization problem is found. Before the solver is to be run, these cells should contain an initial guess of the minimum variance portfolio. A simple guess for
To use the solver, a cell containing the function to be maximized or minimized must be specified. Here, this cell is F10 which contains the array formula {=MMULT(TRANSPOSE(mvec),MMULT(sigma,mvec))} which evaluates the matrix algebra formula for the variance of a portfolio: σ (^2) p m , = m ′ Σ m. Notice that the formula is surrounded by curly braces {}. This indicates that
This formula is specified in cell E10 as =SUM(mvec) The solver add‐in is located on the data tab of the top menu ribbon in the right hand corner. To run the solver, click the cell containing the formula you want to optimize (cell F10, and named sig2px) and then click on the solver button. This will open up the solver dialogue box as shown below.
The field named Set Target Cell must contain either the name or the reference to the cell containing the formula to optimize. You have three choices for the type of optimization: Max, Min and Value of. Here, we want to minimize the portfolio variance so Min should be selected. Next, we must specify the cells containing the variables which are being optimized. These are specified in the By Changing Cells field. Here, we can type in the name mvec or specify the range of cells D10:D12. Finally, we must Add the constraint that the weights sum to one. We do this by clicking the Add button, which opens the Add Constraint dialogue box show below. The Cell Reference contains the cell (E10) that has the formula for the constraint
everything is filled in, click OK to go back to the solver dialogue. The complete dialogue should look like one shown below.
The global minimum variance portfolio has 44% in Microsoft, 36% in Nordstrom and 19% in Starbucks. The expected return on this portfolio is given in cell C13 (called mupx) and is computed using the formula μ p m , = m ′ μ. The Excel array formula is {=MMULT(TRANSPOSE(mvec),muvec)} The portfolio standard deviation in cell C14 is the square root of the portfolio variance, sig2px, in cell F10.
A minimum variance portfolio with target expected return equal to μ 0 solves the optimization problem 2 min y σ p y , = y ′ Σ^ y s.t. y ′μ^ = μ 0 and y ′ 1 = 1 This optimization problem can also be easily solved using the solver with matrix algebra functions. The screenshot below shows how to set‐up this optimization problem in Excel where the target expected return is the expected return on Microsoft (4.27%).
The range of cells K10:K12 is called yvec and will contain the weights in the efficient portfolio once the solver is run and the solution to the optimization problem is found. Before the solver is to be run, these cells should contain an initial guess of the minimum variance portfolio. A simple guess for this vector
portfolio variance, σ (^2) p y , = y ′Σ y , is in cell O10 which contains the array formula {=MMULT(TRANSPOSE(yvec),MMULT(sigma,yvec))} We also need two additional cells to contain formulas that will be used to impose the constraints that the portfolio expected return is equal to the target return, μ (^) p y , = y ′μ =μ 0 , and that the portfolio
which contain the Excel formulas =SUM(yvec) and {=MMULT(TRANSPOSE(yvec),muvec)}, respectively. To run the solver, click cell O10 (called sig2py) and then click on the solver button. Make sure the solver dialogue box is filled out to look like the one below.
for any constant α is also an efficient portfolio. The expected return and variance of this portfolio are , , , 2 2 2 2 2 , , ,
p z p m p y p z p m p y my μ α μ α μ σ α σ α σ α α σ
where the covariance between the returns on portfolios m and y is computed using σ (^) my = m ′Σ y. To create the efficient frontier, create a grid of α values starting at 1 and decrease in increments of 0.1. Use as many values in the grid as necessary to make a nice plot. A screenshot of the part of the spreadsheet to create these portfolios is shown below.
portfolio. The cell P20 contains the formula =N20mupx+O20mupy for the expected portfolio return, and the cell Q20 contains the formula =N20^2sig2px+O20^2sig2py+2N20O20sigmaxy for the portfolio variance. The covariance term sigmaxy is computed in the cell R9 (not shown) which contains the array formula {=MMULT(MMULT(TRANSPOSE(mvec),sigma),yvec)}. The cells S20:U20 give the weights in the convex combination computed using the array formula {=TRANSPOSE(N20D10:D12+O20*K10:K12)}.
The efficient frontier can be plotted by making a scatter plot with the expected return values (cells P20:P50) on the y‐axis and the standard deviation values (cells R20:R50) on the horizontal axis.
The tangency portfolio is the portfolio of risky assets that has the highest Sharpe’s slope. This portfolio can be found by solving the optimization problem ( )
f t ′ μ − r
This optimization problem can also be easily solved using the solver with matrix algebra functions. The screenshot below shows how to set‐up this optimization problem in Excel. The range of cells D33:D35 is called tvec and will contain the weights in the tangency portfolio once the solver is run and the solution to the optimization problem is found. Before the solver is to be run, these cells should contain an initial guess of the minimum variance portfolio. A simple guess for this vector
and is computed in cell F33 using the array formula {=MMULT(TRANSPOSE(tvec),muvec)‐rf}. The second piece is the square of the denominator of Sharpe’s slope, 2 σ (^) p t , = t ′ Σ t , and is computed in cell G33 using the array formula {=MMULT(TRANSPOSE(tvec),MMULT(sigma,tvec))}. Finally, Sharpe’s slope is evaluated in cell H33 using the formula =F33/SQRT(G33). This is the cell that is passed to the solver. To run the solver, click cell H33 and then click on the solver button. Make sure the solver dialogue box is filled out to look like the one below.
From the mutual fund separation theorem, the efficient portfolios of T‐Bills and risky assets are combinations of T‐Bills and the tangency portfolio. The expected return and standard deviation values of these portfolios are computed using tan (^ tan ) tan tan e p f f e p
μ μ σ σ
A screenshot of the spreadsheet where these portfolios are computed is given below.
is given by the formula =rf+J34(mut‐rf). The standard deviation is computed in cell L34 and is given by the formula =J34sigt. The named range sigt is the standard deviation of the tangency portfolio and is given in cell C37.
In many situations short sales of assets are not allowed. Recall, a short sale of an asset occurs when you borrow the asset and then sell it. The proceeds of the short sale are usually used to finance the purchase of other assets. Because the asset was borrowed it eventually has to be returned. You do this by repurchasing the asset at some time in the future and then returning the asset to whomever you borrowed it from. You make a profit on a short sale if the price of the asset drops during the period of time you have borrowed the^ asset^ because^ you^ repurchase^ the^ asset^ for^ a^ price^ less^ than^ for^ what^ you originally sold it. In the context of portfolio theory, when you short sell an asset the corresponding portfolio weight is negative. Hence, when short sales are prohibited all of the portfolio weights must be constrained to be positive. This type of non‐negativity constraint is easy to impose in the solver. Minimum Variance Portfolio subject to Target Expected Return with No Short Sales A minimum variance portfolio with target expected return equal to μ 0 and no short sales solves the optimization problem 2 min y σ p y , = y ′Σ y s.t. y ′μ = μ 0 , y 1 ′ = 1 and yi ≥ 0 This optimization problem can also be easily solved using the solver with matrix algebra functions. The screenshot below shows how to set‐up this optimization problem in Excel where the target expected return is the expected return on Microsoft (4.27%). Previously, we solved this problem where we
Notice that Nordstrom was sold short in that portfolio. Now we want to impose the no short sales restrictions. We set up the Excel spreadsheet exactly how we did before. The only difference occurs in how we use the solver. We add an additional constraint that forces all of the portfolio weights to be positive. The screen shot below shows the initial set‐up. The range of cells AC5:AC7 is called wvec and will contain the weights in the efficient portfolio once the solver is run and the solution to the optimization problem is found. Before the solver is to be run, these
You should see a dialogue box that says that the solver found a solution and that all optimality conditions are satisfied. Keep the solution and click OK. Your spreadsheet should look like the one below. The efficient portfolio has 100% in Microsoft and 0% in the other assets.