0% found this document useful (0 votes)
22 views63 pages

Pairs Trading - Slides - Pairs - Trading

The document outlines a course on Pairs Trading by Prof. Daniel P. Palomar at HKUST, focusing on the concept of cointegration and its application in trading strategies. It explains the basic idea of pairs trading, including the selection of pairs, cointegration tests, and the design of trading strategies based on mean-reverting properties. The document also discusses statistical arbitrage and methods for discovering cointegrated pairs and their parameters.

Uploaded by

Tuninho
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)
22 views63 pages

Pairs Trading - Slides - Pairs - Trading

The document outlines a course on Pairs Trading by Prof. Daniel P. Palomar at HKUST, focusing on the concept of cointegration and its application in trading strategies. It explains the basic idea of pairs trading, including the selection of pairs, cointegration tests, and the design of trading strategies based on mean-reverting properties. The document also discusses statistical arbitrage and methods for discovering cointegrated pairs and their parameters.

Uploaded by

Tuninho
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/ 63

Pairs Trading

Prof. Daniel P. Palomar

MAFS5310 - Portolio Optimization with R


MSc in Financial Mathematics
The Hong Kong University o Science and Technology (HKUST)
Fall 2020-21
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Cointegration
Cointegration is a very interesting property that can be exploited in nance or trading.
Idea: While it may be diffcult to predict individual stocks, it may be easier to predict
relative behavior o stocks.
Illustrative example: A drunk man is wandering the streets (random walk) with a dog.
Both paths o man and dog are nonstationary and diffcult to predict, but the distance
between them is mean-reverting and stationary.

D. Palomar (HKUST) Pairs Trading 4 / 63


Correlation vs. cointegration

Everybody is amiliar with the concept o correlation between two random variables:
correlation is high when they co-move
correlation is zero when they move independently
So what is cointegration?
cointegration is high when two quantities move together or remain close to each other
cointegration is inexistent i the two quantities do not stay together
Clear? You can see why this concept may be diffcult to grasp at rst, but the truth is
that it’s easy.1
In the nancial context:
Cointegration o (log-)prices yt reers to long-term co-movements.
Correlation o (log-)returns ∆yt = yt − yt−1 characterizes short-term co-movements in
(log-)prices yt .

1
Y. Feng and D. P. Palomar, A Signal Processing Perspective on Financial Engineering. Foundations and
Trends in Signal Processing, Now Publishers, 2016.
D. Palomar (HKUST) Pairs Trading 5 / 63
Correlation vs. cointegration
Example o high correlation with no cointegration:
5
ỹ1t
y2t
ỹ1t − y2t

−1
0 20 40 60 80 100 120 140 160 180 200

D. Palomar (HKUST) Pairs Trading 6 / 63


Correlation vs. cointegration
Indeed the returns are highly correlated, see scatter plot:
1

0.8

0.6

0.4

Log−returns of stock 2
0.2

−0.2

−0.4

−0.6

−0.8

−1
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
Log−returns of stock 1

D. Palomar (HKUST) Pairs Trading 7 / 63


Correlation vs. cointegration
Opposite example o high cointegration with no correlation:
1

0.5

−0.5

−1

−1.5

−2

−2.5

−3
y1t
y2t
y1t − y2t
−3.5
0 20 40 60 80 100 120 140 160 180 200

D. Palomar (HKUST) Pairs Trading 8 / 63


Correlation vs. cointegration
Indeed the returns are not correlated, see scatter plot:
1

0.8

0.6

0.4

Log−returns of stock 2
0.2

−0.2

−0.4

−0.6

−0.8

−1
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
Log−returns of stock 1

D. Palomar (HKUST) Pairs Trading 9 / 63


Cointegration

A time series is called integrated o order p, denoted as I(p), i the time series obtained
by dierencing the time series p times is weakly stationary,
while by dierencing the time series p − 1 times is not weakly stationary.
Example: stock log-prices yt are integrated o order I(1) because
log-prices are not stationary
but log-returns yt − yt−1 are stationary (at least or some period o time).
A multivariate time series is said to be cointegrated i it has at least one linear
combination being integrated o a lower order, e.g., yt is not stationary but wT yt is
stationary or some weights w.

D. Palomar (HKUST) Pairs Trading 10 / 63


