# A MODEL PREDICTIVE CONTROL APPROACH FOR PAIRS

## A MODEL PREDICTIVE CONTROL APPROACH FOR PAIRS

A MODEL PREDICTIVE CONTROL APPROACH FOR PAIRS TRADING USING MULTIPLE SPREADS September 27th, 2016

James A. PRIMBS Mihaylo College of Business and Economics, Cal State Fullerton, USA 1

Control & Finance  In finance, we need to reduce risk of asset value fluctuation and manage/construct optimal investment portfolios of, e.g., stocks.  These problems may be thought of control problems to find optimal decision variables (e.g., shares of stocks) given optimization criteria.  Reduce risk of asset value fluctuation

Hedging problem

 Construct optimal investment policy

Portfolio optimization

Reference (e.g., risk and return criteria)

Compute optimal portfolio/ hedge

Wealth consisting of Asset 1 ⋮ Asset m

2

Portfolio optimization Find optimal shares of stocks, 𝜷𝟏 , 𝜷𝟐 , to minimize risk under admissible expected return constraint

X t : Stock A

∆X = X t + ∆t − X t

Yt : Stock B

∆Y = Yt + ∆t − Yt

β1 X t + β 2Yt : Portfolio

β1∆X + β 2 ∆Y t t + ∆t

3

Portfolio optimization Find optimal shares of stocks, 𝜷𝟏 , 𝜷𝟐 , to minimize risk under admissible expected return constraint

β1 X t + β 2Yt : Portfolio

β1∆X + β 2 ∆Y t t + ∆t

µ := Ε[β1∆X + β 2 ∆Y ] Fixed expected return −σ

µ

σ

σ 2 := Var [β1∆X + β 2 ∆Y ] Minimize variance (risk)

Distribution of 𝜷𝟏 𝚫𝚫 + 𝜷𝟐 𝚫𝚫

Usually difficult to control expected returns, because of random walks! 4

Model predictive control for spread portfolio optimization

Optimal vs. Myopic portfolios Outline MPC approach for spread portfolio optimization

Concluding remarks

5

Pairs trading Step 1) Find a pair of stocks whose prices tend to move together (say Stock A and Stock B). Stock A Abnormal spread (say, larger than average)

Stock B t Spread = Price of Stock A – Price of Stock B Step 2) If an abnormal spread (say, larger spread than average) is observed, buy one stock (say, Stock B) and short sell the other (say, Stock A), expecting that the spread will converge to the average in a future period. 6

Pairs trading Stock A Average spread (possibly smaller) Stock B t Step 3) When the spread converges to the average, sell Stock B, buy Stock A, and clear the position.

Why pairs trading? From the practical point of view, it always leads to a positive profit if the spread converges. It does not matter whether the market is going up or down. From the economic theory point of view, stock market prices are believed to evolve according to a random walk and thus the prices of the stock market cannot be predicted. In spite of this random walk belief, we often observe that there are pairs of stocks whose spread processes may exhibit predictable mean reversions.

“Cointegration” of pairs of stocks 8

What is cointegration? Random walk: Assume that you are walking when you are really drunk. You are not sure which way you are walking. Then the location you have at time t just depends on the location at time t-1 plus “random noise”

X t = X t −1 + “random noise” In this case,{X t } has a unit root and is nonstationary ⇒ Random walk Cointegration: Assume that there are two random walk processes, X t and Yt . If there exists a constant β (≠ 0 ) s.t. X t − β Yt is stationary, then X t and Yt are said to be cointegrated.

 The spread of cointegrated stocks has predictable mean-reverting property.  Construct an optimal portfolio on multiple spreads of cointegrated stocks. 9

Spread process We should find cointegrated pairs of stocks for pairs trading, because their spreads are expected to converge on average. That is, find pairs of stocks whose prices are X t ~ I (1) and Yt ~ I (1), but St := X t − βYt is stationary expressed as, e.g., AR(q): S t = φ1S t −1 + φ2 S t − 2 +  + φq S t − q + ε t In the simplest case of q = 1, it holds that

St − St −1 = (φ1 − 1)St −1 + ε t Using continuous time notation, the above equation corresponds to the following Ornstein-Uhlenbeck (OU) process:

dSt = −κ (St − θ )dt + σdZ t

10

Model predictive control for spread portfolio optimization

Optimal vs. Myopic portfolios Outline MPC approach for spread portfolio optimization

