Econ 424/CFRM 462
Portfolio Theory with Matrix Algebra

Eric Zivot

Aug 7, 2014

Portfolio Math with Matrix Algebra
Three Risky Asset Example
Let  ( =   ) denote the return on asset  and assume that  follows
CER model: ∼  ( 2)
cov(  ) = Portfolio “x”
 = share of wealth in asset  +  +  = 1
Portfolio return =  +   +   

Stock A (Microsoft)
B (Nordstrom)C (Starbucks)
0.04270.00150.0285
0.10000.10440.1411

Pair (i,j)
(A,B)
(A,C)
(B,C)

0.0018
0.00110.0026

Table 1: Three asset example data.
In matrix algebra, we have⎛⎞⎛⎞00427⎜⎟⎜⎟
 = ⎝  ⎠ = ⎝ 00015 ⎠⎛2Σ=⎜⎝ 00285⎞⎛ ⎜⎟2
 ⎠ = ⎜⎝2 (01000)20001800011⎞0001800011 ⎟(01044)2 00026 ⎟⎠2
00026 (01411)

Matrix Algebra Representation⎛⎞⎛⎛⎞⎛⎞⎛⎞1⎟⎜⎟⎜⎟R=⎜⎝  ⎠   = ⎝  ⎠  1 = ⎝ 1 ⎠12⎟⎜x=⎜⎝  ⎠  Σ = ⎝ 
Portfolio weights sum to 1⎞

 
⎟2 ⎠2 ⎛1⎞⎟
x01 = (    ) ⎜⎝ 1 ⎠= 1 + 2 + 3 = 1

1

Portfolio return⎛

⎞


⎜
⎟
 = x0R = (    ) ⎝  ⎠=  +   +  

Portfolio expected return⎛

⎞


⎜
⎟
 = x0 = (    ) ⎝  ⎠=  +   +  R formulat(x.vec)%*%mu.vec
