0% found this document useful (0 votes)
19 views38 pages

Vmls Slides Lect17

data

Uploaded by

Dan Dinh
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)
19 views38 pages

Vmls Slides Lect17

data

Uploaded by

Dan Dinh
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/ 38

17.

Constrained least squares applications


Outline

Portfolio optimization

Linear quadratic control

Linear quadratic state estimation

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.1


Portfolio allocation weights

I we invest a total of V dollars in n different assets (stocks, bonds, . . . ) over


some period (one day, week, month, . . . )
I can include short positions, assets you borrow and sell at the beginning,
but must return to the borrower at the end of the period
I portfolio allocation weight vector w gives the fraction of our total portfolio
value held in each asset
I Vwj is the dollar value of asset j you hold
I 1T w = 1, with negative wi meaning a short position
I w = ( 0.2, 0.0, 1.2) means we take a short position of 0.2V in asset 1,
don’t hold any of asset 2, and hold 1.2V in asset 3

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.2


Leverage, long-only portfolios, and cash

I leverage is L = |w1 | + · · · + |wn |


( (L 1)/2 is also sometimes used)

I L = 1 when all weights are nonnegative (‘long only portfolio’)


I w = 1/n is called the uniform portfolio

I we often assume asset n is ‘risk-free’ (or cash or T-bills)

I so w = en means the portfolio is all cash

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.3


Return over a period

I r̃j is the return of asset j over the period


I r̃j is the fractional increase in price or value (decrease if negative)
I often expressed as a percentage, like +1.1% or 2.3%
I full portfolio return is
V+ V
= r̃T w
V
where V + is the portfolio value at the end of the period
I if you hold portfolio for t periods with returns r1 , . . . , rt value is

Vt+1 = V1 (1 + r1 )(1 + r2 ) · · · (1 + rt )

I portfolio value versus time traditionally plotted using V1 = $10000

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.4


Return matrix

I hold portfolio with weights w over T periods

I define T ⇥ n (asset) return matrix, with Rtj the return of asset j in period t

I row t of R is r̃tT , where r̃t is the asset return vector over period t

I column j of R is time series of asset j returns

I portfolio returns vector (time series) is T -vector r = Rw

I if last asset is risk-free, the last column of R is µrf 1, where µrf is the
risk-free per-period interest rate

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.5


Portfolio return and risk

I r is time series (vector) of portfolio returns


I average return or just return is avg(r)

I risk is std(r)

I these are the per-period return and risk

I for small per-period returns we have

VT+1 = V1 (1 + r1 ) · · · (1 + rT )
⇡ V1 + V1 (r1 + · · · + rT )
= V1 + T avg(r)V1

I so return approximates the average per-period increase in portfolio value

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.6


Annualized 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


p
annualized return = P avg(r), annualized risk = P std(r)

(the squareroot in risk annualization comes from the assumption that the
fluctuations in return around the mean are independent)

I if returns are daily, with 250 trading days in a year


p
annualized return = 250 avg(r), annualized risk = 250 std(r)

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.7


Portfolio optimization

I how should we choose the portfolio weight vector w?

I we want high (mean) portfolio return, low portfolio risk

I we know past realized asset returns but not future ones

I we will choose w that would have worked well on past returns

I . . . and hope it will work well going forward (just like data fitting)

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.8


Portfolio optimization

minimize std(Rw) 2 = (1/T)kRw ⇢1k 2


subject to 1T w = 1
avg(Rw) = ⇢

I w is the weight vector we seek


I R is the returns matrix for past returns
I Rw is the (past) portfolio return time series
I require mean (past) return ⇢
I we minimize risk for specified value of return
I solutions w are Pareto optimal

I we are really asking what would have been the best constant allocation,
had we known future returns

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.9


Portfolio optimization via constrained least squares

minimize kRw ⇢1k 2


" T # " #
1 1
subject to w=
µT ⇢

I µ = RT 1/T is n-vector of (past) asset returns


I ⇢ is required (past) portfolio return
I an equality constrained least squares problem, with solution

26 w 37 26 2RT R 1 µ 37 1 26 2⇢T µ 37
66 z 77 = 66 1T 77 66 1 77
66 1 77 66 0 0 77 66 77
4 z2 5 4 µ 5 4 ⇢ 5
T 0 0

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.10


Optimal portfolios

I perform significantly better than individual assets

I risk-return curve forms a straight line

I one end of the line is the risk-free asset

I two-fund theorem: optimal portfolio w is an affine function of ⇢

26 w 37 26 2RT R 1 µ 37 1 26 0 37 26 2RT R 1 µ 37 1 26 2T µ 37
66 z 77 = 66 1T 77 66 1 77 + ⇢ 66 1T 77 66 0 77
66 1 77 66 0 0 77 66 77 66 0 0 77 66 77
4 z2 5 4 µ 5 4 5 4 µ 5 4 1 5
T 0 0 0 T 0 0

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.11


The big assumption

I now we make the big assumption (BA):

– 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

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.12


Example

20 assets over 2000 days