Concluding remarks

11

Spread portfolio optimization problem  Basic idea:  If a pair of stocks is cointegrated, their price difference (or spread) may be modeled as a stationary process  The spread of each pair of stocks can be traded directory by taking a long-short position on the two stocks  Assumption: (i ) (i )  m pairs of stock prices, X t and Yt , whose spreads are modelled as

St( i ) := X t( i ) − β ( i )Yt ( i ) , St( i ) = φ1( i ) St(−i 1) +  + φq( i ) St(−i )q + σ ( i )ε t( i ) , i = 1,, m

[

] : Shares invested in each entry of S := [S

(m) T t

ut := u ,, u (1) t

t

(

T T  Wealth dynamics: ∆Wt = ut ∆S t + rf Wt − ut S t

)

= rf Wt + Wt vtT (∆St − rSt ),

(1) t

,, S

]

(m) T t

Risk free interest rate

vt := ut Wt

12

Method 1: Myopic portfolio  Conditional mean & variance on the wealth return

 ∆Wt   ∆Wt  T T Εt  ( [ ] ) v S rS , = r + Ε ∆ − V = v t f t t t t   t Σvt  Wt   Wt  Σ ∈ℜ

m×m

(i ) (i ) σ ε t , i = 1,, m Covariance matrix of :

 Conditional mean-variance optimization on the wealth return:

  ∆Wt  γ  ∆Wt   max Ε t  − ⋅ Vt    vt 2 W W  t    t 

γ : Risk aversion coefficient  Mean-variance optimal portfolio: v = Σ −1 (Ε t [∆St ] − rSt ), ut∗ = vt∗Wt γ (Myopic portfolio) ∗ t

1

13

Method 2: Long term optimal portfolio  Long term optimal portfolio for spreads [Kim, Primbs and Boyd 2008]:

[

]

1 E WT1−γ vt 1− γ s.t. dSt = − K (St − θ )dt + BdZ t dWt = rdt + vtT ((− K ( X t − θ ) − rS t )dt + BdZ t ) Wt

max

κ (1) σ (1)  θ (1)   St(1)  0  0          = St =   , θ =   , K =  , B      (N )  (N )   0  0  St( N )  θ ( N )  κ σ         - The solution depends on a Riccati equation and linear differential equations [Herzog et al. ‘04, Campbell et al. ’03, Campbell and Viceira ’02] and is dynamic. 14

Search for Cointegrated Pairs  Apply the following procedures to search for cointegrated pairs

Screening procedure) Compute the DF statistics and the correlation coefficient of each pair. If the absolute value of correlation coefficient is below 0.8 or the DF statistics is above certain CV, then remove the pair.

Selection procedure) Sort the pairs following the order of smaller DF statistics. Apply the Engle-Granger cointegration test [Engle and Granger 1987] from the top of the list to select cointegrated pairs without overlap of a company. 15

Search for Cointegrated Pairs DF statistics of the spread: S t := X t − β X |Y Yt

∆St −1 = bSt −1 + ε t , ∆St −1 = St − St −1 bˆ , bˆ : OLS estimator DF statistics := Standard Error If the DF statistics is less than a critical value with a given significance level, the null hypothesis of “unit root” is rejected. The smaller DF statistics is, the stronger the rejection of the hypothesis.

16

Automotive industries Correlation coefficients vs. DF statistics: Nissan, Isuzu, Toyota, Hino, Matsuda, Honda, Suzuki, Subaru, Mitsubishi (2004-2006) 0

-0.5

-1

DF statistics

-1.5

Nissan Isuzu Toyota Hino Matsuda Honda Suzuki Subaru Mitsubishi

Stronger indication of possible cointegration

-2

-2.5

5% critical value

MatsudaNissan

-3

-3.5

-4 -0.5

0

0.5

1

ToyotaNissan

Correlation coefficient 17

Empirical simulation 1st Analysis: Find cointegrated pairs of stocks in Nikkei 225 using data period of 2004-2006 (3 years), construct the optimal and myopic portfolios, and simulate the out-of-sample performance of 2007 (or later period) Possible combinations of pairs are 225×(225-1)/2 = 25,200, but in fact we need to check the double of this number by switching dependent and independent variables in the linear regression. # of pairs is 50,400