crossprod(x.vec, mu.vec)
Excel formula
MMULT(transpose(xvec),muvec)
ctrl-shift-enterPortfolio variance2 = x0Σx⎛2⎜= (    ) ⎝ 
2 + 2  2 + 2  2= 2  ⎞⎛⎞ ⎟⎜⎟2 ⎠ ⎝  ⎠2 + 2  + 2  + 2  
Portfolio distribution2 ) ∼ ( R formulast(x.vec)%*%sigma.mat%*%x.vec
Excel formulas
MMULT(TRANSPOSE(xvec),MMULT(sigma,xvec))
MMULT(MMULT(TRANSPOSE(xvec),sigma),xvec)
ctrl-shift-enterCovariance Between 2 Portfolio Returns
2 portfolios⎛⎞⎛⎞⎜⎟⎜x = ⎝  ⎠  y = ⎝  ⎟⎠x01 = 1 y01 = 1

Portfolio returns = x0R = y0R
Covariancecov(  ) = x0Σy= y0Σx

R formulat(x.vec)%*%sigma.mat%*%y.vec
Excel formula
MMULT(TRANSPOSE(xvec),MMULT(sigma,yvec))
MMULT(TRANSPOSE(yvec),MMULT(sigma,xvec))
ctrl-shift-enterDerivatives of Simple Matrix Functions
Let A be an  ×  symmetric matrix, and let x and y be an  × 1 vectors.
Then⎛⎞ x0y⎜ 1.
⎟ 0⎜
⎟ = y
.
xy=⎝
⎠
x
 x0y
×1
⎛ 
⎞
 x0Ax⎜ 1 .
⎟
 0⎜
⎟ = 2Ax
.
x Ax = ⎝⎠x x0Ax
×1



(1)

(2)

Computing Global Minimum Variance Portfolio
Problem: Find the portfolio m = (    )0 that solvesmin 2
= m0Σm s.t. m01 = 1

1. Analytic solution using matrix algebra

2. Numerical Solution in Excel Using the Solver (see 3firmExample.xls)

Analytic solution using matrix algebra
The Lagrangian is(m ) = m0Σm+(m01 − 1)
First order conditions (use matrix derivative results)(m ) m0Σm
0 ==+(m01 − 1) = 2 · Σm+1
m
m
m
(3×1)
(m ) m0Σm
0 ==+(m01 − 1) = m01 − 1



(1×1)
Write FOCs in matrix form
Ã2Σ 1
10 0!Ã

m

!

=

Ã01!

3×1
1×1

The FOCs are the linear systemAz = bwhereA =

Ã2Σ 1
10 0!

 z =Ãm!

and b =Ã01!

The solution for z isz = A−1
 bThe first three elements of z are the portfolio weights m = (    )0
for the global minimum variance portfolio with expected return  = m0
2= m0Σmand variance 

Alternative Derivation of Global Minimum Variance Portfolio
The first order conditions from the optimization problem can be expressed inmatrix notation as(m )= 2 · Σm+ · 1m
(3×1)
(m )0 == m01 − 1
(1×1)0=

Using first equation, solve for m :1m = − · Σ−112

Next, multiply both sides by 10 and use second equation to solve for :1
1 = 10m = − · 10Σ−1121⇒  = −2 · 0 −1 1Σ 1Finally, substitute the value for  in the equation for m:
1
1m = − (−2) 0 −1 Σ−1121Σ 1
Σ−11= 0 −1 1Σ 1

Eﬃcient Portfolios of Risky Assets: Markowitz Algorithm
Problem 1: find portfolio x that has the highest expected return for a given
level of risk as measured by portfolio variancemax  = x0 s.t
2 = x0Σx =  0 = target riskx01 = 1Problem 2: find portfolio x that has the smallest risk, measured by portfolio
variance, that achieves a target expected return.
min 

2 = x0Σx s.t.
 = x0 = 0 = target returnx01 = 1
Remark: Problem 2 is usually solved in practice by varying the target return
between a given range.

Solving for Eﬃcient Portfolios:

1. Analytic solution using matrix algebra

2. Numerical solution in Excel using the solverAnalytic solution using matrix algebra
The Lagrangian function associated with Problem 2 is( 1 2) = x0Σx + 1(x0−0) + 2(x01 − 1)
The FOCs are(x 1 2)= 2Σx + 1 + 21x(3×1)(x 1 2)0 == x0 − 0
1(1×1)
(x 1 2)
0 == x01 − 1
2
(1×1)

0

=

These FOCs consist of five linear equations in five unknowns(     1 2)

We can represent the FOCs in matrix notation as⎛⎞⎛⎛⎞

02Σ  1x⎟⎜⎟⎜⎟0 0 ⎠ ⎝ 1 ⎠ = ⎝ 0 ⎠0 0
21⎜ 0⎝ 10or⎞Az= b0where⎛⎞⎛⎞⎛⎞02Σ  1x⎟⎜⎟⎜⎟A = ⎜⎝ 0 0 0 ⎠  z = ⎝ 1 ⎠ and b0 = ⎝ 0 ⎠10 0 0
21The solution for z is thenz = A−1
 b0
The first three elements of z are the portfolio weights x = (    )0 for
the eﬃcient portfolio with expected return  = 0.

Example: Find eﬃcient portfolios with the same expected return as MSFT andSBUXFor MSFT, we solvemin 2 = x0Σx s.t.
 = x0 =   = 0.0427

x01 = 1For SBUX, we solvemin 

2 = y0Σy s.t.
 = y0 =   = 0.0285

y0 1 = 1

Example continued
Using the matrix algebra formulas (see R code in Powerpoint slides) we get⎛

⎞⎛

⎞

⎛⎞⎛

⎞

  08275
05194
⎜
⎟
⎜
⎟
⎜
⎟
⎜
x = ⎝  ⎠ = ⎝ −00908 ⎠  y = ⎝  ⎠ = ⎝ 02732 ⎟⎠02633

02075

Also, = x0 = 00427  = y0 = 00285
 = (x0Σx)12 = 009166  = (y0Σy)12 = 007355
 = x0Σy = 0005914  =  ( ) = 08772

Computing the Portfolio Frontier
Result: The portfolio frontier can be represented as convex combinations of
any two frontier portfolios. Let x be a frontier portfolio that solves
2 = x0Σx s.t.
min x = x0 = 0

x01 = 1Let y 6= x be another frontier portfolio that solves
2 = y0Σy s.t.
min y = y0 = 1 6= 0

y0 1 = 1

Let  be any constant. Then the portfolioz =  · x + (1 − ) · y
is a frontier portfolio. Furthermore = z0 =  ·  + (1 − )
2 = z0Σz

2 + (1 − )2 2 + 2(1 − )
= 2
 = cov(  ) = x0Σy

Example: 3 asset casez =  · x + (1 − ) · y
⎛
⎞⎛
⎞

⎜
⎟
⎜
⎟
=  · ⎝  ⎠ + (1 − ) ⎝  ⎠

⎛
⎞
⎛
⎞
 + (1 − )

⎜
⎟
⎜
⎟
= ⎝  + (1 − ) ⎠ = ⎝  ⎠ + (1 − )

Example: Compute eﬃcient portfolio as convex combination of eﬃcient portfolio with same mean as MSFT and eﬃcient portfolio with same mean asSBUX.
Let x denote the eﬃcient portfolio with the same mean as MSFT, y denotethe eﬃcient portfolio with the same mean as SBUX, and let  = 05 Thenz =  · x + (1 − ) · y⎛⎞⎛⎞08274505194⎜⎟⎜⎟= 05 · ⎝ −009075 ⎠ + 05 · ⎝ 02732 ⎠02632902075⎛⎞ ⎛⎞⎛⎞⎛⎞(05)(082745)(05)(05194)
06734⎜⎟ ⎜⎟⎜⎟⎜⎟= ⎝ (05)(−009075) ⎠ + ⎝ (05)(02732) ⎠ = ⎝ 00912 ⎠ = ⎝  ⎠ (05)(026329)(05)(02075)
02354

Example continued
The mean of this portfolio can be computed using:⎛⎞

00427⎜⎟
 = z0 = (06734 00912 02354)0 ⎝ 00015 ⎠ = 00356
00285 =  ·  + (1 − ) = 05(00427) + (05)(00285) = 00356
The variance can be computed using
2 = z0Σz = 000641

2 = 2 2 + (1 − )2 2 + 2(1 − )





= (05)2(009166)2 + (05)2(007355)2 + 2(05)(05)(0005914) = 000641

Example: Find eﬃcient portfolio with expected return 0.05 from two eﬃcient
portfoliosUse
005 =  =  ·  + (1 − )
to solve for  :005 − 005 − 00285
=== 1514
 − 00427 − 00285

Then, solve for portfolio weights usingz =  · x + (1 − ) · y⎛⎞⎛⎞⎛⎞082750519409858
⎜⎟
⎜
⎟
⎜
⎟
= 1514 ⎝ −00908 ⎠ − 0514 ⎝ 02732 ⎠ = ⎝ −02778 ⎠02633
0207502920

Strategy for Plotting Portfolio Frontier

1. Set global minimum variance portfolio = first frontier portfolio
2min = m0Σm s.t. m01 = 1

mand compute  = m0
2. Find asset  that has highest expected return. Set target return to 0 =max() and solve
2 = x0Σx s.t.
min x = x0 = 0 = max()x01 = 1

3. Create grid of  values, initially between 1 and −1 and computez =  · m + (1 − ) · x
 =  ·  + (1 − )
2 = 2 2 + (1 − )2 2 + 2(1 − )

 = m0Σx
4. Plot  against   Expand or contract the grid of  values if necessary
to improve the plot

Finding the Tangency Portfolio
The tangency portfolio t is the portfolio of risky assets that maximizes Sharpe’sslope: − max Sharpe’s ratio =tsubject tot01 = 1In matrix notation,
Sharpe’s ratio =t0 − (t0Σt)12

Solving for Eﬃcient Portfolios:

1. Analytic solution using matrix algebra

2. Numerical solution in Excel using the solverAnalytic solution using matrix algebra
The Lagrangian for this problem is³´− 1200(t ) = t  −  (t Σt) + (t01 − 1)

Using the chain rule, the first order conditions are³´(t )− 12000 == (t Σt) − t  −  (t0Σt)−32Σt + 1
t(3×1)(t )0 == t01 − 1 = 0

(1×1)

After much tedious algebra, it can be shown that the solution for t isΣ−1( −  · 1)
t = 0 −1
1 Σ ( −  · 1)

Remarks:• If the risk free rate,   is less than the expected return on the global
minimum variance portfolio,  min then the tangency portfolio has apositive Sharpe slope• If the risk free rate,   is equal to the expected return on the global
minimum variance portfolio,  min then the tangency portfolio is notdefined• If the risk free rate,   is greater than the expected return on the global
minimum variance portfolio,  min then the tangency portfolio has anegative Sharpe slope.

Mutual Fund Separation Theorem AgainEﬃcient Portfolios of T-bills and Risky assets are combinations of two portfolios(mutual funds)• T-bills• Tangency portfolio

Eﬃcient Portfolios
 = share of wealth in tangency portfolio t = share of wealth in T-bills
 +  = 1 ⇒  = 1 −  =  + ( −  )  = t0 =   =³´120t ΣtRemark: The weights  and  are determined by an investor’s risk preferences• Risk averse investors hold mostly T-Bills ( ≈ 0)
• Risk tolerant investors hold mostly tangency portfolio ( ≈ 1)
• If Sharpe’s slope for the tangency portfolio is negative then the eﬃcient
portfolio involve shorting the tangency portfolioExample: Find eﬃcient portfolio with target risk (SD) equal to 0.02
Solve
002 =  =  = (01116)
002⇒  == 01792
01116
 = 1 −  = 08208
Also,
 =  + ( −  ) = 0005 + (01116) (005189 − 0005) = 00134
 =  = (01792)(01116) = 002

Example: Find eﬃcient portfolio with target ER equal to 0.07Solve007 =  =  + ( −  )007 − 
007 − 0005=⇒  == 1386
 − 
005189 − 0005
Also, =  = (1386)(01116) = 01547

Portfolio Value-at-Risk
Let x = (1     )0 denote a vector of asset share for a portfolio. Portfolio
risk is measured by var() = x0Σx Alternatively, portfolio risk can bemeasured using Value-at-Risk:
VaR = 0
0 = initial investment
 = 100 · % Simple return quantile = loss probability

If returns are normally distributed then =  + 
 = x0

³´120 = x Σx

 = 100 · % quantile from (0 1)
Example: Using VaR to evaluate an eﬃcient portfolio
Invest in 3 risky assets (Microsoft, Starbucks, Nordstrom) and T-bills. Assume
 = 0005

1. Determine eﬃcient portfolio that has same expected return as Starbucks

2. Compare VaR05 for Starbucks and eﬃcient portfolio based on $100,000
investment

Solution for 1.
SBUX = 00285
 =  + ( −  ) = 0005 = t0 = 05186  = 0111
Solve

Note:

00285 = 0005 + (005186 − 0005)
00285 − 005
 == 0501
005186 − 005
 = 1 − 0501 = 0499
 = 0005 + 0501 · (005186 − 0005) = 00285
 =  = (0501)(0111) = 0057

Solution for 2.
SBUX = 05SBUX + SBUX · (−1645)= 00285 + (0141) · (−1645)= −0203 =  +   · (−1645)
05
= 0285 + (057) · (−1645)− 0063
ThenSBUXVaR
= $100 000 · 05
05

= $100 000 · (−0203) = −$20 300

VaR05 = $100 000 · 05

= $100 000 · (−0063) = −$6 300