SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Introduction to Algorithmic Trading Strategies
Lecture 6
Pairs Trading by Stochastic Spread Methods
Haksun Li
haksun.li@numericalmethod.com
www.numericalmethod.com
Outline
 First passage time
 Kalman filter
 Maximum likelihood estimate
 EM algorithm
2
References
 As the emphasis of the basic co-integration methods of most papers are
on the constructionof a synthetic mean-reverting asset, the stochastic
spread methods focuses on the dynamic of the price of the synthetic
asset.
 Most referenced academic paper: Elliot, van der Hoek, and Malcolm,
2005, Pairs Trading
 Model the spread process as a state-space version of Ornstein-Uhlenbeck
process
 Jonathan Chiu, Daniel Wijaya Lukman, Kourosh Modarresi, Avinayan
Senthi Velayutham. High-frequency Trading. Stanford University. 2011
 The idea has been conceived by a lot of popular pairs trading books
 Technical analysis and charting for the spread, Ehrman, 2005, The
Handbook of Pairs Trading
 ARMA model, HMM ARMA model, some non-parametric approach, and a
Kalman filter model, Vidyamurthy, 2004, Pairs Trading: Quantitative
Methods and Analysis
3
Spread as a Mean-Reverting Process
 𝑥 𝑘 − 𝑥 𝑘−1 = 𝑎 − 𝑏𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘
 = 𝑏
𝑎
𝑏
− 𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘
 The long term mean =
𝑎
𝑏
.
 The rate of mean reversion = 𝑏.
4
Sum of Power Series
 We note that
 = ∑ 𝑎 𝑖𝑘−1
𝑖=0 =
𝑎 𝑘−1
𝑎−1
5
Unconditional Mean
 𝐸 𝑥 𝑘 = 𝜇 𝑘 = 𝜇 𝑘−1 + 𝑎 − 𝑏𝜇 𝑘−1 𝜏
 = 𝑎𝜏 + 1 − 𝑏𝜏 𝜇 𝑘−1
 = 𝑎𝜏 + 1 − 𝑏𝜏 𝑎𝜏 + 1 − 𝑏𝜏 𝜇 𝑘−2
 = 𝑎𝜏 + 1 − 𝑏𝜏 𝑎𝜏 + 1 − 𝑏𝜏 2 𝜇 𝑘−2
 = ∑ 1 − 𝑏𝜏 𝑖𝑘−1
𝑖=0 𝑎𝜏 + 1 − 𝑏𝜏 𝑘 𝜇0
 = 𝑎𝜏
1− 1−𝑏𝜏 𝑘
1− 1−𝑏𝜏
+ 1 − 𝑏𝜏 𝑘 𝜇0
 = 𝑎𝜏
1− 1−𝑏𝜏 𝑘
𝑏𝜏
+ 1 − 𝑏𝜏 𝑘 𝜇0
 =
𝑎
𝑏
−
𝑎
𝑏
1 − 𝑏𝜏 𝑘 + 1 − 𝑏𝜏 𝑘 𝜇0
6
Long Term Mean

𝑎
𝑏
−
𝑎
𝑏
1 − 𝑏𝜏 𝑘 + 1 − 𝑏𝜏 𝑘 𝜇0
 →
𝑎
𝑏
7
Unconditional Variance
 Var 𝑥 𝑘 = 𝜎 𝑘
2 = 1 − 𝑏𝜏 2 𝜎 𝑘−1
2 + 𝜎2 𝜏
 = 1 − 𝑏𝜏 2 𝜎 𝑘−1
2 + 𝜎2 𝜏
 = 1 − 𝑏𝜏 2 1 − 𝑏𝜏 2 𝜎 𝑘−2
2 + 𝜎2 𝜏 + 𝜎2 𝜏
 = 𝜎2 𝜏 ∑ 1 − 𝑏𝜏 2𝑖𝑘−1
𝑖=0 + 1 − 𝑏𝜏 2𝑘 𝜎0
2
 = 𝜎2 𝜏
1− 1−𝑏𝜏 2𝑘
1− 1−𝑏𝜏 2 + 1 − 𝑏𝜏 2𝑘 𝜎0
2
8
Long Term Variance
 𝜎2 𝜏
1− 1−𝑏𝜏 2𝑘
1− 1−𝑏𝜏 2 + 1 − 𝑏𝜏 2𝑘 𝜎0
2
 →
𝜎2 𝜏
1− 1−𝑏𝜏 2
9
Observations and Hidden State Process
 The hidden state process is:
 𝑥 𝑘 = 𝑥 𝑘−1 + 𝑎 − 𝑏𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘
 = 𝑎𝜏 + 1 − 𝑏𝜏 𝑥 𝑘−1 + 𝜎 𝜏𝜀 𝑘
 = 𝐴 + 𝐵𝑥 𝑘−1 + 𝐶𝜀 𝑘
 𝐴 ≥ 0, 0 < 𝐵 < 1
 The observations:
 𝑦 𝑘 = 𝑥 𝑘 + 𝐷𝜔 𝑘
 We want to compute the expected state from
observations.
 𝑥� 𝑘 = 𝑥� 𝑘|𝑘 = 𝐸 𝑥 𝑘|𝑌𝑘
10
First Passage Time
 Standardized Ornstein-Uhlenbeck process
 𝑑𝑑 𝑡 = −𝑍 𝑡 𝑑𝑑 + 2𝑑𝑑 𝑡
 First passage time
 𝑇0,𝑐 = inf 𝑡 ≥ 0, 𝑍 𝑡 = 0|𝑍 0 = 𝑐
 The pdf of 𝑇0,𝑐 has a maximum value at
 𝑡̂ =
1
2
ln 1 +
1
2
𝑐2 − 3 2 + 4𝑐2 + 𝑐2 − 3
11
A Sample Trading Strategy
 𝑥 𝑘 = 𝑥 𝑘−1 + 𝑎 − 𝑏𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘
 𝑑𝑋 𝑡 = 𝑎 − 𝑏𝑏 𝑡 𝑑𝑑 + 𝜎𝑑𝑑 𝑡
 𝑋 0 = 𝜇 + 𝑐
𝜎
2𝜌
, 𝑋 𝑇 = 𝜇
 𝑇 =
1
𝜌
𝑡̂
 Buy when 𝑦 𝑘 < 𝜇 − 𝑐
𝜎
2𝜌
unwind after time 𝑇
 Sell when 𝑦 𝑘 > 𝜇 + 𝑐