X t = β X |Y Yt + const + residuals Yt = βY | X X t + const + residuals Nikkei 225 has 35 categories of industries, so choose some and find cointegrated pairs in each category. 10 categories consisting of 84 industries 18

Search for Cointegrated Pairs By applying the screening and selection procedure, the following 13 pairs were selected using the data in the period of 2004-2006: Japan Tobacco vs. Asahi Breweries (Foods) Showa Shell Sekiyu vs. Nippon Oil (Oil & coal products) Tokyo Electron vs. Sharp (Electric machinery) TDK vs. Fuji Electric (Electric machinery) Panasonic vs. Meidensha (Electric machinery) Panasonic Electric Works vs. Sony (Electric machinery) Minebea vs. Kyocera (Electric machinery) Toyota vs. Nissan (Automotive) Olympus vs. Nikon (Precision instruments) Tokyu vs. Tobu (Railway/Bus) KDDI vs. NTT (Communications) Chubu vs. Kansai (Electric power) CSK vs. Dentsu (Services) 19

Out-of-Sample Simulations Objective: Apply the optimal and myopic portfolios for pairs trading to evaluate the out-of-sample performance  Number of pairs?  Data periods? Simulation 1)  Data period: Fixed - Parameter estimation period; 2004—2006

- Simulation peirod (out-of-sample); 2007  Number of pairs: Vary from 3 to 13 Simulation 2)  Number of pairs: Fixed (=13)  Simulation period: Vary from 2007 to 2009 20

Simulation 1) # of pairs? - Parameter estimation period; 2004—2006 - Simulation peirod (out-of-sample); 2007 Number of pairs: 3

Number of pairs: 13

Optimal (γ = 1000), Myopic (γ = 100), # of pairs = 3

Optimal (γ = 1000), Myopic (γ = 100), # of pairs = 13 4.5

2.2

Optimal Myopic

Optimal Myopic 4

2 3.5

Wealth processes

1.8

wealth

wealth

3 1.6

2.5

1.4 2 1.2

1.5

1

1 0

50

100 150 time in days

200

0

50

100 150 time in days

200

21

Simulation 1) # of pairs? - Number of pairs vs. Average annualized Sharpe ratio 3 Optimal

Average annualized sharp ratio Average annualized Sharpe ratio

Myopic

2.5

2

Sharpe ratio =

1.5

Mean rate of return – Risk free rate Standard deviation 1

0.5 2

4

6

8

10

12

Number of pairs

Number of pairs 22

Simulation 2) Extend simulation period  Number of pairs: Fixed (=13) - Parameter estimation period; 2005—2007 - Simulation peirod (out-of-sample); 2008 Optimal (γ = 1000), Myopic (γ = 100), # of pairs = 13 1.8 Optimal Myopic

1.7 1.6 1.5

wealth

1.4 1.3 1.2 1.1 1 0.9 0.8

0

50

100 150 time in days

200 23

Simulation 2) Extend simulation period  Number of pairs: Fixed (=13) - Parameter estimation period; 2005—2007 - Simulation peirod (out-of-sample); 2008-2009.4 Optimal (γ = 1000), Myopic (γ = 100), # of pairs = 13 1.8 Optimal Myopic

1.7 1.6 1.5

wealth

1.4 1.3 1.2 1.1 1 0.9 0.8

0

50

100

150 time in days

200

250

300 24

Simulation 2) Extend simulation period  Number of pairs: Fixed (=13) - Parameter estimation period; 2005—2007 - Simulation peirod (out-of-sample); 2008-2009.10 Optimal (γ = 1000), Myopic (γ = 100),

# of pairs =

13

1.8 Optimal Myopic

1.7 1.6 1.5

wealth

1.4 1.3 1.2 1.1 1 0.9 0.8

0

50

100

150

200 250 time in days

300

350

400 25

Summary so far  Myopic vs. Long term optimal portfolios  Long term optimal portfolio provides a better wealth level.  In terms of Sharpe ratio, myopic portfolio seems to be better.  Long term optimal portfolio is not as good as expected…  May be inflexible, due to fixed horizon and control policy.  Extend myopic portfolio to take longer horizon & flexible control period into account.

Model predictive control for spread portfolio optimization

Optimal vs. Myopic portfolios Outline MPC approach for spread portfolio optimization

Concluding remarks

27

Myopic vs. MPC vs. Long term optimal Predict next day returns

Myopic

Day 0

