0% found this document useful (0 votes)
147 views54 pages

Introduction To Computational Finance and Financial Econometrics

Uploaded by

MR 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views54 pages

Introduction To Computational Finance and Financial Econometrics

Uploaded by

MR 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

You can’t see this text!

Introduction to Computational Finance and


Financial Econometrics
Portfolio Theory with Matrix Algebra

Eric Zivot
Spring 2015

Eric Zivot (Copyright © 2015) Portfolio Theory 1 / 54


Outline

1 Portfolios with Three Risky Assets


Portfolio characteristics using matrix notation
Finding the global minimum variance portfolio
Finding efficient portfolios
Computing the efficient frontier
Mutual fund separation theorem again

Eric Zivot (Copyright © 2015) Portfolio Theory 2 / 54


Example
Example: Three risky assets

Let Ri (i = A, B, C) denote the return on asset i and assume that Ri


follows CER model:

Ri ∼ iid N (µi , σi2 )

cov(Ri , Rj ) = σij

Portfolio “x”:

xi = share of wealth in asset i

xA + xB + xC = 1

Portfolio return:

Rp,x = xA RA + xB RB + xC RC .

Eric Zivot (Copyright © 2015) Portfolio Theory 3 / 54


Example cont.

Stock i µi σi Pair (i,j) σij


A (Microsoft) 0.0427 0.1000 (A,B) 0.0018
B (Nordstrom) 0.0015 0.1044 (A,C) 0.0011
C (Starbucks) 0.0285 0.1411 (B,C) 0.0026
Three asset example data.

In matrix algebra, we have:


0.0427
   
µA
µ =  µB  =  0.0015 
   

µC 0.0285

2 (0.1000)2 0.0018 0.0011


   
σA σAB σAC
Σ =  σAB σB2 =
σBC   0.0018 (0.1044) 2
0.0026 
   

σAC σBC 2
σC 0.0011 0.0026 (0.1411)2

Eric Zivot (Copyright © 2015) Portfolio Theory 4 / 54


Outline

1 Portfolios with Three Risky Assets


Portfolio characteristics using matrix notation
Finding the global minimum variance portfolio
Finding efficient portfolios
Computing the efficient frontier
Mutual fund separation theorem again

Eric Zivot (Copyright © 2015) Portfolio Theory 5 / 54


Matrix Algebra Representation

1
     
RA µA
R =  RB  , µ =  µB  , 1 =  1 
     

RC µC 1

2
   
xA σA σAB σAC
x =  xB  , Σ =  σAB σB2 σBC 
   

xC σAC σBC 2
σC
Portfolio weights sum to 1:

1
 

x 0 1 = ( xA xB xC ) 1 
 

= x1 + x2 + x3 = 1

Eric Zivot (Copyright © 2015) Portfolio Theory 6 / 54


Portfolio return

 
RA
Rp,x = x0 R = ( xA xB xC )  RB 
 

RC

= xA RA + xB RB + xC RC

Portfolio expected return:


 
µA
µp,x = x0 µ = ( xA xB xX )  µB 
 

µC

= x A µA + x B µB + x C µC

Eric Zivot (Copyright © 2015) Portfolio Theory 7 / 54


Computational tools

R formula:

t(x.vec)%*%mu.vec

crossprod(x.vec, mu.vec)

Excel formula:

MMULT(transpose(xvec),muvec)

<ctrl>-<shift>-<enter>

Eric Zivot (Copyright © 2015) Portfolio Theory 8 / 54


Portfolio variance

2
σp,x = x0 Σx
2
  
σA σAB σAC xA
= ( xA xB xC )  σAB σB2 σBC   xB 
  

σAC σBC 2
σC xC

= x2A σA
2
+ x2B σB
2
+ x2C σC
2

+ 2xA xB σAB + 2xA xC σAC + 2xB xC σBC

Portfolio distribution:

Rp,x ∼ N (µp,x , σp,x


2
)

Eric Zivot (Copyright © 2015) Portfolio Theory 9 / 54


Computational tools

R formulas:

t(x.vec)%*%sigma.mat%*%x.vec

Excel formulas:

MMULT(TRANSPOSE(xvec),MMULT(sigma,xvec))

MMULT(MMULT(TRANSPOSE(xvec),sigma),xvec)

<ctrl>-<shift>-<enter>

Eric Zivot (Copyright © 2015) Portfolio Theory 10 / 54


Covariance Between 2 Portfolio Returns
2 portfolios:
   
xA yA
x =  xB  , y =  yB 
   

xC yC

x0 1 = 1, y0 1 = 1
Portfolio returns:
Rp,x = x0 R

Rp,y = y0 R
Covariance:
cov(Rp,x , Rp,y ) = x0 Σy

= y0 Σx
Eric Zivot (Copyright © 2015) Portfolio Theory 11 / 54
Computational tools

R formula:

t(x.vec)%*%sigma.mat%*%y.vec

Excel formula:

MMULT(TRANSPOSE(xvec),MMULT(sigma,yvec))

MMULT(TRANSPOSE(yvec),MMULT(sigma,xvec))

<ctrl>-<shift>-<enter>

Eric Zivot (Copyright © 2015) Portfolio Theory 12 / 54


Derivatives of Simple Matrix Functions

Let A be an n × n symmetric matrix, and let x and y be an n × 1


vectors. Then,
∂ 0
 
∂x1 x y
∂ 0
xy=
 ..  = y,

(1)
∂x  . 
n×1 ∂
x 0y
∂xn

∂ 0
 
∂x1 x Ax
∂ 0
x Ax = 
 ..  = 2Ax.

(2)
∂x  . 
n×1 ∂ 0
∂xn x Ax

Eric Zivot (Copyright © 2015) Portfolio Theory 13 / 54


Outline

1 Portfolios with Three Risky Assets


Portfolio characteristics using matrix notation
Finding the global minimum variance portfolio
Finding efficient portfolios
Computing the efficient frontier
Mutual fund separation theorem again

Eric Zivot (Copyright © 2015) Portfolio Theory 14 / 54


Computing Global Minimum Variance Portfolio

Problem: Find the portfolio m = (mA , mB , mC )0 that solves:

min 2
σp,m = m0 Σm s.t. m0 1 = 1
mA ,mB ,mC

1 Analytic solution using matrix algebra


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

Eric Zivot (Copyright © 2015) Portfolio Theory 15 / 54


Analytic solution using matrix algebra

The Lagrangian is:

L(m, λ) = m0 Σm+λ(m0 1 − 1)

First order conditions (use matrix derivative results):

∂L(m, λ) ∂m0 Σm ∂
0 = = + λ(m0 1 − 1) = 2 · Σm+λ1
(3×1) ∂m ∂m ∂m

∂L(m, λ) ∂m0 Σm ∂
0 = = + λ(m0 1 − 1) = m0 1 − 1
(1×1) ∂λ ∂λ ∂λ

Write FOCs in matrix form:


! ! !
2Σ 1 m 0 3×1
= .
10 0 λ 1 1×1

Eric Zivot (Copyright © 2015) Portfolio Theory 16 / 54


Analytic solution using matrix algebra cont.

The FOCs are the linear system:

A m zm = b

where,
! ! !
2Σ 1 m 0
Am = , zm = and b = .
10 0 λ 1

The solution for zm is:

zm = A−1
m b.

The first three elements of zm are the portfolio weights


m = (mA , mB , mC )0 for the global minimum variance portfolio with
expected return µp,m = m0 µ and variance σp,m
2 = m0 Σm.

Eric Zivot (Copyright © 2015) Portfolio Theory 17 / 54


Alternative Derivation of Global Minimum Variance
Portfolio

The first order conditions from the optimization problem can be


expressed in matrix notation as:

∂L(m, λ)
0 = = 2 · Σm+λ · 1,
(3×1) ∂m

∂L(m, λ)
0 = = m0 1 − 1.
(1×1) ∂λ

Using first equation, solve for m:


1
m = − · λΣ−1 1.
2