0.4
Annualized return

0.3

0.2

0.1

0
risk-free asset

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7


Annualized risk

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.13


Pareto optimal portfolios

0.4
Annualized return

0.3

0.2

0.1

1/n
0

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7


Annualized risk

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.14


Five portfolios

Return Risk
Portfolio Train Test Train Test Leverage
risk-free 0.01 0.01 0.00 0.00 1.00
⇢ = 10% 0.10 0.08 0.09 0.07 1.96
⇢ = 20% 0.20 0.15 0.18 0.15 3.03
⇢ = 40% 0.40 0.30 0.38 0.31 5.48
1/n (uniform weights) 0.10 0.21 0.23 0.13 1.00

I train period of 2000 days used to compute optimal portfolio


I test period is different 500-day period

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.15


Total portfolio value

Train Test
18
150
Risk-free
Value (thousand dollars)

1/n 16
10%
100 20%
14
40%

50 12

10 10

0 400 800 1200 1600 2000 0 100 200 300 400 500
Day Day

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.16


Outline

Portfolio optimization

Linear quadratic control

Linear quadratic state estimation

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.17


Linear dynamical system

xt+1 = At xt + Bt ut , yt = Ct xt , t = 1, 2, . . .

I n-vector xt is state at time t


I m-vector ut is input at time t
I p-vector yt is output at time t
I n ⇥ n matrix At is dynamics matrix
I n ⇥ m matrix Bt is input matrix
I p ⇥ n matrix Ct is output matrix
I xt , ut , yt often represent deviations from a standard operating condition

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.18


Linear quadratic control

minimize Joutput + ⇢Jinput


subject to xt+1 = At xt + Bt ut , t = 1, . . . , T 1
x1 = xinit , xT = xdes

I variables are state sequence x1 , . . . , xT and input sequence u1 , . . . , uT 1


I two objectives are quadratic functions of state and input sequences:

Joutput = ky1 k 2 + · · · + kyT k 2 = kC1 x1 k 2 + · · · + kCT xT k 2


Jinput = ku1 k 2 + · · · + kuT 1 k 2

I first constraint imposes the linear dynamics equations


I second set of constraints specifies the initial and final state
I ⇢ is positive parameter used to trade off the two objectives

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.19


Constrained least squares formulation

minimize kC1 x1 k 2 + · · · + kCT xT k 2 + ⇢ku1 k 2 + · · · + ⇢kuT 1 k 2


subject to xt+1 = At xt + Bt ut , t = 1, . . . , T 1
x1 = xinit , xT = xdes

I can be written as
minimize k Ãz b̃k 2
subject to C̃z = d̃
I vector z contains the Tn + (T 1)m variables:

z = (x1 , . . . , xT , u1 , . . . , uT 1 )

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.20


Constrained least squares formulation

26 C1 ··· 0 0 ··· 0 37
66 .. .. .. .. 77
66 77
.. ..
. . . . . .
66 0 ··· CT 0 ··· 0 77
à = 66 7,
0 77
p b̃ = 0
66 0 ··· 0 ⇢I ···
66 .. .. .. .. 77
. 77
.. ..
66 . . . . .
⇢I 75
p
4 0 ··· 0 0 ···

26 A1 I 0 ··· 0 0 B10 ··· 0 37 26 0 37


66 77 66 77
66 0 A2 I · · · 0 0 0 B2 · · · 0 77 66 0 77
6 .. .. .. .. .. .... . . . 77 6 .. 77
C̃ = 66 . . . . . . . . ..
77 , d̃ = 66 .
7
66 0 0 0 · · · AT I 0 0 · · · BT 77 66 0 77
66 66 xinit 77
1 1

66
I 0 0 ··· 0 0 0 0 ··· 0 77 66 7
4 0 0 0 ··· 0 I 0 0 ··· 0 75 4 xdes 75

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.21


Example

I time-invariant system: system matrices are constant

26 0.855 1.161 0.667 37 26 0.076 37


A = 666 0.015 1.073 0.053 77 ,
77 B = 666 0.139 777 ,
64 0.084 0.059 1.022 5 64 0.342 75
f g
C= 0.218 3.597 1.683

I initial condition xinit = (0.496, 0.745, 1.394)

I target or desired final state xdes = 0

I T = 100

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.22


Optimal trade-off curve

4.4

4.2

⇢=1
Joutput

⇢ = 0.2
3.8
⇢ = 0.05

3.6

0 1 2 3 4
Jinput

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.23


Three points on the trade-off curve

0.5 0.4
⇢ = 0.05 0 0.2
ut

yt
0.5 0
0 20 40 60 80 100 0 20 40 60 80 100

0.5 0.4
⇢ = 0.2 0 0.2
ut

yt

0.5 0
0 20 40 60 80 100 0 20 40 60 80 100

0.5 0.4
⇢=1 0 0.2
ut

yt

0.5 0
0 20 40 60 80 100 0 20 40 60 80 100
t t
Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.24
Linear state feedback control

I linear state feedback control uses the input

ut = Kxt , t = 1, 2, . . .