Cointegration
Consider the ollowing two nonstationary time series (e.g., log-prices o stocks):
y1t = γxt + w1t
y2t = xt + w2t
with a stochastic common trend dened as a random walk:
xt = xt−1 + wt
where w1t , w2t , wt are i.i.d. residual terms mutually independent.
The coeffcient γ is the secret ingredient here.
I γ is known, then we can dene the so-called “spread”
zt = y1t − γy2t = w1t − γw2t
which is stationary and mean reverting.
Interestingly, the dierences
( (i.e., log-returns) ∆y)1t and ∆y2t can have an arbitrarily small
√ √
correlation: ρ = 1/ 1 + 2σ12 /σ 2 1 + 2σ22 /σ 2 .
D. Palomar (HKUST) Pairs Trading 11 / 63
Cointegration
The log-prices y1t and y2t are cointegrated and the spread zt = y1t − γy2t is stationary
(assume γ = 1):
1

0.5

−0.5

−1

−1.5

−2

−2.5

−3
y1t
y2t
y1t − y2t
−3.5
0 20 40 60 80 100 120 140 160 180 200

D. Palomar (HKUST) Pairs Trading 12 / 63


Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Basic Idea o Pairs Trading

Recall that i two time series are cointegrated, then in the long term they remain close to
each other.
In other words, the spread zt = y1t − γy2t is mean reverting.
This mean-reverting property o the spread can be exploited or trading and it is
commonly reerred to as “pairs trading” or “statistical arbitrage”.
The idea behind pairs trading is to
short-sell the relatively overvalued stocks and buy the relatively undervalued stocks,
unwind the position when they are relatively airly valued.

D. Palomar (HKUST) Pairs Trading 14 / 63


Trading the spread

Suppose the spread zt = y1t − γy2t is mean-reverting with zero mean.


Stat-arb trading:
i spread is low (zt < −s0 ), then stock 1 is undervalued and stock 2 overvalued:
buy the spread (i.e., buy stock 1 and short-sell stock 2)
unwind the positions when it reverts to zero ater i time steps zt+i = 0
i spread is high (zt > s0 ), then stock 1 is overvalued and stock 2 undervalued:
short-sell the spread (i.e., short-sell stock 1 and buy stock 2)
unwind the positions when it reverts to zero ater i time steps zt+i = 0
The prot, say, rom buying low and unwinding at zero is zt+i − zt = s0 . So easy!
Indeed zt+i − zt = −γ(y2,t+i − y2t )+ (y1,t+i
 − y1t ), so the whole process is like having
1
used a portolio with weigths w = .
−γ
Recall that the return o a portolio w is wT ∆yt .

D. Palomar (HKUST) Pairs Trading 15 / 63


Trading the spread
Illustration on how to trade the spread zt = y1t − γy2t :2

zt

Sell Sell

s0

Buy to unwind Buy to unwind

Sell to unwind

−s0

Buy

2
G. Vidyamurthy, Pairs Trading: Quantitative Methods and Analysis. John Wiley & Sons, 2004.
D. Palomar (HKUST) Pairs Trading 16 / 63
Pairs trading or statistical arbitrage
Statistical arbitrage can be used in practice with prots:3
0.5

Spread 0

−0.5
0 20 40 60 80 100 120 140 160 180 200
(a)
1

0.5
Position

−0.5

−1
0 20 40 60 80 100 120 140 160 180 200
(b)
40

30
P&L

20

10

0
0 20 40 60 80 100 120 140 160 180 200
(c)

3
M. Avellaneda and J.-H. Lee, “Statistical arbitrage in the US equities market,” Quantitative Finance,
vol. 10, no. 7, pp. 761–782, 2010.
D. Palomar (HKUST) Pairs Trading 17 / 63
But how to discover cointegrated pairs and γ?
One interesting approach is based on a VECM modeling o the universe o stocks: From
the parameter β contained in the low-rank matrix Π = αβ T one can extract a
cointegration subspace. Ater that, one can design some portolio within that
cointegration subspace.4
A simpler approach to discover pairs is by brute orce, i.e., try exhaustively dierent
combinations o pairs o stocks and see i they are cointegrated.
But, given a potential pair, how do we obtain the “secret” γ?
Easy! Just a simple LS regression!