Eric Zivot (Copyright © 2015) Portfolio Theory 18 / 54


Alternative Derivation of Global Minimum Variance
Portfolio cont.

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

Eric Zivot (Copyright © 2015) Portfolio Theory 19 / 54


Outline

1 Portfolios with Three Risky Assets


Portfolio characteristics using matrix notation
Finding the global minimum variance portfolio
Finding efficient portfolios
Computing the efficient frontier
Mutual fund separation theorem again

Eric Zivot (Copyright © 2015) Portfolio Theory 20 / 54


Efficient 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 variance.

max µp,x = x0 µ s.t


xA ,xB ,xC

2
σp,x = x0 Σx = σp0 = target risk

x0 1 = 1

Eric Zivot (Copyright © 2015) Portfolio Theory 21 / 54


Efficient Portfolios of Risky Assets: Markowitz
Algorithm cont.

Problem 2: find portfolio x that has the smallest risk, measured by


portfolio variance, that achieves a target expected return.

min 2
σp,x = x0 Σx s.t.
xA ,xB ,xC

µp,x = x0 µ = µ0p = target return

x0 1 = 1

Remark: Problem 2 is usually solved in practice by varying the target


return between a given range.

Eric Zivot (Copyright © 2015) Portfolio Theory 22 / 54


Solving for Efficient Portfolios

1 Analytic solution using matrix algebra


2 Numerical solution in Excel using the solver

Eric Zivot (Copyright © 2015) Portfolio Theory 23 / 54


Analytic solution using matrix algebra

The Lagrangian function associated with Problem 2 is:

L(x, λ1 , λ2 ) = x0 Σx + λ1 (x0 µ−µp,0 ) + λ2 (x0 1 − 1)

The FOCs are:


∂L(x, λ1 , λ2 )
0 = = 2Σx + λ1 µ + λ2 1,
(3×1) ∂x

∂L(x, λ1 , λ2 )
0 = = x0 µ − µp,0 ,
(1×1) ∂λ1

∂L(x, λ1 , λ2 )
0 = = x0 1 − 1.
(1×1) ∂λ2

These FOCs consist of five linear equations in five unknowns


(xA , xB , xC , λ1 , λ2 ).

Eric Zivot (Copyright © 2015) Portfolio Theory 24 / 54


Analytic solution using matrix algebra cont.

We can represent the FOCs in matrix notation as:

2Σ µ 1
    
x 0
=
0 0   λ1   µp,0 
 0
 µ
   

10 0 0 λ2 1
or,

Ax zx = b0

where,

2Σ µ 1
     
x 0
Ax =  µ 0 0  , zx =  λ1  and b0 =  µp,0 
 0     

10 0 0 λ2 1

Eric Zivot (Copyright © 2015) Portfolio Theory 25 / 54


Analytic solution using matrix algebra cont.

The solution for zx is then:

zx = A−1
x b0 .

The first three elements of zx are the portfolio weights


x = (xA , xB , xC )0 for the efficient portfolio with expected return
µp,x = µp,0 .

Eric Zivot (Copyright © 2015) Portfolio Theory 26 / 54


Example
Example: Find efficient portfolios with the same expected return as
MSFT and SBUX

For MSFT, we solve:


min 2
σp,x = x0 Σx s.t.
xA ,xB ,xC

µp,x = x0 µ = µM SF T = 0.0427

x0 1 = 1
For SBUX, we solve:
min σp,x
2
= y0 Σy s.t.
yA ,yB ,yC

µp,y = y0 µ = µSBU X = 0.0285

y0 1 = 1
Eric Zivot (Copyright © 2015) Portfolio Theory 27 / 54
Example cont.

Using the matrix algebra formulas (see R code in PowerPoint slides) we


get:

0.8275 0.5194
       
xmsf t ymsf t
x =  xnord  =  −0.0908  , y =  ynord  =  0.2732 
       

xsbux 0.2633 ysbux 0.2075

Also,

µp,x = x0 µ = 0.0427, µp,y = y0 µ = 0.0285