I K is state feedback gain matrix


I widely used, especially when xt should converge to zero, T is not specified

I one choice for K : solve linear quadratic control problem with xdes = 0
I solution ut is a linear function of xinit , so u1 can be written as

u1 = Kxinit

I columns of K can be found by computing u1 for xinit = e1 , . . . , en


I use this K as state feedback gain matrix

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.25


Example

0.1 0.4

State feedback
0 Optimal
ut

0.2
yt

Optimal

State feedback
0.1
0
0 50 100 150 0 50 100 150
t t

I system matrices of previous example


I blue curve uses optimal linear quadratic control for T = 100
I red curve uses simple linear state feedback ut = Kxt

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.26


Outline

Portfolio optimization

Linear quadratic control

Linear quadratic state estimation

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.27


State estimation

I linear dynamical system model:

xt+1 = At xt + Bt wt , yt = Ct xt + vt , t = 1, 2, . . .

I xt is state (n-vector)
I yt is measurement (p-vector)
I wt is input or process noise (m-vector)
I vt is measurement noise or measurement residual (p-vector)
I we know At , Bt , Ct , and measurements y1 , . . . , yT

I wt , vt are unknown, but assumed small


I state estimation: estimate/guess x1 , . . . , xT

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.28


Least squares state estimation

minimize Jmeas + Jproc


subject to xt+1 = At xt + Bt wt , t = 1, . . . , T 1

I variables: states x1 , . . . , xT and input noise w1 , . . . , wT 1

I primary objective Jmeas is sum of squares of measurement residuals:

Jmeas = kC1 x1 y1 k 2 + · · · + kCT xT yT k 2

I secondary objective Jproc is sum of squares of process noise

Jproc = kw1 k 2 + · · · + kwT 1 k 2

I > 0 is a parameter, trades off measurement and process errors

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.29


Constrained least squares formulation

minimize kC1 x1 y1 k 2 + · · · + kCT xT yT k 2 + (kw1 k 2 + · · · + kwT 1 k 2 )


subject to xt+1 = At xt + Bt wt , t = 1, . . . , T 1

I can be written as
minimize k Ãz b̃k 2
subject to C̃z = d̃
I vector z contains the Tn + (T 1)m variables:

z = (x1 , . . . , xT , w1 , . . . , wT 1 )

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.30


Constrained least squares formulation

26 C1 0 ··· 0 0 ··· 0 37 26 y1 37
66 0 C2 0 0 0 77 66 77
66 77 66 77
··· ··· y2
66 .. .. ..
.
.. .. .. 77 66 .. 77
6 77 6 77
. . . . . .
à = 66 0 0 ··· CT 0 ··· 0 77 , b̃ = 66 yT 77
66 p
77 66 77
66 0 0 ··· 0 I ··· 0
77 66 0
77
66 .. .. .. .. .. ..
77 66 ..
77
66 66
. . . . .
p. .
4 0 0 ··· 0 0 ··· I 75 4 0 75

26 A1 I 0 ··· 0 0 B1 0 ··· 0 37
66 77
C̃ = 666 77 ,
0 A2 I ··· 0 0 0 B2 ··· 0
66
.. .. .. .. .. .. .. .. .. 77 d̃ = 0
77
. . . . . . . . .
64 0 0 0 ··· AT 1 I 0 0 ··· BT 1 5

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.31


Missing measurements

I suppose we have measurements yt for t 2 T , a subset of {1, . . . , T }

I measurements for t < T are missing

I to estimate states, use same formulation but with


X
Jmeas = kCt xt yt k 2
t2 T

I from estimated states x̂t , can estimate missing measurements

ŷt = Ct x̂t , t<T

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.32


Example

26 37 26 37
6
1 0 1 0
77 6
0 0
77 " #
At = 666 Bt = 666
0 1 0 1 0 0 1 0 0 0
77 , 77 , Ct =
66 0 0 1 0 77 66 1 0 77 0 1 0 0
4 0 0 0 1 5 4 0 1 5

I simple model of mass moving in a 2-D plane

I xt = (pt , zt ) : 2-vector pt is position, 2-vector zt is the velocity


I yt = Ct xt + wt is noisy measurement of position
I T = 100

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.33


Measurements and true positions

0
t=1

500
(xt )2

1000

1500 t = 100

0 100 200 300


(xt )1
I solid line is exact position Ct xt
I 100 noisy measurements yt shown as circles

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.34


Position estimates

=1 = 103 = 105

blue lines show position estimates for three values of

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.35


Cross-validation

I randomly remove 20% (say) of the measurements and use as test set

I for many values of , estimate states using other (training) measurements

I for each , evaluate RMS measurement residuals on test set

I choose to (approximately) minimize the RMS test residuals

Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.36


Example

80

60
RMS error

Test
40

20

Train
0
10 3 10 1 101 103 105

I cross-validation method applied to previous example


I remove 20 of the 100 measurements
I suggests using ⇡ 103
Introduction to Applied Linear Algebra Boyd & Vandenberghe 17.37

You might also like