𝜎
2𝜌
unwind after time 𝑇
12
Kalman Filter
 The Kalman filter is an efficient recursive filter that
estimates the state of a dynamic system from a series
of incomplete and noisy measurements.
13
Conceptual Diagram
prediction at time t Update at time t+1
as new measurements come in
correct for better estimation
14
A Linear Discrete System
 𝑥 𝑘 = 𝐹𝑘 𝑥 𝑘−1 + 𝐵 𝑘 𝑢 𝑘 + 𝜔 𝑘
 𝐹𝑘: the state transition model applied to the previous
state
 𝐵 𝑘: the control-input model applied to control vectors
 𝜔 𝑘~𝑁 0, 𝑄 𝑘 : the noise process drawn from
multivariate Normal distribution
15
Observations and Noises
 𝑧 𝑘 = 𝐻 𝑘 𝑥 𝑘 + 𝑣 𝑘
 𝐻 𝑘: the observation model mapping the true states to
observations
 𝑣 𝑘~𝑁 0, 𝑅 𝑘 : the observation noise
16
Discrete System Diagram
17
Prediction
 predicted a prior state estimate
 𝑥� 𝑘|𝑘−1 = 𝐹𝑘 𝑥� 𝑘−1|𝑘−1 + 𝐵 𝑘 𝑢 𝑘
 predicted a prior estimate covariance
 𝑃𝑘|𝑘−1 = 𝐹𝑘 𝑃𝑘−1|𝑘−1 𝐹𝑘
𝑇
+ 𝑄 𝑘
18
Update
 measurement residual
 𝑦� 𝑘 = 𝑧 𝑘 − 𝐻 𝑘 𝑥� 𝑘|𝑘−1
 residual covariance
 𝑆 𝑘 = 𝐻 𝑘 𝑃𝑘|𝑘−1 𝐻 𝑘
𝑇
+ 𝑅 𝑘
 optimal Kalman gain
 𝐾𝑘 = 𝑃𝑘|𝑘−1 𝐻 𝑘
𝑇
𝑆 𝑘
−1
 updated a posteriori state estimate
 𝑥� 𝑘|𝑘 = 𝑥� 𝑘|𝑘−1 + 𝐾𝑘 𝑦� 𝑘
 updated a posteriori estimate covariance
 𝑃𝑘|𝑘 = 𝐼 − 𝐾𝑘 𝐻 𝑘 𝑃𝑘|𝑘−1
19
Computing the ‘Best’ State Estimate
 Given 𝐴, 𝐵, 𝐶, 𝐷, we define the conditional variance
 𝑅 𝑘 = Σ 𝑘|𝑘 ≡ E 𝑥 𝑘 − 𝑥� 𝑘
2|𝑌𝑘
 Start with 𝑥�0|0 = 𝑦0, 𝑅0 = 𝐷2.
20
Predicted (a Priori) State Estimation
 𝑥� 𝑘+1|𝑘
 = E 𝑥 𝑘+1|𝑌𝑘
 = E 𝐴 + 𝐵𝑥 𝑘 + 𝐶𝜀 𝑘+1|𝑌𝑘
 = E 𝐴 + 𝐵𝑥 𝑘|𝑌𝑘
 = 𝐴 + 𝐵 E 𝑥 𝑘|𝑌𝑘
 = 𝐴 + 𝐵𝑥� 𝑘|𝑘
21
Predicted (a Priori) Variance
 Σ 𝑘+1|𝑘
 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1
2|𝑌𝑘
 = E 𝐴 + 𝐵𝐵 𝑘 + 𝐶𝜀 𝑘+1 − 𝑥� 𝑘+1
2|𝑌𝑘
 = E 𝐴 + 𝐵𝐵 𝑘 + 𝐶𝜀 𝑘+1 − 𝐴 − 𝐵𝑥� 𝑘|𝑘
2
|𝑌𝑘
 = E 𝐵𝐵 𝑘 − 𝐵𝑥� 𝑘|𝑘 + 𝐶𝜀 𝑘+1
2
|𝑌𝑘
 = E 𝐵𝐵 𝑘 − 𝐵𝑥� 𝑘|𝑘
2
+ 𝐶2 𝜀2
𝑘+1|𝑌𝑘
 = 𝐵2Σ 𝑘|𝑘 + 𝐶2
22
Minimize Posteriori Variance
 Let the Kalman updating formula be
 𝑥� 𝑘+1 = 𝑥� 𝑘+1|𝑘+1 = 𝑥� 𝑘+1|𝑘 + 𝐾 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘
 We want to solve for K such that the conditional
variance is minimized.
 Σ 𝑘+1|𝑘 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1
2|𝑌𝑘
23
Solve for K
 E 𝑥 𝑘+1 − 𝑥� 𝑘+1
2|𝑌𝑘
 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 − 𝐾 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘
2
|𝑌𝑘
 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 − 𝐾 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 + 𝐷𝜔 𝑘+1
2
|𝑌𝑘
 = E 1 − 𝐾 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 − 𝐾𝐾𝜔 𝑘+1
2
|𝑌𝑘
 = 1 − 𝐾 2 E 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘
2
|𝑌𝑘 + 𝐾2 𝐷2
 = 1 − 𝐾 2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2
24
First Order Condition for k

𝑑
𝑑𝐾
1 − 𝐾 2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2
 =
𝑑
𝑑𝐾
1 − 2𝐾 + 𝐾2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2
 = −2 + 2𝐾 Σ 𝑘+1|𝑘 + 2𝐾𝐷2
 = 0
25
Optimal Kalman Filter
 𝐾𝑘+1 =
Σ 𝑘+1|𝑘
Σ 𝑘+1|𝑘+𝐷2
26
Updated (a Posteriori) State Estimation
 So, we have the “optimal” Kalman updating rule.
 𝑥� 𝑘+1 = 𝑥� 𝑘+1|𝑘+1 = 𝑥� 𝑘+1|𝑘 + 𝐾 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘
 = 𝑥� 𝑘+1|𝑘 +
Σ 𝑘+1|𝑘
Σ 𝑘+1|𝑘+𝐷2 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘
27
Updated (a Posteriori) Variance
 𝑅 𝑘+1 = Σ 𝑘+1|𝑘 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1
2
|𝑌𝑘+1 = 1 − 𝐾 2
Σ 𝑘+1|𝑘 + 𝐾2
𝐷2
 = 1 −