Day 1

Day 2

Day 3

Time in Days

Day 3

Time in Days

Day 3

Time in Days

Fix the target horizon at the maturity

Optimal

Day 0

Day 1

Day 2

Predict long horizon returns (say, one month)

MPC

Day 0

Day 1

Day 2

28

Model predictive control for spread trading  Basic idea  Express multivariate spread process based on VARMA model.  Solve conditional MV problem for arbitrarily long prediction horizon using the prediction of future spread.  Once the conditional MV problem is solved, we can calculate an optimal portfolio that gives a static feedback control law.  Update the control law dynamically with the current state variables for the spreads at each rebalance period.

29

Construction of MPC VAR (q ) : St = Φ1St −1 +  + Φ q St − q + c + et , Φ i ∈ ℜm×m , c ∈ ℜm

[

St := S ,, S (1) t

],

(m) T t

St( i ) := X t( i ) − β ( i )Yt ( i ) ,

i = 1,, m

et ~ N (0, Σ ), Σ ∈ ℜm×m : covariance matrix

 Wealth in the future time horizon: Wt +τ = u St +τ + (1 + rf ) T t

τ

(

[

)

]

T

Wt − u St , ut := ut(1) ,  , ut( m ) ∈ ℜ m T t

 Total return of the wealth: Wt +τ τ τ Rt ,τ := = (1 + r ) + vtT St +τ − (1 + r ) St , Wt  Conditional mean-variance optimization:

[

]

ut vt := Wt

γ   maxm Ε t [Rt ,τ ] − ⋅ Vt [Rt ,τ ], Vt [Rt ,τ ] = Vt vtT St +τ : conditional variance ut ∈ℜ  2 

[

]

30

Construction of MPC VAR (1) : St = Φ1St −1 + c + et , Φ1 ∈ ℜ16×16

St +τ = Φ1St +τ −1 + c + et +τ = Φ12 St +τ −2 + (Φ1 + 1)c + (Φ1et +τ −1 + et +τ ) =   

= Φτ1 St + (Φτ1 −1 +  + Φ1 + I )c + (Φτ1 −1et +1 +  + Φ1et +τ −1 + et +τ )

 Predicted value: Ε t (St +τ ) = Φτ1 St + (Φτ1 −1 +  + Φ1 + I )c  Optimal control input (share unit vector on the spread): u = * t

Wt

γ

(Σ + Φ ΣΦ 1

T 1

+  Φ1 Σ(Φ1 τ −1

) ) × [Ε (S ) − (1 + r )S ]∈ ℜ

−1 τ −1 T

t

t +τ

τ

16

t

Prediction horizon: τ

MPC

Day 0 ControlDay 1 Day 2 Day 3 period (rebalance interval): δ

Time in Days 31

New simulations  List of 16 pairs based on the data period of 2007—2009: Sapporo vs. Asahi Breweries (Foods) Ajinomoto vs. Kikkoman (Foods) Nippon Oil vs. Nippon Mining Holdings (Oil & coal products) Advantest vs. Taiyo Yuden (Electric machinery) TDK vs. Tokyo Electron (Electric machinery) Canon vs. Kyocera (Electric machinery) Minebea vs. Denso (Electric machinery) Fanuc vs. Toshiba (Electric machinery) Fuji Electric vs. Sony (Electric machinery) Honda vs. Nissan (Automotive) Matsuda vs. Fuji Heavy Industries (Automotive) Konica Minolta Holdings vs. Nikon (Precision instruments) West Japan Railway vs. East Japan Railway (Railway/Bus) NTT Data vs. NTT (Communications) Tokyo Gas vs. Chubu Electric Power (Gas/Electric power) Yahoo vs. Konami (Services)

32

Myopic vs. MPC with different prediction horizons - Myopic; τ = 1 day (prediction horizon) & δ = 1 day (rebalance interval) - MPC; τ = 20 days and τ = 80 days with δ = 1 day 5.5 Myopic MPC with 1 month prediction horizon MPC with 4 month prediction horizon

5 4.5 4

wealth

3.5

Sharpe ratio: 5.25

3

Sharpe ratio: 5.01 2.5 2 1.5

Sharpe ratio: 4.31

1 0.5

0

20

40

60

80

120 100 time in days

140

160

180

200 33