σp,x = (x0 Σx)1/2 = 0.09166, σp,y = (y0 Σy)1/2 = 0.07355

σxy = x0 Σy = 0.005914, ρxy = σxy /(σp,x σp,y ) = 0.8772

Eric Zivot (Copyright © 2015) Portfolio Theory 28 / 54


Outline

1 Portfolios with Three Risky Assets


Portfolio characteristics using matrix notation
Finding the global minimum variance portfolio
Finding efficient portfolios
Computing the efficient frontier
Mutual fund separation theorem again

Eric Zivot (Copyright © 2015) Portfolio Theory 29 / 54


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:

min σp,x
2
= x0 Σx s.t.
x

µp,x = x0 µ = µ0p

x0 1 = 1

Let y 6= x be another frontier portfolio that solves:

min σp,y
2
= y0 Σy s.t.
y

µp,y = y0 µ = µ1p 6= µ0p

y0 1 = 1

Eric Zivot (Copyright © 2015) Portfolio Theory 30 / 54


Computing the Portfolio Frontier cont.

Let α be any constant. Then the portfolio:

z = α · x + (1 − α) · y

is a frontier portfolio. Furthermore,

µp,z = z0 µ = α · µp,x + (1 − α)µp,y


2
σp,z = z0 Σz

= α2 σp,x
2
+ (1 − α)2 σp,y
2
+ 2α(1 − α)σx,y

σx,y = cov(Rp,x , Rp,y ) = x0 Σy

Eric Zivot (Copyright © 2015) Portfolio Theory 31 / 54


Example

Example: 3 asset case

z = α · x + (1 − α) · y
   
xA yA
= α ·  xB  + (1 − α)  yB 
   

xC yC

αxA + (1 − α)yA
   
zA
=  αxB + (1 − α)yB  =  zB 
   

αxC + (1 − α)yC zC

Eric Zivot (Copyright © 2015) Portfolio Theory 32 / 54


Example
Example: Compute efficient portfolio as convex combination of
efficient portfolio with same mean as MSFT and efficient portfolio with
same mean as SBUX.

Let x denote the efficient portfolio with the same mean as MSFT, y
denote the efficient portfolio with the same mean as SBUX, and let
α = 0.5. Then,

z = α · x + (1 − α) · y

0.82745 0.5194
   

= 0.5 ·  −0.09075  + 0.5 ·  0.2732 


   

0.26329 0.2075
! ! ! !
(0.5)(0.82745) (0.5)(0.5194) 0.6734 zA
= (0.5)(−0.09075) + (0.5)(0.2732) = 0.0912 = zB .
(0.5)(0.26329) (0.5)(0.2075) 0.2354 zC

Eric Zivot (Copyright © 2015) Portfolio Theory 33 / 54


Example cont.
The mean of this portfolio can be computed using:

0.0427
 

µp,z = z0 µ = (0.6734, 0.0912, 0.2354)0  0.0015  = 0.0356


 

0.0285

µp,z = α · µp,x + (1 − α)µp,y = 0.5(0.0427) + (0.5)(0.0285) = 0.0356

The variance can be computed using:


2
σp,z = z0 Σz = 0.00641
2
σp,z = α2 σp,x
2
+ (1 − α)2 σp,y
2
+ 2α(1 − α)σxy

= (0.5)2 (0.09166)2 + (0.5)2 (0.07355)2 + 2(0.5)(0.5)(0.005914)

= 0.00641

Eric Zivot (Copyright © 2015) Portfolio Theory 34 / 54


Example
Example: Find efficient portfolio with expected return 0.05 from two
efficient portfolios Use,

0.05 = µp,z = α · µp,x + (1 − α)µp,y

to solve for α:
0.05 − µp,y 0.05 − 0.0285
α= = = 1.514
µp,x − µp,y 0.0427 − 0.0285

Then, solve for portfolio weights using:

z = α · x + (1 − α) · y

0.8275 0.5194 0.9858


     

= 1.514  −0.0908  − 0.514  0.2732  =  −0.2778 


     

0.2633 0.2075 0.2920