Recall that
γ is needed to orm the spread to be traded (i.e., portolio)
the spread mean µ is needed to determine the thresholds or entering a trade and unwind
later the position.
4
Z. Zhao and D. P. Palomar, “Mean-reverting portolio with budget constraint,” IEEE Trans. Signal
Process., vol. 66, no. 9, pp. 2342–2357, 2018.
D. Palomar (HKUST) Pairs Trading 18 / 63
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Design o a pairs trading strategy

We rst ocus on pairs trading (i.e., statistical arbitrage between two stocks) as the
example to introduce the main steps o statistical arbitrage.
In practice, pairs trading contains three main steps5 :
Pairs selection: identiy stock pairs that could potentially be cointegrated.
Cointegration test: test whether the identied stock pairs are indeed cointegrated or not.
Trading strategy design: study the spread dynamics and design proper trading rules.

5
G. Vidyamurthy, Pairs Trading: Quantitative Methods and Analysis. John Wiley & Sons, 2004.
D. Palomar (HKUST) Pairs Trading 20 / 63
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Pairs selection: normalized price distance

Normalized price distance6 (as a rough proxy to measure cointegration):


T

NPD ≜ (p̃1t − p̃2t )2
t=1

where the normalized price p̃1t o stock 1 is given by p̃1t = p1t /p10 . The normalized prices
o stock 2 dened similarly.
One can easily (i.e., cheaply) compute the NPD or all the possible combination o pairs
and select some pairs with smallest NPD as the potentially cointegrated pairs.
Later one can use a more rened measure o cointegration (more computationally
demanding).

6
E. Gatev, W. N. Goetzmann, and K. G. Rouwenhorst, “Pairs trading: Perormance o a relative-value
arbitrage rule,” Review of Financial Studies, vol. 19, no. 3, pp. 797–827, 2006.
D. Palomar (HKUST) Pairs Trading 22 / 63
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Least Squares (LS) regression
I the spread zt is stationary, it can be written as7

zt = y1t − γy2t = µ + ϵt

where
µ represents the equilibrium value and
ϵt is a zero-mean residual.
Equivalently, it can be written as

y1t = µ + γy2t + ϵt

which now has the typical orm o linear regression.


Least squares (LS) regression over T observations:
T

minimize (y1t − (µ + γy2t ))2
µ,γ
t=1
7
G. Vidyamurthy, Pairs Trading: Quantitative Methods and Analysis. John Wiley & Sons, 2004.
D. Palomar (HKUST) Pairs Trading 24 / 63
Cointegration test

LS regression is used to estimate the parameters µ and γ, obtaining the estimates µ̂ and
γ̂.
I y1t and y2t are I(1) and are cointegrated, then the estimates converge to the true values
as the number o observations goes to innity8 .
Using the estimated parameters µ̂ and γ̂, we can compute the residuals

ϵ̂t = y1t − γ̂y2t − µ̂.

Then, one has to decide whether the spread is stationary, i.e., ϵt is stationary. In practice,
the estimated residuals are used ϵ̂t
There are many well-dened mathematical tests or the stationarity o ϵ̂t , e.g., augmented
Dicky-Fuller (ADF) test, Johansen test, etc.
8
R. F. Engle and C. W. J. Granger, “Co-integration and error correction: Representation, estimation, and
testing,” Econometrica: Journal of the Econometric Society, pp. 251–276, 1987.
D. Palomar (HKUST) Pairs Trading 25 / 63
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Optimum threshold

Once some identied pairs have passed the cointegration test, one still needs to decide
the entry and exit thresholds to open and unwind the positions, respectively.
For the sake o concreteness, we ocus on studying the entry threshold:
open positions when the spread diverges rom its long-term mean by s0
unwind the position when it reverts to its mean
Thus, the key problem now is how to design the value o s0 such that the total prot is
maximized.
Total prot:
prot o each trade × number o trades
prot o each trade is s0
number o trades is related to the zero crossings, which can be analized theoretically as well
as empirically.
We ocus now on estimating the number o trades.

D. Palomar (HKUST) Pairs Trading 27 / 63


Optimum threshold s0 : Parametric approach∗
Suppose the spread ollows a standard Normal distribution.
The probability that the spread deviates above rom the mean by s0 or more is

1 − Φ(s0 )

where Φ(·) is the c.d.. o the standard Normal distribution.


For a path with T days, the number o tradable events is