Σ 𝑘+1|𝑘
Σ 𝑘+1|𝑘+𝐷2
2
Σ 𝑘+1|𝑘 +
Σ 𝑘+1|𝑘
Σ 𝑘+1|𝑘+𝐷2
2
𝐷2
 =
𝐷2
Σ 𝑘+1|𝑘+𝐷2
2
Σ 𝑘+1|𝑘 +
Σ 𝑘+1|𝑘
Σ 𝑘+1|𝑘+𝐷2
2
𝐷2
 =
𝐷4Σ 𝑘+1|𝑘+𝐷2Σ 𝑘+1|𝑘
2
Σ 𝑘+1|𝑘+𝐷2 2
 =
𝐷4Σ 𝑘+1|𝑘+𝐷2Σ 𝑘+1|𝑘
2
Σ 𝑘+1|𝑘+𝐷2 2
 =
Σ 𝑘+1|𝑘 𝐷2 𝐷2+Σ 𝑘+1|𝑘 𝐷2
Σ 𝑘+1|𝑘+𝐷2 2
 = Σ 𝑘+1|𝑘 𝐷2
28
Parameter Estimation
 We need to estimate the parameters 𝜗 = 𝐴, 𝐵, 𝐶, 𝐷
from the observable data before we can use the
Kalman filter model.
 We need to write down the likelihood function in
terms of 𝜗, and then maximize w.r.t. 𝜗.
29
Likelihood Function
 A likelihood function (often simply the likelihood) is a
function of the parameters of a statistical model,
defined as follows: the likelihood of a set of parameter
values given some observed outcomes is equal to the
probability of those observed outcomes given those
parameter values.
 𝐿 𝜗; 𝑌 = 𝑝 𝑌|𝜗
30
Maximum Likelihood Estimate
 We find 𝜗 such that 𝐿 𝜗; 𝑌 is maximized given the
observation.
31
Example Using the Normal Distribution
 We want to estimate the mean of a sample of size
𝑁 drawn from a Normal distribution.
 𝑓 𝑦 =
1
2𝜋𝜎2
exp −
𝑦−𝜇 2
2𝜎2
 𝜗 = 𝜇, 𝜎
 𝐿 𝑁 𝜗; 𝑌 = ∏
1
2𝜋𝜎2
exp −
𝑦 𝑖−𝜇 2
2𝜎2
𝑁
𝑖=1
32
Log-Likelihood
 log 𝐿 𝑁 𝜗; 𝑌 = ∑ log
1
2𝜋𝜎2
−
𝑥𝑖−𝜇 2
2𝜎2
𝑁
𝑖=1
 Maximizing the log-likelihood is equivalent to
maximizing the following.
 − ∑ 𝑥𝑖 − 𝜇 2𝑁
𝑖=1
 First order condition w.r.t.,𝜇
 𝜇 =
1
𝑁
∑ 𝑥𝑖
𝑁
𝑖=1
33
Nelder-Mead
 After we write down the likelihood function for the
Kalman model in terms of 𝜗 = 𝐴, 𝐵, 𝐶, 𝐷 , we can run
any multivariate optimization algorithm, e.g., Nelder-
Mead, to search for 𝜗.
 ma𝑥
𝜗
𝐿 𝜗; 𝑌
 The disadvantage is that it may not converge well,
hence not landing close to the optimal solution.
34
Marginal Likelihood
 For the set of hidden states, 𝑋𝑡 , we write
 𝐿 𝜗; 𝑌 = 𝑝 𝑌|𝜗 = ∑ 𝑝 𝑌, 𝑋|𝜗𝑋
 Assume we know the conditional distribution of 𝑋, we
could instead maximize the following.
 ma𝑥
𝜗
E
𝑋
𝐿 𝜗|𝑌, 𝑋 , or
 ma𝑥
𝜗
E
𝑋
log 𝐿 𝜗|𝑌, 𝑋
 The expectation is a weighted sum of the (log-)
likelihoods weighted by the probability of the hidden
states.
35
The Q-Function
 Where do we get the conditional distribution of 𝑋𝑡
from?
 Suppose we somehow have an (initial) estimation of
the parameters, 𝜗0. Then the model has no unknowns.
We can compute the distribution of 𝑋𝑡 .
 𝑄 𝜗|𝜗 𝑡 = E
𝑋|𝑌,𝜗
log 𝐿 𝜗|𝑌, 𝑋
36
EM Intuition
 Suppose we know 𝜗, we know completely about the
mode; we can find 𝑋.
 Suppose we know 𝑋, we can estimate 𝜗, by, e.g.,
maximum likelihood.
 What do we do if we don’t know both 𝜗 and 𝑋?
37
Expectation-Maximization Algorithm
 Expectation step (E-step): compute the expected value
of the log-likelihood function, w.r.t., the conditional
distribution of 𝑋 under 𝑌and 𝜗.
 𝑄 𝜗|𝜗 𝑡 = E
𝑋|𝑌,𝜗
log 𝐿 𝜗|𝑌, 𝑋
 Maximization step (M-step): find the parameters, 𝜗,
that maximize the Q-value.
 𝜗 𝑡+1 = argmax
𝜗
𝑄 𝜗|𝜗 𝑡
38
EM Algorithms for Kalman Filter
 Offline: Shumway and Stoffer smoother approach,
1982
 Online: Elliott and Krishnamurthy filter approach,
1999
39
A Trading Algorithm
 From 𝑦0, 𝑦1, …, 𝑦 𝑁, we estimate 𝜗̂ 𝑁 .
 Decide whether to make a trade at 𝑡 = 𝑁, unwind at
𝑡 = 𝑁 + 1, or some time later, e.g., 𝑡 = 𝑁 + 𝑇.
 As 𝑦 𝑁+1arrives, estimate 𝜗̂ 𝑁 + 1 .
 Repeat.
40
Results (1)
41
Results (2)
42
Results (3)
43

Contenu connexe

Tendances

Stat lesson 5.1 probability distributions
Stat lesson 5.1 probability distributionsStat lesson 5.1 probability distributions
Stat lesson 5.1 probability distributions
pipamutuc
 
Chapter 07
Chapter 07Chapter 07
Chapter 07
bmcfad01
 

Tendances (20)

Intro to Quant Trading Strategies (Lecture 9 of 10)
Intro to Quant Trading Strategies (Lecture 9 of 10)Intro to Quant Trading Strategies (Lecture 9 of 10)
Intro to Quant Trading Strategies (Lecture 9 of 10)
 
