ams-5-sol-04-m.nb AMS 5 - Foundations Factor Models Robert J. Frey Research Professor Stony Brook University, Applied Mathematics and Statistics frey@ams.sunysb.edu Exercises for Class 3. The Chapters refer to Luenberger s Investment Science. February 2006 Mathematica Tutorial A matrix in Mathematica is represented by a list of equal length lists. The function "MatrixForm" is useful for displaying both vectors and matrices in a user friendly form. v = 8, 2, 3<; q = 88, 2, 0<, 84, 0, 6<, 80, 8, 9<<; MatrixForm@vD MatrixForm@qD i y 2 j z k 3 { i 2 0 y 4 0 6 j z k 0 8 9 { In Mathematica vectors are treated as one-dimnsional objects not as row or column vectors per se. Thus, the bilinear form v T Qv can be entered as v.q.v 78
ams-5-sol-04-m.nb 2 The "Solve" function attempts to solve an equation or system of equations symbolically. It returns its results as a list of a list of production rules. Each top-level list represents a solution.? Solve Solve@eqns, varsd attempts to solve an equation or set of equations for the variables vars. Solve@ eqns, vars, elimsd attempts to solve the equations for vars, eliminating the variables elims. More For this system of equations there are four possible solutions. Each solution consists of two production rules. Solve@8y == a x 2 + b, y ã c x2 2 + d<, 8x, x2<d è!!!!!!!!!!!!!!! è!!!!!!!!!!!!!!! è!!!!!!!!!!!!!!! è!!!!!!!!!!!!!!! -b + y -d + y -b + y -d + y 99x Ø - Å è!!! ÅÅ, x2 Ø - Å è!!! ÅÅ =, 9x Ø - Å è!!! ÅÅ, x2 Ø Å è!!! ÅÅ =, a c a c è!!!!!!!!!!!!!!! è!!!!!!!!!!!!!!!! è!!!!!!!!!!!!!!! è!!!!!!!!!!!!!!! -b + y -d + y -b + y -d + y 9x Ø Å è!!! ÅÅ, x2 Ø - Å è!!! ÅÅ =, 9x Ø Å è!!! ÅÅ, x2 Ø Å è!!! ÅÅ == a c a c "Outer" is usually used to perform an outer product of two vectors, although it generalizes to other operations and to more complex list structures.? Outer Outer@f, list, list2,... D gives the generalized outer product of the listi, forming all possible combinations of the lowestlevel elements in each of them, and feeding them as arguments to f. Outer@f, list, list2,..., nd treats as separate elements only sublists at level n in the listi. Outer@f, list, list2,..., n, n2,... D treats as separate elements only sublists at level ni in the corresponding listi. More MatrixForm@Outer@Times, 8x, x2, x3<, 8y, y2<dd i x y x2 y j k x3 y x y2 y x2 y2 z x3 y2 { A numerical matrix may be inverted with "Inverse".
ams-5-sol-04-m.nb 3? Inverse Inverse@mD gives the inverse of a square matrix m. More qi = Inverse@qD; MatrixForm@qiD MatrixForm@q.qiD i 2 ÅÅÅ 3 5 20-0 3 0-3 40 20 5 5 5 j k - 4 y z { i 0 0 y 0 0 j z k 0 0 { There are two common statistical functions used : "Mean" and "Variance". General::spell : Possible spelling error: new symbol name "and" is similar to existing symbol "And". More Syntax::tsntxi : "Variance." is incomplete; more input is needed. More There are two common statistical functions used : "Mean" and "Variance".? Mean? Variance Mean@listD gives the statistical mean of the elements in list. More Variance@listD gives the statistical variance of the elements in list. More Chapter 7, Problem 2 Here's the data we are given in the problem. nriskfree = 0.; nmarketreturn = 0.8; mncovariance = 880.04, 0.0<, 80.0, 0.02<<; vnmarketportfolio = 80.5, 0.5<;
ams-5-sol-04-m.nb 4 The market variance is a function of the covariance and the market portfolio, both of which are known. nvarmarket = vnmarketportfolio.mncovariance.vnmarketportfolio 0.02 The gradient of the Langrangian implies that Q x r r f. Once we know the returns to within proportionality, we can then solve for them using the CAPM and the fact that the market portfolio has a b of. 8pA, pb< = mncovariance.vnmarketportfolio; sol = First@ Solve@ 8 l pa ã ba HnMarketReturn - nriskfreel, l pb ã bb HnMarketReturn - nriskfreel, ã 8bA, bb<.vnmarketportfolio <, 8l, ba, bb<d D General::spell : Possible spelling error: new symbol name "bb" is similar to existing symbol "ba". More 8l Ø 4., ba Ø.25, bb Ø 0.75< Once the b's are known, the CAPM can be used to compute the asset returns. ra = nriskfree + HbA ê. soll HnMarketReturn - nriskfreel rb = nriskfree + HbB ê. soll HnMarketReturn - nriskfreel 0.2 0.6 As a final check, we verify that the asset returns when taken in proportion to the market portfolio yield the market return. nmarketreturn ã 8rA, rb<.vnmarketportfolio True
ams-5-sol-04-m.nb 5 Chapter 7, Problem 6 Here are the data provided in the table and text of the problem in form appropriate for computation. vnassetprice = 8.50, 2.<; vnassetshares = 800, 50<; vnassetreturn = 80.5, 0.2<; vnassetsdev = 80.5, 0.09<; mncorrelation = 88, ê 3<, 8 ê 3, <<; mncovariance = Outer@Times, #, #D &@vnassetsdevd mncorrelation; First, the market portfolio is computed as the proportion of each asset's market capitalizaion. vnmarketportfolio = # Å Plus üü # &@vnassetprice vnassetsharesd 80.333333, 0.666667< The expected rate of return and standard deviation are computed from the market portfolio applied to the expect asset returns and asset covariances. nmarketreturn = vnassetreturn.vnmarketportfolio nmarketsdev = è!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! vnmarketportfolio.mncovariance.vnmarketportfolio!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 0.3 0.09 Letting "rf" represent the risk free rate, we can solve for ba and bb in terms of the risk free rate.
ams-5-sol-04-m.nb 6 sol = First@ Solve@ 8 vnassetreturnpt - rf ã ba HnMarketReturn - rfl, vnassetreturnp2t - rf ã bb HnMarketReturn - rfl <, 8bA, bb< D D. H-0.5 +. rfl. H-0.2 +. rfl 9bA Ø - ÅÅ ÅÅÅ, bb Ø - ÅÅ ÅÅÅ = 0.3 -. rf 0.3 -. rf However, if we now weight these b's by the market portfolio, then we find the result is independent of the value of "rf". Simplify@H8bA, bb< ê. soll.vnmarketportfoliod. Any risk free rate works in satisfying the requirement that the market has a b of. Thus, the risk free rate is indeterminate. Chapter 7, Problem 8 The key returns are: Note that nmarketreturn = 0.33; nriskfree = 0.09; and by the definition of b E[I Å p pêê M(r c m r ê m)] = E[H ÅÅÅÅ c L E[Hp pêê L(r m r ê m)] = ÅÅÅÅ 2 ( Å 20 + Å 6 ) 20 s m 2 b = E[I Å p pêê M(r c m r ê 2 m)] / s m = ÅÅÅÅ 2 ( Å 20 + Å 6 ) 20 nbeta = ÅÅÅÅ 2 i j ÅÅ k 20 + ÅÅ y z 20. 6 { General::spell : Possible spelling error: new symbol name "nbeta" is similar to existing symbol "Beta". More.25
ams-5-sol-04-m.nb 7 We can now determine the CAPM return. ncapmreturn = nriskfree + nbeta HnMarketReturn - nriskfreel 0.36 The actual rate of return projected is nexpectedreturn = ÅÅÅÅ 2 0.35 i j ÅÅ 24 k 20 + ÅÅ 24 y z -. 6 { Thus, the project falls slightly short of the return required by the CAPM. Chapter 8, Problem 2 The data for the problem are as follows. vnreturn = 80.5, 0.20<; nriskfree = 0.0; mnfactorloadings = 88, 2, <, 8, 3, 4<<; If we assume that the CAPM applies to the factors, then the excess factor returns are vnfactorexcessreturns = Inverse@mnFactorLoadingsPAll, 82, 3<TD.HvnReturn - nriskfreel 80.02, 0.0< We can now construct l = {l 0, l, l 2 } by simply prepending the risk free rate to the factor returns. vnlambda = Prepend@vnFactorExcessReturns, nriskfreed 80., 0.02, 0.0< When we apply l to the original APT factor loadings we recover the original expected returns.
ams-5-sol-04-m.nb 8 vnreturn ã mnfactorloadings.vnlambda True Chapter 8, Problem 4 This the well-known statistical results for the sample mean and sample variance. Any text on mathematical statistics will provide a proof. Intuitively, however, we are using the sample, rather than true, mean in the computation of the sample variance and have lost a degree of freedom, i.e., we have n and not n independent data points. Chapter 8, Problem 6 Here is the raw data for the problem: two-years of monthly returns, expressed as percentages. vnmonthlyreturn = 8.0, 0.5, 4.2, -2.7, -2.0, 3.5, -3., 4.,.7, 0., -2.4, 3.2, 4.2, 4.5, -2.5, 2., -.7, 3.7, 3.2, -2.4, 2.7, 2.9, -.9,.<; nsamplesize = Length@vnMonthlyReturnD; The mean and standard deviation of return are nmonthlymean = Mean@vnMonthlyReturnD nmonthlysdev = è!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Variance@vnMonthlyReturnD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!. 2.6866 Using the approximation suggested in the text, the annualized mean and standard deviation are nannualizedmean = 2 nmonthlymean nannualizedsdev = è!!!!!!! 2 nmonthlysdev 2. 9.28955
ams-5-sol-04-m.nb 9 The standard deviations of the monthly estimates are nmonthlymeansdev = nmonthlysdev ë è!!!!!!!!!!!!!!!!!!!!!!!!!!!! nsamplesize nmonthlyvarsdev = I è!!! 2 nmonthlysdev 2 M ë è!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! nsamplesize - 0.547392 2.206