T(1 − Φ(s0 )).

For each trade, the prot is s0 and then the total prot is s0 T(1 − Φ(s0 )).
Then the optimal threshold is s⋆0 = arg maxs0 {s0 T(1 − Φ(s0 ))}.
In practice, one cannot know the true distribution but can estimate the distribution
parameters.
Then one can compute the total prot based on estimated distribution.
D. Palomar (HKUST) Pairs Trading 28 / 63
Optimum threshold s0 : Parametric approach∗
Optimal threshold s⋆0 maximizes the total prot:
0.7 3
Theoretical
0.6 Parametric 2.5
Probability of trades

Profit of each trade


0.5
2
0.4
1.5
0.3
1
0.2

0.1 0.5

0 0
0 1 2 3 0 1 2 3
s0 s0
(a) (b)

0.25
Theoretical
0.2 Parametric
Total profit

0.15

0.1

0.05

0
0 0.5 1 1.5 2 2.5 3
s0
(c)

D. Palomar (HKUST) Pairs Trading 29 / 63


Optimum threshold s0 : Non-parametric approach∗

Suppose the observed sample path has length T: z1 , z2 , . . . , zT .


We consider J discretized threshold values as s0 ∈ {s01 , s02 , . . . , s0J } and the empirical
trading requency or the threshold s0j is
T
t=1 1{zt >s0j }
f̄j = .
T

The empirical values f̄j may not be a smoothed enough and the resulted prot unction
may not be accurate enough.
Smooth the trading requency unction by regularization:
J
∑ J−1

minimize (f̄j − fj )2 + λ (fj − fj+1 )2

j=1 j=1

D. Palomar (HKUST) Pairs Trading 30 / 63


Optimum threshold s0 : Non-parametric approach∗
The problem can be rewritten as

minimize ∥̄ − ∥22 + λ ∥D∥22


where  
1 −1
 
 1 −1 
D=
  ∈ R(J−1)×J .
.. .. 
 . . 
1 −1
Setting the derivative o the objective w.r.t.  to zero yields the optimal solution
⋆ = (I + λDT D)−1 ̄.
The optimal threshold is the one maximizes the total prot:

s⋆0 = arg max {s0j fj } .


s0j ∈{s01 ,s02 ,...,s0J }

D. Palomar (HKUST) Pairs Trading 31 / 63


Optimum threshold s0 : Non-parametric approach∗
Optimal threshold s⋆0 maximizes the total prot:
0.5 3
Theoretical
0.4 NonParam: empirical 2.5
Probability of trades

Profit of each trade


NonParam: regularized
2
0.3
1.5
0.2
1
0.1 0.5

0 0
0 1 2 3 0 1 2 3
s0 s0
(a) (b)

0.2
Theoretical
NonParam: empirical
0.15 NonParam: regularized
Total profit

0.1

0.05

0
0 0.5 1 1.5 2 2.5 3
s0
(c)

D. Palomar (HKUST) Pairs Trading 32 / 63


Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
LS regression or pairs trading
I the spread zt is stationary, it can be written as
zt = y1t − γy2t = µ + ϵt
where
µ represents the equilibrium value and
ϵt is a zero-mean residual.
Equivalently, it can be written as
y1t = µ + γy2t + ϵt
which now has the typical orm or linear regression.
Least squares (LS) regression over T observations:
T

minimize (y1t − (µ + γy2t ))2
µ,γ
t=1
By stacking the T observations in the vectors y1 and y2 , we can nally write:
minimize ∥y1 − (µ1 + γy2 )∥2
µ,γ
D. Palomar (HKUST) Pairs Trading 34 / 63
LS regression or pairs trading

Using the estimated parameters µ̂ and γ̂, we can compute the residuals
ϵ̂t = y1t − µ̂ − γ̂y2t .
Then, one has to decide whether the cointegration is acceptable or not so move to the
trading part.
There are many well-dened mathematical tests or the stationarity o ϵ̂t , e.g., augmented
Dicky-Fuller (ADF) test, Johansen test, etc.
Total prot:
prot o each trade × number o trades
prot o each trade is s0
number o trades is related to the zero crossings, which can be analized theoretically as well
as empirically.
Ideally, we want residuals with large amplitude (variance) as well as a strong mean
reversion because they directly aect the prot.

D. Palomar (HKUST) Pairs Trading 35 / 63