Intro to Quantitative Investment (Lecture 6 of 6)
Intro to Quantitative Investment (Lecture 6 of 6)Intro to Quantitative Investment (Lecture 6 of 6)
Intro to Quantitative Investment (Lecture 6 of 6)
 
Intro to Quantitative Investment (Lecture 1 of 6)
Intro to Quantitative Investment (Lecture 1 of 6)Intro to Quantitative Investment (Lecture 1 of 6)
Intro to Quantitative Investment (Lecture 1 of 6)
 
Intro to Quantitative Investment (Lecture 3 of 6)
Intro to Quantitative Investment (Lecture 3 of 6)Intro to Quantitative Investment (Lecture 3 of 6)
Intro to Quantitative Investment (Lecture 3 of 6)
 
Quantitative Methods for Lawyers - Class #20 - Regression Analysis - Part 3
Quantitative Methods for Lawyers - Class #20 - Regression Analysis - Part 3Quantitative Methods for Lawyers - Class #20 - Regression Analysis - Part 3
Quantitative Methods for Lawyers - Class #20 - Regression Analysis - Part 3
 
Probability distributions
Probability distributionsProbability distributions
Probability distributions
 
Statistical inference: Probability and Distribution
Statistical inference: Probability and DistributionStatistical inference: Probability and Distribution
Statistical inference: Probability and Distribution
 
Quantitative Methods for Lawyers - Class #10 - Binomial Distributions, Normal...
Quantitative Methods for Lawyers - Class #10 - Binomial Distributions, Normal...Quantitative Methods for Lawyers - Class #10 - Binomial Distributions, Normal...
Quantitative Methods for Lawyers - Class #10 - Binomial Distributions, Normal...
 
Quantitative Methods for Lawyers - Class #22 - Regression Analysis - Part 5
Quantitative Methods for Lawyers - Class #22 - Regression Analysis - Part 5Quantitative Methods for Lawyers - Class #22 - Regression Analysis - Part 5
Quantitative Methods for Lawyers - Class #22 - Regression Analysis - Part 5
 
Quantitative Methods for Lawyers - Class #6 - Basic Statistics + Probability ...
Quantitative Methods for Lawyers - Class #6 - Basic Statistics + Probability ...Quantitative Methods for Lawyers - Class #6 - Basic Statistics + Probability ...
Quantitative Methods for Lawyers - Class #6 - Basic Statistics + Probability ...
 
Discrete Probability Distributions.
Discrete Probability Distributions.Discrete Probability Distributions.
Discrete Probability Distributions.
 
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
Quantitative Methods for Lawyers - Class #21 - Regression Analysis - Part 4
 
Stat lesson 5.1 probability distributions
Stat lesson 5.1 probability distributionsStat lesson 5.1 probability distributions
Stat lesson 5.1 probability distributions
 
Quantitative Methods for Lawyers - Class #19 - Regression Analysis - Part 2
Quantitative Methods for Lawyers - Class #19 - Regression Analysis - Part 2Quantitative Methods for Lawyers - Class #19 - Regression Analysis - Part 2
Quantitative Methods for Lawyers - Class #19 - Regression Analysis - Part 2
 
Quantitative Methods for Lawyers - Class #22 - Regression Analysis - Part 1
Quantitative Methods for Lawyers - Class #22 -  Regression Analysis - Part 1Quantitative Methods for Lawyers - Class #22 -  Regression Analysis - Part 1
Quantitative Methods for Lawyers - Class #22 - Regression Analysis - Part 1
 
Quantitative Methods for Lawyers - Class #7 - Probability & Basic Statistics ...
Quantitative Methods for Lawyers - Class #7 - Probability & Basic Statistics ...Quantitative Methods for Lawyers - Class #7 - Probability & Basic Statistics ...
Quantitative Methods for Lawyers - Class #7 - Probability & Basic Statistics ...
 
Types of Probability Distributions - Statistics II
Types of Probability Distributions - Statistics IITypes of Probability Distributions - Statistics II
Types of Probability Distributions - Statistics II
 
Chapter 07
Chapter 07Chapter 07
Chapter 07
 
Les5e ppt 04
Les5e ppt 04Les5e ppt 04
Les5e ppt 04
 
Quantitative Methods for Lawyers - Class #15 - R Boot Camp - Part 2 - Profess...
Quantitative Methods for Lawyers - Class #15 - R Boot Camp - Part 2 - Profess...Quantitative Methods for Lawyers - Class #15 - R Boot Camp - Part 2 - Profess...
Quantitative Methods for Lawyers - Class #15 - R Boot Camp - Part 2 - Profess...
 

Similaire à Intro to Quant Trading Strategies (Lecture 6 of 10)

14th_Class_19-03-2024 Control systems.pptx
14th_Class_19-03-2024 Control systems.pptx14th_Class_19-03-2024 Control systems.pptx
14th_Class_19-03-2024 Control systems.pptx
buttshaheemsoci77
 
2Multi_armed_bandits.pptx
2Multi_armed_bandits.pptx2Multi_armed_bandits.pptx
2Multi_armed_bandits.pptx
ZhiwuGuo1
 

Similaire à Intro to Quant Trading Strategies (Lecture 6 of 10) (20)

Stochastic Optimization
Stochastic OptimizationStochastic Optimization
Stochastic Optimization
 
Stochastic optimal control &amp; rl
Stochastic optimal control &amp; rlStochastic optimal control &amp; rl
Stochastic optimal control &amp; rl
 
Learning group em - 20171025 - copy
Learning group   em - 20171025 - copyLearning group   em - 20171025 - copy
Learning group em - 20171025 - copy
 
Kalman filter for Beginners
Kalman filter for BeginnersKalman filter for Beginners
Kalman filter for Beginners
 
Intro to Quantitative Investment (Lecture 4 of 6)
Intro to Quantitative Investment (Lecture 4 of 6)Intro to Quantitative Investment (Lecture 4 of 6)
Intro to Quantitative Investment (Lecture 4 of 6)
 
Av 738 - Adaptive Filtering - Kalman Filters
Av 738 - Adaptive Filtering - Kalman Filters Av 738 - Adaptive Filtering - Kalman Filters
Av 738 - Adaptive Filtering - Kalman Filters
 