Eric Zivot (Copyright © 2015) Portfolio Theory 35 / 54


Strategy for Plotting Portfolio Frontier

1 Set global minimum variance portfolio = first frontier portfolio

min σp,m
2
= m0 Σm s.t. m0 1 = 1
m

and compute µp,m = m0 µ


2 Find asset i that has highest expected return. Set target return to
µ0 = max(µ) and solve:

min σp,x
2
= x0 Σx s.t.
x

µp,x = x0 µ = µ0p = max(µ)

x0 1 = 1

Eric Zivot (Copyright © 2015) Portfolio Theory 36 / 54


Strategy for Plotting Portfolio Frontier cont.

3 Create grid of α values, initially between 1 and −1, and compute

z = α · m + (1 − α) · x

µp,z = α · µp,m + (1 − α)µp,x


2
σp,z = α2 σp,m
2
+ (1 − α)2 σp,x
2
+ 2α(1 − α)σm,x

σm,x = m0 Σx

4 Plot µp,z against σp,z . Expand or contract the grid of α values if


necessary to improve the plot.

Eric Zivot (Copyright © 2015) Portfolio Theory 37 / 54


Finding the Tangency Portfolio

The tangency portfolio t is the portfolio of risky assets that maximizes


Sharpe’s slope:
µp,t − rf
max Sharpe’s ratio =
t σp,t

subject to,

t0 1 = 1

In matrix notation,

t0 µ − rf
Sharpe’s ratio =
(t0 Σt)1/2

Eric Zivot (Copyright © 2015) Portfolio Theory 38 / 54


Solving for Efficient Portfolios

1 Analytic solution using matrix algebra


2 Numerical solution in Excel using the solver

Eric Zivot (Copyright © 2015) Portfolio Theory 39 / 54


Analytic solution using matrix algebra

The Lagrangian for this problem is:


1
L(t, λ) = t0 µ − rf (t0 Σt)− 2 + λ(t0 1 − 1)


Using the chain rule, the first order conditions are:

∂L(t, λ) 1
0 = = µ(t0 Σt)− 2 − t0 µ − rf (t0 Σt)−3/2 Σt + λ1

(3×1) ∂t

∂L(t, λ)
0 = = t0 1 − 1 = 0
(1×1) ∂λ

After much tedious algebra, it can be shown that the solution for t is:

Σ−1 (µ − rf · 1)
t=
10 Σ−1 (µ − rf · 1)

Eric Zivot (Copyright © 2015) Portfolio Theory 40 / 54


Remakrs

If the risk free rate, rf , is less than the expected return on the
global minimum variance portfolio, µg min , then the tangency
portfolio has a positive Sharpe slope
If the risk free rate, rf , is equal to the expected return on the
global minimum variance portfolio, µg min , then the tangency
portfolio is not defined
If the risk free rate, rf , is greater than the expected return on the
global minimum variance portfolio, µg min , then the tangency
portfolio has a negative Sharpe slope

Eric Zivot (Copyright © 2015) Portfolio Theory 41 / 54


Outline

1 Portfolios with Three Risky Assets


Portfolio characteristics using matrix notation
Finding the global minimum variance portfolio
Finding efficient portfolios
Computing the efficient frontier
Mutual fund separation theorem again

Eric Zivot (Copyright © 2015) Portfolio Theory 42 / 54


Mutual Fund Separation Theorem Again

Efficient Portfolios of T-bills and Risky assets are combinations of two


portfolios (mutual funds).
T-bills
Tangency portfolio
Efficient Portfolios:

xt = share of wealth in tangency portfolio t

xf = share of wealth in T-bills

xt + xf = 1 ⇒ xf = 1 − xt

µep = rf + xt (µp,t − rf ), µp,t = t0 µ


1/2
σpe = xt σp,t , σp,t = t0 Σt

Eric Zivot (Copyright © 2015) Portfolio Theory 43 / 54


Remarks

The weights xt and xf are determined by an investor’s risk preferences.

Risk averse investors hold mostly T-Bills (xt ≈ 0)