LS regression or pairs trading
One good case:
Z−score and trading signal for EWH vs EWZ 2000−08−01 / 2002−01−31
2 2

1 1

0 0

−1 −1

−2 −2
Z−score
−3 signal −3

Aug 01 Sep 01 Oct 02 Nov 01 Dec 01 Jan 02 Feb 01 Apr 02 May 01 Jun 01 Jul 02 Aug 01 Sep 04 Nov 01 Dec 03 Jan 02 Jan 31
2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2002 2002

Cum P&L 2000−08−01 / 2002−01−31

2.5 2.5

2.0 2.0

1.5 1.5

1.0 1.0

Aug 01 Sep 01 Oct 02 Nov 01 Dec 01 Jan 02 Feb 01 Apr 02 May 01 Jun 01 Jul 02 Aug 01 Sep 04 Nov 01 Dec 03 Jan 02 Jan 31
2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2002 2002

D. Palomar (HKUST) Pairs Trading 36 / 63


LS regression or pairs trading
But also a bad case:
Z−score and trading signal for EWY vs EWT 2000−07−03 / 2001−12−31

8 Z−score 8
signal
6 6

4 4

2 2

0 0

−2 −2

Jul 03 Aug 01 Sep 01 Oct 02 Nov 01 Dec 01 Jan 02 Feb 01 Apr 02 May 01 Jun 01 Jul 02 Aug 01 Sep 04 Nov 01 Dec 03
2000 2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001

Cum P&L 2000−07−03 / 2001−12−31


2.0 2.0

1.8 1.8

1.6 1.6

1.4 1.4

1.2 1.2

1.0 1.0

Jul 03 Aug 01 Sep 01 Oct 02 Nov 01 Dec 01 Jan 02 Feb 01 Apr 02 May 01 Jun 01 Jul 02 Aug 01 Sep 04 Nov 01 Dec 03
2000 2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001

D. Palomar (HKUST) Pairs Trading 37 / 63


LS regression or pairs trading

The problem with the LS regression is that it assumes that µ and γ are constant.
In practice, they can change with time, resulting in a spread that drits rom equilibrim
never to revert back with huge potential losses.
Thus, in practice, µ and γ are time-varying and have to be tracked.
How to track time-varying parameters?

O course… Kalman!!!
Well, you can also try a rolling regression or exponential smoothing, but Kalman works
better.

D. Palomar (HKUST) Pairs Trading 38 / 63


Kalman or pairs trading

Recall the previous static relationship or cointegrated series y1t and y2t :

y1t = µ + γy2t + ϵt

Let’s make it time-varying:


y1t = µt + γt y2t + ϵt
Let’s urther assume that the parameters µt and γt change slowly over time:

µt+1 = µt + η1t
γt+1 = γt + η2t

Obviously, this ts nicely the Kalman ramework!

D. Palomar (HKUST) Pairs Trading 39 / 63


Interlude: The Kalman flter

Kalman lter consist o two equations that model the time-varying hidden state xt and
the observations yt :
xt+1 = Tt xt + η t
y t = Z t x t + ϵt
The observation equation yt = Zt xt + ϵt relates the observation yt to the hidden state xt
as a linear relationship, where Zt is the time-varying observation matrix and ϵt is a
zero-mean Gaussian error ϵt ∼ N (0, R) with covariance matrix R.
The state transition equation xt+1 = Tt xt + η t expresses the transition o the hidden
state rom xt to xt+1 as a linear relationship, where Tt is the time-varying transition
matrix and η t is a zero-mean Gaussian error η t ∼ N (0, Q) with covariance matrix Q.
The Kalman lter is extremely versatile in modeling a variety o real-lie processes.9

9
J. Durbin and S. J. Koopman, Time Series Analysis by State Space Methods, 2nd Ed. Oxord University
Press, 2012.
D. Palomar (HKUST) Pairs Trading 40 / 63
Kalman or pairs trading
Kalman lter (state transition equation and observation equation):
xt+1 = Txt + η t
y1t = Zt xt + ϵt
where µt
 
xt ≜ is the hidden state
γ
 t 
1 0
T≜ is the state transition matrix
0 1
 
σ12 0
η t ∼ N (0, Q) is the i.i.d. state transition noise with Q =
0 σ22
 
