Portfolio Optimization
Jaehyun Park Stephen Boyd
EE103
Stanford University
November 26, 2016
Outline
Single asset investment
Portfolio investment
Portfolio optimization
Single asset investment 2
Return of an asset over one period
I asset can be stock, bond, real estate, commodity, . . .
I invest in a single asset over period (quarter, week, day, . . . )
I buy q shares at price p (at beginning of investment period)
I h = pq is dollar value of holdings
I sell q shares at new price p+ (at end of period)
p+ −p
I profit is qp+ − qp = q(p+ − p) = p h
p+ −p profit
I define return r = p = investment
I profit = rh
I example: invest h = $1000 over period, r = +0.03: profit = $30
Single asset investment 3
Short positions
I basic idea: holdings h and share quantities q are negative
I called shorting or taking a short position on the asset
(h or q positive is called a long position)
I how it works:
– you borrow q shares at the beginning of the period and sell them at
price p
– at the end of the period, you have to buy q shares at price p+ to
return them to the lender
I all formulas still hold, e.g., profit = rh
I example: invest h = −$1000, r = −0.05: profit = +$50
I no limit to how much you can lose when you short assets
I normal people (and mutual funds) don’t do this; hedge funds do
Single asset investment 4
Return of an asset over multiple periods
I invest over periods t = 1, 2, . . . , T
(quarters, trading days, minutes, seconds . . . )
I pt is price at the beginning of period t
pt+1 −pt
I return over period t is rt = pt
I invest dollar amount ht in period t, or share number qt = ht /pt
I profit over period t is rt ht
PT
I total profit is t=1 rt ht
PT
I per period profit is T1 t=1 rt ht
Single asset investment 5
Examples
stock prices of BP (BP) and Coca-Cola (KO) for last 10 years
70
KO
BP
60
50
40
Prices
30
20
10
0
0 500 1000 1500 2000 2500
Days
Single asset investment 6
Examples
price changes over a few weeks
70
KO
BP
60
50
40
Prices
30
20
10
0
1600 1605 1610 1615 1620 1625 1630 1635 1640 1645 1650
Days
Single asset investment 7
Examples
returns of the assets over the same period
0.2
KO
BP
0.15
0.1
0.05
Returns
−0.05
−0.1
−0.15
−0.2
1600 1605 1610 1615 1620 1625 1630 1635 1640 1645 1650
Days
Single asset investment 8
Buy and hold
I a very simple choice of ht
I qt = q for all t = 1, 2, . . . , T
– buy q shares at the beginning of period 1
– sell q shares at the end of period T
I hence ht = pt q
I profit is
T T
X X pt+1 − pt
rt ht = (pt q) = q(pT +1 − p1 )
t=1 t=1
pt
I same as combining periods 1, . . . , T into a single period
Single asset investment 9
Cumulative value plot
plot of ht = pt q versus t (h1 = $10,000 by tradition)
4
x 10
2.5
KO
MSFT
2
Value
1.5
0.5
0 500 1000 1500 2000 2500
Days
Single asset investment 10
Constant value
I another simple choice of ht : ht = h, t = 1, . . . , T
I number of shares qt = h/pt (which varies with t)
I requires buying or selling shares every period to keep value constant
PT
I profit is t=1 rt h
PT
I per period profit is (1/T ) t=1 rt h = avg(rt )h (in $)
I mean return is avg(rt ) (fractional; often expressed in %)
I profit standard deviation is std(rt h) = std(rt )h (in $)
I risk is std(rt ) (fractional)
I want per period profit high, risk low
Single asset investment 11
Annualizing return and risk
I mean return and risk are often expressed in annualized form
(i.e., per year)
I if there are P trading periods per year
– annualized return √
= P avg(rt )
– annualized risk = P std(rt )
(the squareroot in risk annualization comes from the assumption
that the fluctuations in return around the mean are independent)
I if t denotes trading days, with 250 trading days in a year
– annualized return √
= 250 avg(rt )
– annualized risk = 250 std(rt )
Single asset investment 12
Risk-return plot
I annualized risk versus annualized return of various assets
I up (high return) and left (low risk) is good
25
SBUX
20
GS
Annualized Return
15
BRCM
MMM
10
USDOLLAR
0
0 10 20 30 40 50 60
Annualized Risk
Single asset investment 13
Outline
Single asset investment
Portfolio investment
Portfolio optimization
Portfolio investment 14
Portfolio of assets
I n assets
I n-vector pt is prices of assets in period t, t = 1, 2, . . . , T
I n-vector ht is dollar value holdings of the assets
I total portfolio value: Vt = 1T ht
I n-vector qt is the number of shares: (qt )i = (ht )i /(pt )i
I wt = (1/1T ht )ht gives portfolio weights or allocation
(fraction of total portfolio value, defined only for 1T ht > 0)
Portfolio investment 15
Examples
I (h3 )5 = −1000 means you short asset 5 in investment period 3 by
$1,000
I (w2 )4 = 0.20 means 20% of total portfolio value in period 2 is
invested in asset 4
I wt = (1/n, . . . , 1/n), t = 1, . . . , T means total portfolio value is
equally allocated across assets in all investment periods
I 1T ht = 0 means total short positions = total long positions
Portfolio investment 16
Buy and hold portfolio
I same idea as single asset case
I (n-vector) qt = q for all t = 1, . . . , T
I holdings given by (ht )i = (pt )i qi , i = 1, . . . , n
I profit is
T T X
n
X X (pt+1 )i − (pt )i
rtT ht = ((pt )i qi ) = q T (pT +1 − p1 )
t=1 t=1 i=1
(pt )i
Portfolio investment 17
Constant value portfolio
I simple choice of ht : ht = h, t = 1, . . . , T
I requires rebalancing (buying and selling) shares to maintain
(ht )i = hi every period
PT
I profit is t=1 rtT h
PT
I per period profit is (1/T ) t=1 rtT h (in $)
I mean return is avg(rtT h)/1T h (fractional; often expressed in %)
I profit standard deviation is std(rtT h) (in $)
I risk is std(rtT h)/1T h (fractional)
Portfolio investment 18
Risk-return plot for constant value portfolio
20 individual assets in blue, some constant portfolios in red
25
20
good
Annualized Return
15
uniform
10
bad
0
0 10 20 30 40 50 60
Annualized Risk
Portfolio investment 19
Constant weight portfolio with re-investment
I fix weight vector w
I given initial total investment V1 , set h1 = V1 w
I V2 = V1 + r1T h1
I set h2 = V2 w, i.e., re-invest total portfolio value using allocation w
I and so on . . .
I VT = V1 (1 + r1T w)(1 + r2T w) · · · (1 + rTT w)
I Vt ≤ 0 (or some small value like 0.1V1 ) called going bust or ruin
I time series V1 , V2 , . . . is called cumulative value
Portfolio investment 20
Cumulative value plot
uniform portfolio between Coca-Cola (KO) and Microsoft (MSFT), with
h1 = $10,000 (by tradition)
4
x 10
3
uniform portfolio
individual assets
2.5
2
Value
1.5
0.5
0
0 500 1000 1500 2000 2500
Days
Portfolio investment 21
Cumulative value plot
portfolio with large short positions (heavily leveraged) going bust
(dropping to 10% of starting value), with weights w = (−3, 4)
4
x 10
3
leveraged portfolio
individual assets
2.5
2
Value
1.5
0.5
0
0 500 1000 1500 2000 2500
Days
Portfolio investment 22
Comparison: Re-investment or not
I constant value portfolio (without re-investment) gives total profit
PT T
t=1 rt h
I constant weight portfolio (with re-investment) gives total profit
VT − V1 = ((1 + rTT w) · · · (1 + r1T w) − 1)V1
I for |rtT w| all small (say, ≤ 0.01)
T
X
(1 + rTT w) · · · (1 + r1T w) ≈ 1 + rtT w
t=1
PT T
so VT − V1 ≈ t=1 rt wV1
I profit with constant value h ≈ profit with constant weight
w = (1/1T h)h and initial investment h
Portfolio investment 23
Comparison: Re-investment or not
4
x 10
5
no reinvestment
reinvestment
4.5
3.5
3
Value
2.5
1.5
0.5
0
0 500 1000 1500 2000 2500
Days
Portfolio investment 24
Outline
Single asset investment
Portfolio investment
Portfolio optimization
Portfolio optimization 25
Portfolio optimization
I how should we choose a portfolio value vector h, or a portfolio
weight vector w, over some investment period?
I more generally, these vectors could change with time, as our
information or goals changes
I when we choose h or w, we know past returns (‘realized returns’)
but (of course) not future ones
I in all cases, we want high (mean) return, low risk
Portfolio optimization 26
Returns matrix
I define returns matrix
r1T
R = ...
rTT
I row rtT gives returns of all assets in period t
I jth column is asset j return time series
I Rh is profit time series
I 1T Rh is total profit
I avg(Rh) = (1/T )1T Rh is per period profit
I std(Rh) is per period risk
I goal: choose h that makes avg(Rh) high, std(Rh) low
Portfolio optimization 27
Portfolio optimization via least squares on past returns
minimize std(Rh)2 = (1/T )kRh − ρB1k2
subject to 1T h = B, avg(Rh) = ρB
I h is holdings vector to be found
I B is budget to be invested
I R is the returns matrix for past returns
I Rh is the (past) profit time series
I require mean (past) profit ρB
I minimize the standard deviation of (past) profit
I we are really asking what would have been the best constant
allocation, had we known future returns
Portfolio optimization 28
Constant weight portfolio optimization
minimize std(Rw)2 = (1/T )kRw − ρ1k2
subject to 1T w = 1, avg(Rw) = ρ
I very similar to constant holdings optimization
(in fact the two solutions are the same, except for scaling)
I w is weight allocation vector to be found
I Rw is the (past) return time series
I require mean (past) return ρ
I minimize the standard deviation of (past) return
Portfolio optimization 29
Examples
I optimal w for annual return 1% (last asset is risk-less with 1%
return)
w = (0.0000, 0.0000, 0.0000, . . . , 0.0000, 0.0000, 1.0000)
I optimal w for annual return 13%
w = (0.0250, −0.0715, −0.0454, . . . , −0.0351, 0.0633, 0.5595)
I optimal w for annual return 25%
w = (0.0500, −0.1430, −0.0907, . . . , −0.0703, 0.1265, 0.1191)
I asking for higher annual return yields
– more invested in risky, but high return assets
– larger short positions (‘leveraging’)
Portfolio optimization 30
Cumulative value plots for optimal portfolios
cumulative value plot for optimal portfolios and some individual assets
optimal portfolio, rho=0.20/250
optimal portfolio, rho=0.25/250
individual assets
5
10
Value
4
10
0 500 1000 1500 2000 2500
Days
Portfolio optimization 31
Optimal risk-return curve
red curve obtained by solving problem for various values of ρ
25
20
Annualized Return
15
10
0
0 10 20 30 40 50 60
Annualized Risk
Portfolio optimization 32
Optimal portfolios
I perform significantly better than individual assets
I risk-return curve forms a straight line
– one end of the line is the risk-free asset
I two-fund theorem: optimal portfolio w is an affine function in ρ
T −1 T
1 RT 1
w R R R 1
ν1 = 1T 0 0 1
ν2 1T R 0 0 ρT
Portfolio optimization 33
The big assumption
I now we make the big assumption (BA):
future returns will look something like past ones
– you are warned this is false, every time you invest
– it is often reasonably true
– in periods of ‘market shift’ it’s much less true
I if BA holds (even approximately), then a good weight vector for past
(realized) returns should be good for future (unknown) returns
I for example:
– choose w based on last 2 years of returns
– then use w for next 6 months
Portfolio optimization 34
Optimal risk-return curve
I trained on 900 days (red), tested on the next 200 days (blue)
I here BA held reasonably well
Train
25 Test
20
Annualized Return
15
10
0
0 2 4 6 8 10 12 14 16
Annualized Risk
Portfolio optimization 35
Optimal risk-return curve
I corresponding train and test periods
4
x 10
5
4.5
4 Train Test
3.5
2.5
1.5
0.5
0
0 500 1000 1500 2000 2500
Portfolio optimization 36
Optimal risk-return curve
I and here BA didn’t hold so well
I (can you guess when this was?)
25 Train
Test
20
15
10
Annualized Return
−5
−10
−15
−20
0 2 4 6 8 10 12 14 16
Annualized Risk
Portfolio optimization 37
Optimal risk-return curve
I corresponding train and test periods
4
x 10
5
4.5
4 Train Test
3.5
2.5
1.5
0.5
0
0 500 1000 1500 2000 2500
Portfolio optimization 38
Rolling portfolio optimization
for each period t, find weight wt using L past returns
rt−1 , . . . , rt−L
variations:
I update w every K periods (say, monthly or quarterly)
I add cost term κkwt − wt−1 k2 to objective to discourage turnover,
reduce transaction cost
I add logic to detect when the future is likely to not look like the past
I add ‘signals’ that predict future returns of assets
(. . . and pretty soon you have a quantitative hedge fund)
Portfolio optimization 39
Rolling portfolio optimization example
I cumulative value plot for different target returns
I update w daily, using L = 400 past returns
4
x 10
1.3
rho=0.05/250
rho=0.1/250
rho=0.15/250
1.25
1.2
1.15
Value
1.1
1.05
0.95
1600 1700 1800 1900 2000 2100 2200 2300 2400 2500
Days
Portfolio optimization 40
Rolling portfolio optimization example
I same as previous example, but update w every quarter (60 periods)
4
x 10
1.3
rho=0.05/250
rho=0.1/250
rho=0.15/250
1.25
1.2
1.15
Value
1.1
1.05
0.95
1600 1700 1800 1900 2000 2100 2200 2300 2400 2500
Days
Portfolio optimization 41