02 - Discrete-Time Markov Models - incomplete.pptx
02 - Discrete-Time Markov Models - incomplete.pptx02 - Discrete-Time Markov Models - incomplete.pptx
02 - Discrete-Time Markov Models - incomplete.pptx
 
Kalman_filtering
Kalman_filteringKalman_filtering
Kalman_filtering
 
Koh_Liang_ICML2017
Koh_Liang_ICML2017Koh_Liang_ICML2017
Koh_Liang_ICML2017
 
Two queue tandem resim 16 presentatio
Two queue tandem resim 16 presentatioTwo queue tandem resim 16 presentatio
Two queue tandem resim 16 presentatio
 
14th_Class_19-03-2024 Control systems.pptx
14th_Class_19-03-2024 Control systems.pptx14th_Class_19-03-2024 Control systems.pptx
14th_Class_19-03-2024 Control systems.pptx
 
Machine Learning - Reinforcement Learning
Machine Learning - Reinforcement LearningMachine Learning - Reinforcement Learning
Machine Learning - Reinforcement Learning
 
lecture_18-19_state_observer_design.pptx
lecture_18-19_state_observer_design.pptxlecture_18-19_state_observer_design.pptx
lecture_18-19_state_observer_design.pptx
 
Passivity-based control of rigid-body manipulator
Passivity-based control of rigid-body manipulatorPassivity-based control of rigid-body manipulator
Passivity-based control of rigid-body manipulator
 
Energy-Based Control of Under-Actuated Mechanical Systems - Remotely Driven A...
Energy-Based Control of Under-Actuated Mechanical Systems - Remotely Driven A...Energy-Based Control of Under-Actuated Mechanical Systems - Remotely Driven A...
Energy-Based Control of Under-Actuated Mechanical Systems - Remotely Driven A...
 
Solving Poisson Equation using Conjugate Gradient Method and its implementation
Solving Poisson Equation using Conjugate Gradient Methodand its implementationSolving Poisson Equation using Conjugate Gradient Methodand its implementation
Solving Poisson Equation using Conjugate Gradient Method and its implementation
 
2Multi_armed_bandits.pptx
2Multi_armed_bandits.pptx2Multi_armed_bandits.pptx
2Multi_armed_bandits.pptx
 
Deep robotics
Deep roboticsDeep robotics
Deep robotics
 
Lesson 9 transcendental functions
Lesson 9 transcendental functionsLesson 9 transcendental functions
Lesson 9 transcendental functions
 
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Fundamental...
Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Fundamental...Lecture Notes:  EEEC4340318 Instrumentation and Control Systems - Fundamental...
Lecture Notes: EEEC4340318 Instrumentation and Control Systems - Fundamental...
 

Dernier

VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...
VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...
VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...
dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
dipikadinghjn ( Why You Choose Us? ) Escorts
 
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
dipikadinghjn ( Why You Choose Us? ) Escorts
 

Dernier (20)

(INDIRA) Call Girl Srinagar Call Now 8617697112 Srinagar Escorts 24x7
(INDIRA) Call Girl Srinagar Call Now 8617697112 Srinagar Escorts 24x7(INDIRA) Call Girl Srinagar Call Now 8617697112 Srinagar Escorts 24x7
(INDIRA) Call Girl Srinagar Call Now 8617697112 Srinagar Escorts 24x7
 
Top Rated Pune Call Girls Viman Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Sex...
Top Rated  Pune Call Girls Viman Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Sex...Top Rated  Pune Call Girls Viman Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Sex...
Top Rated Pune Call Girls Viman Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Sex...
 
Booking open Available Pune Call Girls Wadgaon Sheri 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Wadgaon Sheri  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Wadgaon Sheri  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Wadgaon Sheri 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Dighi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Dighi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Dighi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Dighi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Booking open Available Pune Call Girls Talegaon Dabhade 6297143586 Call Hot ...
Booking open Available Pune Call Girls Talegaon Dabhade  6297143586 Call Hot ...Booking open Available Pune Call Girls Talegaon Dabhade  6297143586 Call Hot ...
Booking open Available Pune Call Girls Talegaon Dabhade 6297143586 Call Hot ...
 
WhatsApp 📞 Call : 9892124323 ✅Call Girls In Chembur ( Mumbai ) secure service
WhatsApp 📞 Call : 9892124323  ✅Call Girls In Chembur ( Mumbai ) secure serviceWhatsApp 📞 Call : 9892124323  ✅Call Girls In Chembur ( Mumbai ) secure service
WhatsApp 📞 Call : 9892124323 ✅Call Girls In Chembur ( Mumbai ) secure service
 
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
Kharghar Blowjob Housewife Call Girls NUmber-9833754194-CBD Belapur Internati...
 
8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available
8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available
8377087607, Door Step Call Girls In Kalkaji (Locanto) 24/7 Available
 
VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
VIP Call Girl in Mumbai 💧 9920725232 ( Call Me ) Get A New Crush Everyday Wit...
 
falcon-invoice-discounting-unlocking-prime-investment-opportunities
falcon-invoice-discounting-unlocking-prime-investment-opportunitiesfalcon-invoice-discounting-unlocking-prime-investment-opportunities
falcon-invoice-discounting-unlocking-prime-investment-opportunities
 
VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...
VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...
VIP Call Girl in Thane 💧 9920725232 ( Call Me ) Get A New Crush Everyday With...
 
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
Solution Manual for Financial Accounting, 11th Edition by Robert Libby, Patri...
 
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
Navi Mumbai Cooperetive Housewife Call Girls-9833754194-Natural Panvel Enjoye...
 
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
VIP Independent Call Girls in Andheri 🌹 9920725232 ( Call Me ) Mumbai Escorts...
 
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
Mira Road Awesome 100% Independent Call Girls NUmber-9833754194-Dahisar Inter...
 
Indore Real Estate Market Trends Report.pdf
Indore Real Estate Market Trends Report.pdfIndore Real Estate Market Trends Report.pdf
Indore Real Estate Market Trends Report.pdf
 
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
VIP Independent Call Girls in Mumbai 🌹 9920725232 ( Call Me ) Mumbai Escorts ...
 
Top Rated Pune Call Girls Shikrapur ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated  Pune Call Girls Shikrapur ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...Top Rated  Pune Call Girls Shikrapur ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
Top Rated Pune Call Girls Shikrapur ⟟ 6297143586 ⟟ Call Me For Genuine Sex S...
 
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
VIP Call Girl in Mira Road 💧 9920725232 ( Call Me ) Get A New Crush Everyday ...
 