Zt ≜ 1 y2t is the observation coeffcient matrix
ϵt ∼ N 0, σϵ2 is the i.i.d. observation noise
Note that this is a time-varying Kalman lter since Zt is time-varying.
Parameters σ12 , σ22 , σϵ2 can be estimated using the EM algorithm using historical data or
calibration.
The hidden state path xt gives the sought time-varying coeffcients.
D. Palomar (HKUST) Pairs Trading 41 / 63
Kalman or pairs trading
Log-prices o ETFs EWH and EWZ:
Log−prices 2000−08−01 / 2003−12−31

2.4 2.4

2.2 2.2

2.0 2.0

1.8 1.8

1.6 1.6

1.4 EWH 1.4


EWZ

Aug 01 Nov 01 Feb 01 Jun 01 Sep 04 Jan 02 Apr 01 Jul 01 Oct 01 Jan 02 Apr 01 Jul 01 Oct 01 Dec 31
2000 2000 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003 2003

D. Palomar (HKUST) Pairs Trading 42 / 63


Kalman or pairs trading
Tracking o µ and γ by LS, rolling LS, and Kalman:
Tracking of mu 2000−08−01 / 2003−12−31

mu.LS
1.0 mu.rolling.LS 1.0
mu.Kalman

0.8 0.8

0.6 0.6

0.4 0.4

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03 May 01 Aug 01 Nov 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003

Tracking of gamma 2000−08−01 / 2003−12−31

gamma.LS
0.6 gamma.rolling.LS 0.6
gamma.Kalman
0.5 0.5

0.4 0.4

0.3 0.3

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03 May 01 Aug 01 Nov 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003

D. Palomar (HKUST) Pairs Trading 43 / 63


Kalman or pairs trading
Spreads achieved by LS, rolling LS, and Kalman:
Spreads 2000−08−01 / 2003−12−31

LS
0.15 rolling.LS 0.15
Kalman
0.10 0.10

0.05 0.05

0.00 0.00

−0.05 −0.05

−0.10 −0.10

−0.15 −0.15

Aug 01 Nov 01 Feb 01 Jun 01 Sep 04 Jan 02 Apr 01 Jul 01 Oct 01 Jan 02 Apr 01 Jul 01 Oct 01 Dec 31
2000 2000 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003 2003

D. Palomar (HKUST) Pairs Trading 44 / 63


Kalman or pairs trading
Trading o spread rom LS:
Z−score and trading on spread based on LS 2000−08−01 / 2003−12−31

2 Z−score 2
signal
1 1

0 0

−1 −1

−2 −2

−3 −3

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03 May 01 Aug 01 Nov 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003

Cum P&L for spread based on LS 2000−08−01 / 2003−12−31

2.5 2.5

2.0 2.0

1.5 1.5

1.0 1.0

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03 May 01 Aug 01 Nov 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003

D. Palomar (HKUST) Pairs Trading 45 / 63


Kalman or pairs trading
Trading o spread rom rolling LS:
Z−score and trading on spread based on rolling−LS 2000−08−01 / 2003−12−31

2 Z−score 2
signal
1 1

0 0

−1 −1

−2 −2

−3 −3

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03 May 01 Aug 01 Nov 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003

Cum P&L for spread based on rolling−LS 2000−08−01 / 2003−12−31

3.0 3.0

2.5 2.5

2.0 2.0

1.5 1.5

1.0 1.0

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03 May 01 Aug 01 Nov 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003 2003 2003 2003

D. Palomar (HKUST) Pairs Trading 46 / 63


Kalman or pairs trading
Trading o spread rom Kalman:
Z−score and trading on spread based on Kalman 2000−08−01 / 2003−03−31

Z−score
2 signal 2

1 1

0 0

−1 −1

−2 −2

−3 −3

Aug 01 Oct 02 Dec 01 Feb 01 Apr 02 Jun 01 Aug 01 Oct 01 Dec 03 Feb 01 Apr 01 Jun 03 Aug 01 Oct 01 Dec 02 Feb 03 Mar 31
2000 2000 2000 2001 2001 2001 2001 2001 2001 2002 2002 2002 2002 2002 2002 2003 2003

Cum P&L for spread based on Kalman 2000−08−01 / 2003−03−31

4.0 4.0

3.5 3.5

3.0 3.0

2.5 2.5