Risk tolerant investors hold mostly tangency portfolio (xt ≈ 1)
If Sharpe’s slope for the tangency portfolio is negative then the
efficient portfolio involve shorting the tangency portfolio

Eric Zivot (Copyright © 2015) Portfolio Theory 44 / 54


Example

Example: Find efficient portfolio with target risk (SD) equal to 0.02
Solve,

0.02 = σpe = xt σp,t = xt (0.1116)

0.02
⇒ xt = = 0.1792
0.1116
xf = 1 − xt = 0.8208

Also,

µep = rf + xt (µp,t − rf ) = 0.005 + (0.1116) (0.05189 − 0.005) = 0.0134

σpe = xt σp,t = (0.1792)(0.1116) = 0.02

Eric Zivot (Copyright © 2015) Portfolio Theory 45 / 54


Example

Example: Find efficient portfolio with target ER equal to 0.07 Solve,

0.07 = µep = rf + xt (µp,t − rf )

0.07 − rf 0.07 − 0.005


⇒ xt = = = 1.386
µp,t − rf 0.05189 − 0.005

Also,

σpe = xt σp,t = (1.386)(0.1116) = 0.1547

Eric Zivot (Copyright © 2015) Portfolio Theory 46 / 54


Portfolio Value-at-Risk

Let x = (x1 , . . . , xn )0 denote a vector of asset share for a portfolio.


Portfolio risk is measured by var(Rp,x ) = x0 Σx. Alternatively, portfolio
risk can be measured using Value-at-Risk:

VaRα = W0 qαR

W0 = initial investment

qαR = 100 · α% Simple return quantile

α = loss probability

Eric Zivot (Copyright © 2015) Portfolio Theory 47 / 54


Portfolio Value-at-Risk cont.

If returns are normally distributed then:

qα = µp,x + σp,x qαZ

µp,x = x0 µ
1/2
σp,x = x0 Σx

qαZ = 100 · α% quantile from N (0, 1)

Eric Zivot (Copyright © 2015) Portfolio Theory 48 / 54


Example

Example: Using VaR to evaluate an efficient portfolio

Invest in 3 risky assets (Microsoft, Starbucks, Nordstrom) and T-bills.


Assume rf = 0.005.
1 Determine efficient portfolio that has same expected return as
Starbucks
2 Compare VaR.05 for Starbucks and efficient portfolio based on
$100,000 investment

Eric Zivot (Copyright © 2015) Portfolio Theory 49 / 54


Solution for 1

µSBUX = 0.0285

µep = rf + xt (µp,t − rf )

rf = 0.005

µp,t = t0 µ = .05186, σp,t = 0.111

Solve,

0.0285 = 0.005 + xt (0.05186 − 0.005)

0.0285 − .005
xt = = 0.501
0.05186 − .005
xf = 1 − 0.501 = 0.499

Eric Zivot (Copyright © 2015) Portfolio Theory 50 / 54


Solution for 1 cont.

Note:

µep = 0.005 + 0.501 · (0.05186 − 0.005) = 0.0285

σpe = xt σp,t = (0.501)(0.111) = 0.057

Eric Zivot (Copyright © 2015) Portfolio Theory 51 / 54


Solution for 2

SBUX
q.05 = µSBUX + σSBUX · (−1.645)

= 0.0285 + (0.141) · (−1.645)

= −0.203
e
q.05 = µep + σpe · (−1.645)

= .0285 + (.057) · (−1.645)

− 0.063

Eric Zivot (Copyright © 2015) Portfolio Theory 52 / 54


Solution for 2 cont.

Then,

VaRSBU
.05
X
= $100, 000 · q.05
SBUX

= $100, 000 · (−0.203) = −$20, 300

VaRe.05 = $100, 000 · q.05


e

= $100, 000 · (−0.063) = −$6, 300

Eric Zivot (Copyright © 2015) Portfolio Theory 53 / 54


You can’t see this text!

faculty.washington.edu/ezivot/

Eric Zivot (Copyright © 2015) Portfolio Theory 54 / 54

You might also like