Enjoy Night⚡Call Girls Patel Nagar Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Patel Nagar Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Patel Nagar Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Patel Nagar Delhi >༒8448380779 Escort Service
 

Intro to Quant Trading Strategies (Lecture 6 of 10)

  • 1. Introduction to Algorithmic Trading Strategies Lecture 6 Pairs Trading by Stochastic Spread Methods Haksun Li haksun.li@numericalmethod.com www.numericalmethod.com
  • 2. Outline  First passage time  Kalman filter  Maximum likelihood estimate  EM algorithm 2
  • 3. References  As the emphasis of the basic co-integration methods of most papers are on the constructionof a synthetic mean-reverting asset, the stochastic spread methods focuses on the dynamic of the price of the synthetic asset.  Most referenced academic paper: Elliot, van der Hoek, and Malcolm, 2005, Pairs Trading  Model the spread process as a state-space version of Ornstein-Uhlenbeck process  Jonathan Chiu, Daniel Wijaya Lukman, Kourosh Modarresi, Avinayan Senthi Velayutham. High-frequency Trading. Stanford University. 2011  The idea has been conceived by a lot of popular pairs trading books  Technical analysis and charting for the spread, Ehrman, 2005, The Handbook of Pairs Trading  ARMA model, HMM ARMA model, some non-parametric approach, and a Kalman filter model, Vidyamurthy, 2004, Pairs Trading: Quantitative Methods and Analysis 3
  • 4. Spread as a Mean-Reverting Process  𝑥 𝑘 − 𝑥 𝑘−1 = 𝑎 − 𝑏𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘  = 𝑏 𝑎 𝑏 − 𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘  The long term mean = 𝑎 𝑏 .  The rate of mean reversion = 𝑏. 4
  • 5. Sum of Power Series  We note that  = ∑ 𝑎 𝑖𝑘−1 𝑖=0 = 𝑎 𝑘−1 𝑎−1 5
  • 6. Unconditional Mean  𝐸 𝑥 𝑘 = 𝜇 𝑘 = 𝜇 𝑘−1 + 𝑎 − 𝑏𝜇 𝑘−1 𝜏  = 𝑎𝜏 + 1 − 𝑏𝜏 𝜇 𝑘−1  = 𝑎𝜏 + 1 − 𝑏𝜏 𝑎𝜏 + 1 − 𝑏𝜏 𝜇 𝑘−2  = 𝑎𝜏 + 1 − 𝑏𝜏 𝑎𝜏 + 1 − 𝑏𝜏 2 𝜇 𝑘−2  = ∑ 1 − 𝑏𝜏 𝑖𝑘−1 𝑖=0 𝑎𝜏 + 1 − 𝑏𝜏 𝑘 𝜇0  = 𝑎𝜏 1− 1−𝑏𝜏 𝑘 1− 1−𝑏𝜏 + 1 − 𝑏𝜏 𝑘 𝜇0  = 𝑎𝜏 1− 1−𝑏𝜏 𝑘 𝑏𝜏 + 1 − 𝑏𝜏 𝑘 𝜇0  = 𝑎 𝑏 − 𝑎 𝑏 1 − 𝑏𝜏 𝑘 + 1 − 𝑏𝜏 𝑘 𝜇0 6
  • 7. Long Term Mean  𝑎 𝑏 − 𝑎 𝑏 1 − 𝑏𝜏 𝑘 + 1 − 𝑏𝜏 𝑘 𝜇0  → 𝑎 𝑏 7
  • 8. Unconditional Variance  Var 𝑥 𝑘 = 𝜎 𝑘 2 = 1 − 𝑏𝜏 2 𝜎 𝑘−1 2 + 𝜎2 𝜏  = 1 − 𝑏𝜏 2 𝜎 𝑘−1 2 + 𝜎2 𝜏  = 1 − 𝑏𝜏 2 1 − 𝑏𝜏 2 𝜎 𝑘−2 2 + 𝜎2 𝜏 + 𝜎2 𝜏  = 𝜎2 𝜏 ∑ 1 − 𝑏𝜏 2𝑖𝑘−1 𝑖=0 + 1 − 𝑏𝜏 2𝑘 𝜎0 2  = 𝜎2 𝜏 1− 1−𝑏𝜏 2𝑘 1− 1−𝑏𝜏 2 + 1 − 𝑏𝜏 2𝑘 𝜎0 2 8
  • 9. Long Term Variance  𝜎2 𝜏 1− 1−𝑏𝜏 2𝑘 1− 1−𝑏𝜏 2 + 1 − 𝑏𝜏 2𝑘 𝜎0 2  → 𝜎2 𝜏 1− 1−𝑏𝜏 2 9
  • 10. Observations and Hidden State Process  The hidden state process is:  𝑥 𝑘 = 𝑥 𝑘−1 + 𝑎 − 𝑏𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘  = 𝑎𝜏 + 1 − 𝑏𝜏 𝑥 𝑘−1 + 𝜎 𝜏𝜀 𝑘  = 𝐴 + 𝐵𝑥 𝑘−1 + 𝐶𝜀 𝑘  𝐴 ≥ 0, 0 < 𝐵 < 1  The observations:  𝑦 𝑘 = 𝑥 𝑘 + 𝐷𝜔 𝑘  We want to compute the expected state from observations.  𝑥� 𝑘 = 𝑥� 𝑘|𝑘 = 𝐸 𝑥 𝑘|𝑌𝑘 10
  • 11. First Passage Time  Standardized Ornstein-Uhlenbeck process  𝑑𝑑 𝑡 = −𝑍 𝑡 𝑑𝑑 + 2𝑑𝑑 𝑡  First passage time  𝑇0,𝑐 = inf 𝑡 ≥ 0, 𝑍 𝑡 = 0|𝑍 0 = 𝑐  The pdf of 𝑇0,𝑐 has a maximum value at  𝑡̂ = 1 2 ln 1 + 1 2 𝑐2 − 3 2 + 4𝑐2 + 𝑐2 − 3 11
  • 12. A Sample Trading Strategy  𝑥 𝑘 = 𝑥 𝑘−1 + 𝑎 − 𝑏𝑥 𝑘−1 𝜏 + 𝜎 𝜏𝜀 𝑘  𝑑𝑋 𝑡 = 𝑎 − 𝑏𝑏 𝑡 𝑑𝑑 + 𝜎𝑑𝑑 𝑡  𝑋 0 = 𝜇 + 𝑐 𝜎 2𝜌 , 𝑋 𝑇 = 𝜇  𝑇 = 1 𝜌 𝑡̂  Buy when 𝑦 𝑘 < 𝜇 − 𝑐 𝜎 2𝜌 unwind after time 𝑇  Sell when 𝑦 𝑘 > 𝜇 + 𝑐 𝜎 2𝜌 unwind after time 𝑇 12
  • 13. Kalman Filter  The Kalman filter is an efficient recursive filter that estimates the state of a dynamic system from a series of incomplete and noisy measurements. 13
  • 14. Conceptual Diagram prediction at time t Update at time t+1 as new measurements come in correct for better estimation 14
  • 15. A Linear Discrete System  𝑥 𝑘 = 𝐹𝑘 𝑥 𝑘−1 + 𝐵 𝑘 𝑢 𝑘 + 𝜔 𝑘  𝐹𝑘: the state transition model applied to the previous state  𝐵 𝑘: the control-input model applied to control vectors  𝜔 𝑘~𝑁 0, 𝑄 𝑘 : the noise process drawn from multivariate Normal distribution 15
  • 16. Observations and Noises  𝑧 𝑘 = 𝐻 𝑘 𝑥 𝑘 + 𝑣 𝑘  𝐻 𝑘: the observation model mapping the true states to observations  𝑣 𝑘~𝑁 0, 𝑅 𝑘 : the observation noise 16
  • 18. Prediction  predicted a prior state estimate  𝑥� 𝑘|𝑘−1 = 𝐹𝑘 𝑥� 𝑘−1|𝑘−1 + 𝐵 𝑘 𝑢 𝑘  predicted a prior estimate covariance  𝑃𝑘|𝑘−1 = 𝐹𝑘 𝑃𝑘−1|𝑘−1 𝐹𝑘 𝑇 + 𝑄 𝑘 18
  • 19. Update  measurement residual  𝑦� 𝑘 = 𝑧 𝑘 − 𝐻 𝑘 𝑥� 𝑘|𝑘−1  residual covariance  𝑆 𝑘 = 𝐻 𝑘 𝑃𝑘|𝑘−1 𝐻 𝑘 𝑇 + 𝑅 𝑘  optimal Kalman gain  𝐾𝑘 = 𝑃𝑘|𝑘−1 𝐻 𝑘 𝑇 𝑆 𝑘 −1  updated a posteriori state estimate  𝑥� 𝑘|𝑘 = 𝑥� 𝑘|𝑘−1 + 𝐾𝑘 𝑦� 𝑘  updated a posteriori estimate covariance  𝑃𝑘|𝑘 = 𝐼 − 𝐾𝑘 𝐻 𝑘 𝑃𝑘|𝑘−1 19
  • 20. Computing the ‘Best’ State Estimate  Given 𝐴, 𝐵, 𝐶, 𝐷, we define the conditional variance  𝑅 𝑘 = Σ 𝑘|𝑘 ≡ E 𝑥 𝑘 − 𝑥� 𝑘 2|𝑌𝑘  Start with 𝑥�0|0 = 𝑦0, 𝑅0 = 𝐷2. 20
  • 21. Predicted (a Priori) State Estimation  𝑥� 𝑘+1|𝑘  = E 𝑥 𝑘+1|𝑌𝑘  = E 𝐴 + 𝐵𝑥 𝑘 + 𝐶𝜀 𝑘+1|𝑌𝑘  = E 𝐴 + 𝐵𝑥 𝑘|𝑌𝑘  = 𝐴 + 𝐵 E 𝑥 𝑘|𝑌𝑘  = 𝐴 + 𝐵𝑥� 𝑘|𝑘 21
  • 22. Predicted (a Priori) Variance  Σ 𝑘+1|𝑘  = E 𝑥 𝑘+1 − 𝑥� 𝑘+1 2|𝑌𝑘  = E 𝐴 + 𝐵𝐵 𝑘 + 𝐶𝜀 𝑘+1 − 𝑥� 𝑘+1 2|𝑌𝑘  = E 𝐴 + 𝐵𝐵 𝑘 + 𝐶𝜀 𝑘+1 − 𝐴 − 𝐵𝑥� 𝑘|𝑘 2 |𝑌𝑘  = E 𝐵𝐵 𝑘 − 𝐵𝑥� 𝑘|𝑘 + 𝐶𝜀 𝑘+1 2 |𝑌𝑘  = E 𝐵𝐵 𝑘 − 𝐵𝑥� 𝑘|𝑘 2 + 𝐶2 𝜀2 𝑘+1|𝑌𝑘  = 𝐵2Σ 𝑘|𝑘 + 𝐶2 22
  • 23. Minimize Posteriori Variance  Let the Kalman updating formula be  𝑥� 𝑘+1 = 𝑥� 𝑘+1|𝑘+1 = 𝑥� 𝑘+1|𝑘 + 𝐾 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘  We want to solve for K such that the conditional variance is minimized.  Σ 𝑘+1|𝑘 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1 2|𝑌𝑘 23
  • 24. Solve for K  E 𝑥 𝑘+1 − 𝑥� 𝑘+1 2|𝑌𝑘  = E 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 − 𝐾 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘 2 |𝑌𝑘  = E 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 − 𝐾 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 + 𝐷𝜔 𝑘+1 2 |𝑌𝑘  = E 1 − 𝐾 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 − 𝐾𝐾𝜔 𝑘+1 2 |𝑌𝑘  = 1 − 𝐾 2 E 𝑥 𝑘+1 − 𝑥� 𝑘+1|𝑘 2 |𝑌𝑘 + 𝐾2 𝐷2  = 1 − 𝐾 2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2 24
  • 25. First Order Condition for k  𝑑 𝑑𝐾 1 − 𝐾 2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2  = 𝑑 𝑑𝐾 1 − 2𝐾 + 𝐾2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2  = −2 + 2𝐾 Σ 𝑘+1|𝑘 + 2𝐾𝐷2  = 0 25
  • 26. Optimal Kalman Filter  𝐾𝑘+1 = Σ 𝑘+1|𝑘 Σ 𝑘+1|𝑘+𝐷2 26
  • 27. Updated (a Posteriori) State Estimation  So, we have the “optimal” Kalman updating rule.  𝑥� 𝑘+1 = 𝑥� 𝑘+1|𝑘+1 = 𝑥� 𝑘+1|𝑘 + 𝐾 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘  = 𝑥� 𝑘+1|𝑘 + Σ 𝑘+1|𝑘 Σ 𝑘+1|𝑘+𝐷2 𝑦 𝑘+1 − 𝑥� 𝑘+1|𝑘 27
  • 28. Updated (a Posteriori) Variance  𝑅 𝑘+1 = Σ 𝑘+1|𝑘 = E 𝑥 𝑘+1 − 𝑥� 𝑘+1 2 |𝑌𝑘+1 = 1 − 𝐾 2 Σ 𝑘+1|𝑘 + 𝐾2 𝐷2  = 1 − Σ 𝑘+1|𝑘 Σ 𝑘+1|𝑘+𝐷2 2 Σ 𝑘+1|𝑘 + Σ 𝑘+1|𝑘 Σ 𝑘+1|𝑘+𝐷2 2 𝐷2  = 𝐷2 Σ 𝑘+1|𝑘+𝐷2 2 Σ 𝑘+1|𝑘 + Σ 𝑘+1|𝑘 Σ 𝑘+1|𝑘+𝐷2 2 𝐷2  = 𝐷4Σ 𝑘+1|𝑘+𝐷2Σ 𝑘+1|𝑘 2 Σ 𝑘+1|𝑘+𝐷2 2  = 𝐷4Σ 𝑘+1|𝑘+𝐷2Σ 𝑘+1|𝑘 2 Σ 𝑘+1|𝑘+𝐷2 2  = Σ 𝑘+1|𝑘 𝐷2 𝐷2+Σ 𝑘+1|𝑘 𝐷2 Σ 𝑘+1|𝑘+𝐷2 2  = Σ 𝑘+1|𝑘 𝐷2 28
  • 29. Parameter Estimation  We need to estimate the parameters 𝜗 = 𝐴, 𝐵, 𝐶, 𝐷 from the observable data before we can use the Kalman filter model.  We need to write down the likelihood function in terms of 𝜗, and then maximize w.r.t. 𝜗. 29
  • 30. Likelihood Function  A likelihood function (often simply the likelihood) is a function of the parameters of a statistical model, defined as follows: the likelihood of a set of parameter values given some observed outcomes is equal to the probability of those observed outcomes given those parameter values.  𝐿 𝜗; 𝑌 = 𝑝 𝑌|𝜗 30
  • 31. Maximum Likelihood Estimate  We find 𝜗 such that 𝐿 𝜗; 𝑌 is maximized given the observation. 31
  • 32. Example Using the Normal Distribution  We want to estimate the mean of a sample of size 𝑁 drawn from a Normal distribution.  𝑓 𝑦 = 1 2𝜋𝜎2 exp − 𝑦−𝜇 2 2𝜎2  𝜗 = 𝜇, 𝜎  𝐿 𝑁 𝜗; 𝑌 = ∏ 1 2𝜋𝜎2 exp − 𝑦 𝑖−𝜇 2 2𝜎2 𝑁 𝑖=1 32
  • 33. Log-Likelihood  log 𝐿 𝑁 𝜗; 𝑌 = ∑ log 1 2𝜋𝜎2 − 𝑥𝑖−𝜇 2 2𝜎2 𝑁 𝑖=1  Maximizing the log-likelihood is equivalent to maximizing the following.  − ∑ 𝑥𝑖 − 𝜇 2𝑁 𝑖=1  First order condition w.r.t.,𝜇  𝜇 = 1 𝑁 ∑ 𝑥𝑖 𝑁 𝑖=1 33
  • 34. Nelder-Mead  After we write down the likelihood function for the Kalman model in terms of 𝜗 = 𝐴, 𝐵, 𝐶, 𝐷 , we can run any multivariate optimization algorithm, e.g., Nelder- Mead, to search for 𝜗.  ma𝑥 𝜗 𝐿 𝜗; 𝑌  The disadvantage is that it may not converge well, hence not landing close to the optimal solution. 34
  • 35. Marginal Likelihood  For the set of hidden states, 𝑋𝑡 , we write  𝐿 𝜗; 𝑌 = 𝑝 𝑌|𝜗 = ∑ 𝑝 𝑌, 𝑋|𝜗𝑋  Assume we know the conditional distribution of 𝑋, we could instead maximize the following.  ma𝑥 𝜗 E 𝑋 𝐿 𝜗|𝑌, 𝑋 , or  ma𝑥 𝜗 E 𝑋 log 𝐿 𝜗|𝑌, 𝑋  The expectation is a weighted sum of the (log-) likelihoods weighted by the probability of the hidden states. 35
  • 36. The Q-Function  Where do we get the conditional distribution of 𝑋𝑡 from?  Suppose we somehow have an (initial) estimation of the parameters, 𝜗0. Then the model has no unknowns. We can compute the distribution of 𝑋𝑡 .  𝑄 𝜗|𝜗 𝑡 = E 𝑋|𝑌,𝜗 log 𝐿 𝜗|𝑌, 𝑋 36
  • 37. EM Intuition  Suppose we know 𝜗, we know completely about the mode; we can find 𝑋.  Suppose we know 𝑋, we can estimate 𝜗, by, e.g., maximum likelihood.  What do we do if we don’t know both 𝜗 and 𝑋? 37
  • 38. Expectation-Maximization Algorithm  Expectation step (E-step): compute the expected value of the log-likelihood function, w.r.t., the conditional distribution of 𝑋 under 𝑌and 𝜗.  𝑄 𝜗|𝜗 𝑡 = E 𝑋|𝑌,𝜗 log 𝐿 𝜗|𝑌, 𝑋  Maximization step (M-step): find the parameters, 𝜗, that maximize the Q-value.  𝜗 𝑡+1 = argmax 𝜗 𝑄 𝜗|𝜗 𝑡 38
  • 39. EM Algorithms for Kalman Filter  Offline: Shumway and Stoffer smoother approach, 1982  Online: Elliott and Krishnamurthy filter approach, 1999 39
  • 40. A Trading Algorithm  From 𝑦0, 𝑦1, …, 𝑦 𝑁, we estimate 𝜗̂ 𝑁 .  Decide whether to make a trade at 𝑡 = 𝑁, unwind at 𝑡 = 𝑁 + 1, or some time later, e.g., 𝑡 = 𝑁 + 𝑇.  As 𝑦 𝑁+1arrives, estimate 𝜗̂ 𝑁 + 1 .  Repeat. 40