2.0 2.0

1.5 1.5

Aug 01 Oct 02 Dec 01 Feb 01 Apr 02 Jun 01 Aug 01 Oct 01 Dec 03 Feb 01 Apr 01 Jun 03 Aug 01 Oct 01 Dec 02 Feb 03 Mar 31
2000 2000 2000 2001 2001 2001 2001 2001 2001 2002 2002 2002 2002 2002 2002 2003 2003

D. Palomar (HKUST) Pairs Trading 47 / 63


Kalman or pairs trading
Wealth comparison:
Cum P&L 2000−08−01 / 2003−03−31

LS
4.0 4.0
rolling.LS
Kalman
3.5 3.5

3.0 3.0

2.5 2.5

2.0 2.0

1.5 1.5

1.0 1.0

Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 01 May 01 Aug 01 Nov 01 Feb 03
2000 2000 2001 2001 2001 2001 2002 2002 2002 2002 2003

D. Palomar (HKUST) Pairs Trading 48 / 63


Kalman flter in fnance

The Kalman lter can and has been used in many aspects o nancial time-series
modeling as one could expect.10
Examples o univariate time series: rate o infation, national income, level o
unemployment, etc.
Typical models include: local model, trend-cycle decompositions, seasonality, etc.
Examples o multivariate time series: infation and national income.
Multiple time series allows or more sophisticated models including common actors,
cointegration, etc.
Also data irregularities can be easily handled, e.g., missing observations, outliers, mixed
requencies.
Plenty o applications or nonlinear and non-Gaussian models as well, e.g., GARCH
modeling and stochastic volatility modeling.

10
A. Harvey and S. J. Koopman, “Unobserved components models in economics and fnance: The role o the
Kalman flter in time series econometrics,” IEEE Control Systems Magazine, vol. 29, no. 6, pp. 71–81, 2009.
D. Palomar (HKUST) Pairs Trading 49 / 63
Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
From pairs trading to statistical arbitrage

Pairs trading ocuses on nding cointegration between two stocks.


A more general idea is to extend this statistical arbitrage rom two stocks to more stocks.

The idea is still based on cointegration:


Try to construct a linear combination of the log-prices of multiple (more than two)
stocks such that it is a cointegrated mean-reversion process.

In the case o two assets, the spread


 is zt = y1t − γy2t , which can be understood as a
1
portolio with weights: w = .
−γ
In the general case o many assets, one has to properly design the portolio w.

D. Palomar (HKUST) Pairs Trading 51 / 63


Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
VECM

Denote the log-prices o multiple stocks as yt and the log-returns as rt = ∆yt = yt − yt−1 .
Most o the multivariate time-series models attempt to model the log-returns rt (because
the log-prices are nonstationary whereas the log-returns are weakly stationary, at least
over some time horizon).
However, it turns out that dierencing the log-prices may destroy part o the structure.
The VECM11 tries to x that issue by including an additional term in the model:
p−1

rt = ϕ0 + Πyt−1 + Φ̃i rt−i + wt ,
i=1

where the term Πyt−1 is called error correction term.

11
R. F. Engle and C. W. J. Granger, “Co-integration and error correction: Representation, estimation, and
testing,” Econometrica: Journal of the Econometric Society, pp. 251–276, 1987.
D. Palomar (HKUST) Pairs Trading 53 / 63
VECM - Matrix Π

The matrix Π is o extreme importance.


p−1
Notice that rom the model rt = ϕ0 + Πyt−1 + i=1 Φ̃i rt−i + wt one can conclude that
Πyt must be stationary even though yt is not!!!
I that happens, it is said that yt is cointegrated.
There are three possibilities or Π:
rank (Π) = 0: This implies Π = 0, thus yt is not cointegrated (so no mystery here) and the
VECM reduces to a VAR model on the log-returns.
rank (Π) = N: This implies Π is invertible and thus yt must be stationary already.
0 < rank (Π) < N: This is the interestinc case and Π can be decomposed as Π = αβ T with
α, β ∈ RN×r with ull column rank. This means that yt has r linearly independent
cointegrated components, i.e., β T yt , each o which can be used or pairs trading.

D. Palomar (HKUST) Pairs Trading 54 / 63


Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Mean-reverting portolio (MRP)

In the case o two assets, the spread


 is zt = y1t − γy2t , which can be understood as a
