Introduction To Algorithmic Trading Strategies: Pairs Trading by Cointegration
Introduction To Algorithmic Trading Strategies: Pairs Trading by Cointegration
Introduction To Algorithmic Trading Strategies: Pairs Trading by Cointegration
Lecture 3
Pairs Trading by Cointegration
Haksun Li
[email protected]
www.numericalmethod.com
Outline
Distance method
Cointegration
Stationarity
DickeyFuller tests
2
References
Pairs Trading: A Cointegration Approach. Arlen David
Schmidt. University of Sydney. Finance Honours
Thesis. November 2008.
Likelihood-Based Inference in Cointegrated Vector
Autoregressive Models. Soren Johansen. Oxford
University Press, USA. February 1, 1996.
3
Pairs Trading
Definition: trade one asset (or basket) against another
asset (or basket)
Long one and short the other
Intuition: For two closely related assets, they tend to
move together (common trend). We want to buy the
cheap one and sell the expensive one.
Exploit short term deviation from long term equilibrium.
Try to make money from spread.
4
Spread
=
hedge ratio
cointegration coefficient
5
Dollar Neutral Hedge
Suppose ES (S&P500 E-mini future) is at 1220 and each
point worth $50, its dollar value is about $61,000.
Suppose NQ (Nasdaq 100 E-mini future) is at 1634 and
each point worth $20, its dollar value is $32,680.
=
61000
32680
= 1.87.
= 1.87
Buy Z = Buy 10 ES contracts and Sell 19 NQ contracts.
Sell Z = Sell 10 ES contracts and Buy 19 NQ contracts.
6
Market Neutral Hedge
Suppose ES has a beta of 1.25, NQ 1.11.
We use =
1.25
1.11
= 1.13
7
Dynamic Hedge
changes with time, covariance, market conditions,
etc.
Periodic recalibration.
8
Distance
The distance between two time series:
=
Other forms:
=
M, S are proprietary functions for forecasting.
11
A Very Simple Distance Pairs Trading
Sell Z when z > 2 (standard deviations).
Sell 10 ES contracts and Buy 19 NQ contracts.
Buy Z when z < -2 (standard deviations).
Buy 10 ES contracts and Sell 19 NQ contracts.
12
Pros of the Distance Model
Model free.
No mis-specification.
No mis-estimation.
Distance measure intuitively captures the LOP idea.
13
Cons of the Distance Model
Does not guarantee stationarity.
Cannot predict the convergence time (expected
holding period).
Ignores the dynamic nature of the spread process,
essentially treat the spread as i.i.d.
Using more strict criterions works for equity. In fixed
income trading, we dont have the luxury of throwing
away many pairs.
14
Risks in Pairs Trading
Long term equilibrium does not hold.
Systematic market risk.
Firm specific risk.
Liquidity.
15
Stationarity
These ad-hoc calibration does not guarantee the
single most important statistical property in trading:
stationarity.
Strong stationarity: the joint probability distribution
of
= +
< .
Sell when
> +.
18
Stocks from the Same Industry
Reduce market risk, esp., in bear market.
Stocks from the same industry are likely to be subject to the
same systematic risk.
Give some theoretical unpinning to the pairs trading.
Stocks from the same industry are likely to be driven by the
same fundamental factors (common trends).
19
Cointegration Definition
~CI , if
All components of
1
+
2
2
++
, is integrated of order
, > 0.
is the cointegrating vector, not unique.
20
Illustration for Trading
Suppose we have two assets, both reasonably I(1), we
want to find such that
= + is I(0), i.e., stationary.
In this case, we have = 1, = 1.
21
A Simple VAR Example
=
11
1
+
12
1
+
=
21
1
+
22
1
+
Theorem 4.2, Johansen, places certain restrictions on
the coefficients for the VAR to be cointegrated.
The roots of the characteristics equation lie on or outside
the unit disc.
22
Coefficient Restrictions
11
=
1
22
12
21
1
22
22
> 1
12
21
+
22
< 1
23
VECM (1)
Taking differences
1
=
11
1
1
+
12
1
+
1
=
21
1
+
22
1
1
+
=
11
1
12
21
22
1
1
1
+
Substitution of
11
=
12
21
1
22
12
21
22
1
1
1
+
24
VECM (2)
1
1
+
1
1
+
=
12
21
1
22
=
21
=
1
22
21
, the cointegrating coefficient
1
1
is the long run equilibrium, I(0).
< 0,
> 0,
1
+
1
+
In our simple example, we have
1
1
1
+
27
Granger Causality
if lagged values of
equation.
if lagged values of
equation.
28
Test for Stationarity
An augmented DickeyFuller test (ADF) is a test for a unit
root in a time series sample.
It is an augmented version of the DickeyFuller test for a
larger and more complicated set of time series models.
Intuition:
if the series
= + +
1
+
1
=1
+
Null hypothesis
0
: = 0. (
non-stationary)
= 0, = 0 models a random walk.
= 0 models a random walk with drift.
Test statistics =
, the more negative, the more
reason to reject
0
(hence
stationary).
SuanShu: AugmentedDickeyFuller.java
30
Engle-Granger Two Step Approach
Estimate either
=
10
+
11
+
1
=
20
+
21
+
2
As the sample size increase indefinitely, asymptotically a
test for a unit root in
1
and
2
are equivalent, but not
for small sample sizes.
Test for unit root using ADF on either
1
and
2
.
If
and
=
12
21
1
22
12
21
22
1
1
1
+
12
21
1
22
12
1
22
12
=
21
22
1
The rank of determine whether the two assets
and
are cointegrated.
33
VAR & VECM
In general, we can write convert a VAR to an VECM.
VAR (from numerical estimation by, e.g., OLS):
=1
Transitory form of VECM (reduced form)
=
1
+
1
=1
Long run form of VECM
1
=1
+
34
The Matrix
Rank() = n, full rank
The system is already stationary; a standard VAR model in
levels.
Rank() = 0
There exists NO cointegrating relations among the time
series.
0 < Rank() < n
=
is the cointegrating vector
is the speed of adjustment.
35
Rank Determination
Determining the rank of is amount to determining
the number of non-zero eigenvalues of .
is usually obtained from (numerical VAR) estimation.
Eigenvalues are computed using a numerical procedure.
36
Trace Statistics
Suppose the eigenvalues of are:
1
>
2
> >
.
For the 0 eigenvalues, ln 1
= 0.
For the (big) non-zero eigenvalues, ln 1
is (very
negative).
The likelihood ratio test statistics
| = log 1
=+1
H0: rank r; there are at most r cointegrating .
37
Test Procedure
int r = 0;//rank
for (; r <= n; ++r) {
compute Q = | ;
If (Q > c.v.) {//compare against a critical value
break;//fail to reject the null hypothesis; rank found
}
}
r is the rank found
38
Decomposing
Suppose the rank of = .
=
.
is .
is .
is r .
39
Estimating
can estimated by maximizing the log-likelihood
function in Chapter 6, Johansen.
logL , , ,
Theorem 6.1, Johansen: is found by solving the
following eigenvalue problem:
11
10
00
1
01
= 0
40
Each non-zero eigenvalue corresponds to a
cointegrating vector, which is its eigenvector.
=
1
,
2
, ,
spans the cointegrating space.
For two cointegrating asset, there are only one (
1
)
so it is unequivocal.
When there are multiple , we need to add economic
restrictions to identify .
41
Trading the Pairs
Given a space of (liquid) assets, we compute the
pairwise cointegrating relationships.
For each pair, we validate stationarity by performing
the ADF test.
For the strongly mean-reverting pairs, we can design
trading strategies around them.
42