SOLUTION NOTES FOR EXERCISES ON FUNCTIONS
4. Code for Standard Deviation of Cash Flows
6.12 MACROS IN ModuleM
The macros to generate the efficient frontier using Solver are contained in this module sheet. Solver is an add-in to Excel and, unless it appears on the Tools menu, needs to be installed. Additionally, to use the Solver functions in VBA, the module sheet must include a reference to the SOLVER.xla add-in file:
Sub EffFrontier1() SolverReset
Call SolverAdd(Range(“ portret1”), 2, Range(“ target1”)) Call SolverOk(Range(“ portsd1”), 2, 0, Range(“ change1”)) Call SolverSolve(True)
SolverFinish End Sub
The EffFrontier1 macro contains a single application of Solver. The SolverAdd function adds the single constraint needed (where the value 2 represents the equality constraint) then the SolverOk function sets up the problem (here the value 2 ensures minimisation).
The SolverSolve function solves the problem (the True parameter hides the results screen) then the SolverFinish function retains the final solution values in the spreadsheet.
Strictly speaking, the Call word is not strictly necessary, but we prefer to include it when a subroutine requiring parameters is used in the code. The parameters must then be in brackets when using this syntax.
The EffFrontier2 macro is rather more complicated in that it generates the complete efficient frontier using repeated applications of the Solver function within a loop. The number of repeats is predetermined. The most important lesson is to minimise the code contained in the loop. The Solver problem is set up outside the loop, with the Solver- Change function changing the right-hand side of the constraint (the target expected return) inside the loop. Within the loop, the results of each Solver iteration are copied to a range in the spreadsheet using the PasteSpecial command. The code for the loop is as follows:
Do While iter <= niter Call SolverSolve(True) SolverFinish
Range(“ portwts2”).Copy
Range(“ effwts2”).Offset(iter, 0).PasteSpecial Paste:=xlValues Range(“ priter2”) = Range(“ priter2”).Value + pradd
’amend portret constraint in Solver
Call SolverChange(Range(“ portret2”), 2, Range(“ priter2”)) iter = iter + 1
Loop
The initial part of the macro uses Solver twice, first to calculate the minimum portfolio return achievable with the given constraints (with the value of 2 in the SolverOk function) and then to calculate the maximum return (with the value of 1 in the SolverOk function).
The range between these two returns is divided into the chosen number of target returns and the frontier portfolio weights determined and stored for each return.
SolverReset
’first calculate portfolio min return given constraints Call SolverAdd(Range(“ portwts2”), 3, Range(“ portmin2”)) Call SolverAdd(Range(“ portwts2”), 1, Range(“ portmax2”)) Call SolverOk(Range(“ portret2”), 2, 0, Range(“ change2”)) Call SolverSolve(True)
SolverFinish
prmin = Range(“ portret2”).Value
’then calculate portfolio max return given constraints Call SolverOk(Range(“ portret2”), 1, 0, Range(“ change2”)) Call SolverSolve(True)
SolverFinish
Portfolio Optimisation 123
SUMMARY
The theory of portfolio optimisation developed by Markowitz underpins the whole Equities part of the book. We show how the basic formulas for portfolio mean and variance with two assets can be easily extended, using the array functions in Excel, to cover many assets. The array functions allowing matrix multiplication and inversion allow us to implement Huang and Litzenberger’s analytic solution to generate the efficient frontier.
This is illustrated in spreadsheet form as well as within user-defined functions.
Although the theory is important, its practical implementation requires numerical methods, such as Solver. We demonstrate that the solution obtained by Solver agrees with the HL analytic solution for the unconstrained case and show how to use Solver when there are constraints on the holdings of individual assets. Again, we illustrate the use of Solver both in spreadsheet form and using macros (for repeated applications).
In the next chapter, we cover the next crucial development in finance theory, the capital asset pricing model and the role of beta. We go on to use the lognormal distribution of equity returns in forecasting horizon wealth and Value-at-Risk for individual shares and portfolios.
REFERENCES
Bodie, Z., A. Kane and A. J. Marcus, 1996,Investments, 3rd edition, Richard D. Irwin, Englewood Cliffs, NJ.
Elton, E. J. and M. J. Gruber, 1995,Modern Portfolio Theory and Investment Analysis, John Wiley & Sons, Chichester.
Eppen, G. D., F. J. Gould, C. P. Schmidt, J. H. Moore and L. R. Weatherford, 1998,Introductory Management Science,Decision Modelling with Spreadsheets, 5th edition, Prentice Hall, New Jersey.
Huang, C. and R. Litzenberger, 1988,Foundations for Financial Economics, North Holland, New York.
Taggart, R. A., 1996,Quantitative Analysis for Investment Management, Prentice Hall, New Jersey.
7
Asset Pricing
We move from examining individual investors (a micro view) to the markets for assets and looking at the behaviour of all investors (a macro view). The crucial difference is the move from making statements about individuals to the drawing of conclusions about the behaviour of investors as a whole. It is this different focus that allows us to make statements about the pricing of financial assets. The capital asset pricing model (CAPM) was developed in the sixties by finance academics. It developed out of the mean–variance portfolio analysis described in the previous chapter. An important conclusion was that market prices reflect only part of a portfolio’s risk. The part that is priced, the market- related risk, is measured by beta. The background to the CAPM is extensively discussed in Bodie et al. (1996), Chapter 8.
This chapter opens with the single-index model and illustrates the calculation of associ- ated risk measures, in particular the estimation of betas and variance–covariance matrices from the returns of individual assets. The central numerical technique is regression, which is applied to estimate the beta of an asset, i.e. the return on the asset relative to the return on the market. The betas for a set of assets are useful in their own right to describe the rela- tive responsiveness of assets to the market. However, they also facilitate the calculation of covariances via the single-index model. The EQUITY2.xls workbook contains imple- mentations of the various estimation procedures and a range of user-defined functions have been developed to reduce the computational burden of the procedures.
In the previous chapter, we developed the mean–variance model of Markowitz assuming a utility function to describe the preferences of individual investors. In that analysis, the distribution of asset returns was ignored. We can, as an alternative, generate exactly the same theoretical results from the mean–variance model by assuming that asset returns are lognormally distributed whilst ignoring the preferences of individuals.
If log returns can be assumed to be normally distributed, we can derive analytic answers for both Value-at-Risk and the forecasting of horizon wealth. In this chapter, we include examples of both these techniques. In a sense, we reap the benefit of Markowitz’s insight that return and risk can be associated with the mean and variance of the normal distribution and thus can use familiar results from the field of statistics. Also, since it is vital to manoeuvre easily between normal and lognormal moments of asset returns, we give practical illustrations to reinforce the theory linking the two distributions.