1
portolio with weights: w = .
−γ
In the general case o many assets, one has to properly design the portolio w.
One interesting approach is based on a VECM modeling o the universe o stocks:
From the parameter β contained in the low-rank matrix Π = αβ T one can simply use any
column o β (even all o them)
Even better, β denes a cointegration subspace and we can then optimize the portolio
within that cointegration subspace.12,13

12
Z. Zhao and D. P. Palomar, “Mean-reverting portolio with budget constraint,” IEEE Trans. Signal
Process., vol. 66, no. 9, pp. 2342–2357, 2018.
13
Z. Zhao, R. Zhou, and D. P. Palomar, “Optimal mean-reverting portolio with leverage constraint or
statistical arbitrage in fnance,” IEEE Trans. Signal Process., vol. 67, no. 7, pp. 1681–1695, 2019.
D. Palomar (HKUST) Pairs Trading 56 / 63
Mean-reverting portolio (MRP)

Consider the log-prices yt and use β to extract several spreads st = β T yt .


Let’s now use a portolio w to extract the best mean-reverting spread rom st as
zt = w T st .
To design the the portolio w we have two main objectives (recall that total prot equals:
prot o each trade × number o trades):
we want[large variance (prot o each]trade): wT M0 w, where
T
Mi = E (st − E [st ]) (st+i − E [st+i ])
we want strong mean reversion (number o trades): many proxies exist like the Portmanteau
statistics or crossing statistics.

D. Palomar (HKUST) Pairs Trading 57 / 63


Mean-reverting portolio (MRP)

For example, i we use the Portmanteau statistics as a proxy or the mean reversion, the
problem ormulation becomes:
p  2
wT M i w
minimize i=1 wT M 0 w
w
subject to wT M0 w = ν
w ∈ W.

Using other proxies, the ormulation can be expressed more generally as14
p  2
minimize wT Hw + λ i=1 wT Mi w
w
subject to wT M0 w = ν
w ∈ W.
14
Z. Zhao and D. P. Palomar, “Mean-reverting portolio with budget constraint,” IEEE Trans. Signal
Process., vol. 66, no. 9, pp. 2342–2357, 2018.
D. Palomar (HKUST) Pairs Trading 58 / 63
MRP in practice
Observe several stock log-prices and the spreads obtained rom β:

5.5
APA
AXP
CAT
5.0 COF
FCX
IBM
MMM

Log-prices
4.5

4.0

3.5

3.0

6.0
s1

5.5

5.4
5.2
s2

5.0

5.6
s3

5.4
5.2
2012 2013 2014

D. Palomar (HKUST) Pairs Trading 59 / 63


MRP in practice
Observe several stock log-prices and the spreads obtained rom β:

0.4

Spreads
0.2
0 MRP-cro (prop.)
-0.2 Spread s 1
-0.4

0.02
MRP-cro (prop.) - SR=3.2471

ROI
0

-0.02

0.01
Spread s 1 - SR=2.8579
ROI

0
-0.01

8
MRP-cro (prop.)
Spread s 1
6
Cum. P&L

0
2012 2013 2014

D. Palomar (HKUST) Pairs Trading 60 / 63


Outline
1 Cointegration
2 Basic Idea o Pairs Trading
3 Design o Pairs Trading
Pairs selection
Cointegration test
Optimum threshold
4 LS Regression and Kalman or Pairs Trading
5 From Pairs Trading to Statistical Arbitrage (StatArb)∗
VECM
Optimization o mean-reverting portolio (MRP)
6 Summary
Summary

First o all, we have discovered the concept o cointegration.


We have learned the basic idea o pairs trading or cointegrated assets:
searching or a cointegrated spread is the rst step
making sure that the chosen spread remains cointegrated is key (cointegrated tests)
obtaining the cointegration ratio γ and the entering and exiting thresholds are important
details.
We have learned o the use o Kalman (initially developed or tracking missiles) ltering
or improved pairs trading.
We have briefy explored the extension o pairs trading (or two stocks) to statistical
arbitrage (or more than two stocks):
VECM modeling is an important multivariate time-series modeling tool
sophisticated portolio designs on the cointegration subspace are possible.

D. Palomar (HKUST) Pairs Trading 62 / 63


Thanks

For more inormation visit:

https://www.danielppalomar.com

You might also like