Prediction horizon vs. Sharpe ratio - Rebalance interval 【𝜹】; 1 day - Prediction horizon 【𝝉】; 1day (myopic) – 160 days (8 months) 5.3 5.2 5.1

Sharpe ratio

5 4.9 4.8 4.7 4.6 4.5

Myopic

4.4 4.3

20

40

60

80 100 Prediction horizon

120

140

160 34

MPC with different rebalance interval δ = 1 day, 5 days, and 20 days (τ = 60 days)

δ vs. Sharpe ratio (τ = 1 day and 60 days)

5.5

5.5 Rebalance interval = 1 Rebalance interval = 5 Rebalance interval = 20

5

Prediction horizon = 1 (myopic) Prediction horizon = 60 (3 months)

5

4.5

4.5

4 4 Sharpe ratio

wealth

Sharpe ratio: 5.25 3.5 3

Sharpe ratio: 3.92

2.5

3 2.5

2

2

1.5 1

3.5

Sharpe ratio: 2.68 0

20

40

60

80

120 100 time in days

140

160

180

200

1.5

5

10

15

25 20 Rebalance interval

30

35

40

- A larger δ (less frequent rebalance) tends to provide a lower level of Sharpe ratio - MPC is almost always better for rebalance interval of δ ≤ 40 days 35

Effect of transaction costs (1) - Proportional transaction cost of 0.5% - Prediction horizon; 1 day, 5 days, and 20 days Rebalance interval; 1 day

Rebalance interval; 20 days

δ = 1, ρ = 0.005

1.5

Prediction horizon = 1 Prediction horizon = 5 Prediction horizon = 20

1.4

Prediction horizon = 1 Prediction horizon = 5 Prediction horizon = 20

1.7 1.6

Sharpe ratio: 0.59

1.3

δ = 20, ρ = 0.005

1.8

Sharpe ratio: 1.62

1.5

wealth

wealth

1.2

Sharpe ratio: −0.088

1.1

1.4

Sharpe ratio: 1.45

1.3 1.2

1

0.9

0.8

1.1

Sharpe ratio: −0.36

Sharpe ratio: 1.36

1

0

20

40

60

80

100 120 time in days

140

160

180

200

0.9

0

20

40

60

80

100 120 time in days

140

160

180

200

36

Effect of transaction costs (2) - Prediction horizon vs. Sharpe ratio for different transaction cost rates Rebalance interval; 1 day

Rebalance interval; 20 days

δ=1

6

δ = 20

2.8 2.6

5

2.4

Sharpe Sharpe ratioratio

Sharpe ratioratio Sharpe

4

3

2

2.2 2 1.8

ρ ρ ρ ρ ρ ρ

1

0

-1

20

40

60

100 80 Prediction horizon

120

140

= = = = = =

0.0% 0.1% 0.2% 0.3% 0.4% 0.5%

ρ ρ ρ ρ ρ ρ

1.6 1.4

160

20

40

60

100 80 Prediction horizon

120

140

= = = = = =

0.0% 0.1% 0.2% 0.3% 0.4% 0.5% 160

Myopic 37

Effect of transaction costs (3) - Transaction cost rates vs. Sharpe ratio for different rebalance interval, δ 5.5 Rebalance Rebalance Rebalance Rebalance

5

= = = =

1 5 10 20

4

4

3.5

3.5

3

3

2.5

2.5

2 1.5

Myopic

Rebalance Rebalance Rebalance Rebalance

interval interval interval interval

= = = =

1 5 10 20

2 1.5 1

1 0.5

【τ = 1】

4.5

Sharpe ratio

Sharpe ratio

4.5

interval interval interval interval

0

0.05

0.1

0.15

0.2 0.25 0.3 0.35 Transaction cost rate (%)

0.4

MPC with different rebalance interval 【τ = 60 】

0.45

0.5

0.5 0 -0.5

0

0.05

0.1

0.15

0.2 0.25 0.3 0.35 Transaction cost rate (%)

0.4

0.45

0.5

38

Conclusion  Summary  MPC with adequate prediction horizon may provide a better performance than Myopic strategy for both wealth level and Sharpe ratio.  Although the wealth drops significantly with the increase of transaction costs, their performance may be improved by adjusting rebalance interval.  Remarks  We have tested recent data period for TOPIX500, S&P500, and HSI, and obtained a similar performance.  Proportional transaction cost constraint may be added in the objective function and is solved by quadratic optimization. 39