introduction to algorithmic trading strategies lecture 4
DESCRIPTION
Introduction to Algorithmic Trading Strategies Lecture 4. Optimal Pairs Trading by Stochastic Control. Haksun Li [email protected] www.numericalmethod.com. Outline. Problem formulation Ito’s lemma Dynamic programming Hamilton-Jacobi-Bellman equation Riccati equation - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/1.jpg)
Introduction to Algorithmic Trading StrategiesLecture 4
Optimal Pairs Trading by Stochastic Control
Haksun [email protected]
www.numericalmethod.com
![Page 2: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/2.jpg)
2
Outline Problem formulation Ito’s lemma Dynamic programming Hamilton-Jacobi-Bellman equation Riccati equation Integrating factor
![Page 3: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/3.jpg)
3
Reference Optimal Pairs Trading: A Stochastic Control
Approach. Mudchanatongsuk, S., Primbs, J.A., Wong, W. Dept. of Manage. Sci. & Eng., Stanford Univ., Stanford, CA.
![Page 4: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/4.jpg)
4
Basket Creation vs. Trading In lecture 3, we discussed a few ways to
construct a mean-reverting basket. In this and the next lectures, we discuss how
to trade a mean-reverting asset, if such exists.
![Page 5: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/5.jpg)
5
Stochastic Control We model the difference between the log-
returns of two assets as an Ornstein-Uhlenbeck process.
We compute the optimal position to take as a function of the deviation from the equilibrium.
This is done by solving the corresponding the Hamilton-Jacobi-Bellman equation.
![Page 6: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/6.jpg)
6
Formulation Assume a risk free asset, which satisfies
Assume two assets, and . Assumefollows a geometric Brownian motion.
is the spread between the two assets.
![Page 7: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/7.jpg)
7
Ornstein-Uhlenbeck Process We assume the spread, the basket that we
want to trade, follows a mean-reverting process.
is the long term equilibrium to which the spread reverts.
is the rate of reversion. It must be positive to ensure stability around the equilibrium value.
![Page 8: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/8.jpg)
8
Instantaneous Correlation Let denote the instantaneous correlation
coefficient between and .
![Page 9: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/9.jpg)
9
Univariate Ito’s Lemma
Assume is twice differentiable of two real variables
We have
![Page 10: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/10.jpg)
10
Log example For G.B.M., ,
![Page 11: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/11.jpg)
11
Multivariate Ito’s Lemma
Assume is a vector Ito process is twice differentiable
We have
![Page 12: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/12.jpg)
12
Multivariate Example
![Page 13: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/13.jpg)
13
What is the Dynamic of Asset At?
![Page 14: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/14.jpg)
14
Dynamic of Asset At
![Page 15: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/15.jpg)
15
Notations : the value of a self-financing pairs trading
portfolio :the portfolio weight for stock A :the portfolio weight for stock B
![Page 16: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/16.jpg)
16
Self-Financing Portfolio Dynamic
![Page 17: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/17.jpg)
17
Power Utility Investor preference:
![Page 18: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/18.jpg)
18
Problem Formulation , s.t., ,
Note that we simplify GBM to BM of , and remove some constants.
![Page 19: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/19.jpg)
19
Dynamic Programming
Consider a stage problem to minimize (or maximize) the accumulated costs over a system path.
s0
s11
s12
timet = 0 t = 1
S21
S22
s23
t = 2
3
2
3
5
Cost =
s3
s12
5
4
3
1
5
![Page 20: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/20.jpg)
20
Dynamic Programming Formulation State change:
: time : state : control decision selected at time : a random noise
Cost: Objective: minimize (maximize) the expected
cost. We need to take expectation to account for the
noise, .
![Page 21: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/21.jpg)
21
Principle of Optimality Let be an optimal policy for the basic
problem, and assume that when using , a give state occurs at time with positive probability. Consider the sub-problem whereby we are at at time and wish to minimize the “cost-to-go” from time to time .
Then the truncated policy is optimal for this sub-problem.
![Page 22: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/22.jpg)
22
Dynamic Programming Algorithm For every initial state , the optimal cost of
the basic problem is equal to , given by the last step of the following algorithm, which proceeds backward in time from period to period
![Page 23: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/23.jpg)
23
Value function Terminal condition:
DP equation:
By Ito’s lemma:
![Page 24: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/24.jpg)
24
Hamilton-Jacobi-Bellman Equation Cancel on both LHS and RHS. Divide by time discretization, . Take limit as , hence Ito.
The optimal portfolio position is .
![Page 25: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/25.jpg)
25
HJB for Our Portfolio Value
![Page 26: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/26.jpg)
26
Taking Expectation All disapper because of the expectation
operator. Only the deterministic terms remain. Divide LHR and RHS by .
![Page 27: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/27.jpg)
27
Dynamic Programming Solution Solve for the cost-to-go function, . Assume that the optimal policy is .
![Page 28: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/28.jpg)
28
First Order Condition Differentiate w.r.t. .
In order to determine the optimal position, , we need to solve for to get , , and .
![Page 29: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/29.jpg)
29
The Partial Differential Equation (1)𝐺𝑡−
𝐺𝑉 (𝐺𝑉 (𝑘 (𝜃−𝑥𝑡 ) )+𝐺𝑉𝑥𝜂2
𝐺𝑉𝑉 𝜂2 𝑘 (𝜃− 𝑥𝑡 ))+¿
𝐺𝑥 (𝑘 (𝜃−𝑥𝑡 ))+¿ 12𝐺𝑉𝑉 𝜂
2(𝐺𝑉 (𝑘 (𝜃−𝑥𝑡 ))+𝐺𝑉𝑥𝜂2
𝐺𝑉𝑉 𝜂2 )
2
+¿ 12𝐺𝑥𝑥𝜂
2−
𝐺𝑉𝑥𝜂2𝐺𝑉 (𝑘 (𝜃− 𝑥𝑡 ))+𝐺𝑉𝑥𝜂2
𝐺𝑉𝑉 𝜂2
=0
¿
![Page 30: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/30.jpg)
30
The Partial Differential Equation (2)𝐺𝑡−
𝐺𝑉 𝑘 (𝜃−𝑥𝑡 )𝐺𝑉 (𝑘 (𝜃−𝑥𝑡 ))+𝐺𝑉𝑥𝜂 2
𝐺𝑉𝑉 𝜂2 +¿
𝐺𝑥 (𝑘 (𝜃−𝑥𝑡 ))+¿12
[𝐺𝑉 (𝑘 (𝜃−𝑥𝑡 ))+𝐺𝑉𝑥𝜂2 ]2
𝐺𝑉𝑉 𝜂2+¿12𝐺𝑥𝑥𝜂2−
𝐺𝑉𝑥𝐺𝑉 (𝑘 (𝜃−𝑥𝑡 ) )+𝐺𝑉𝑥𝜂
2
𝐺𝑉𝑉
=0
¿
![Page 31: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/31.jpg)
31
Dis-equilibrium Let . Rewrite:
Multiply by .
![Page 32: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/32.jpg)
32
Simplification Note that The PDE becomes
![Page 33: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/33.jpg)
33
The Partial Differential Equation (3)
𝐺𝑡𝐺𝑉𝑉 𝜂2+𝐺𝑥𝑏𝐺𝑉𝑉 𝜂2+12 𝐺𝑥𝑥𝐺𝑉𝑉 𝜂 4−
12 (𝐺𝑉 𝑏+𝐺𝑉𝑥𝜂2 )
2=0
![Page 34: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/34.jpg)
34
Ansatz for G
![Page 35: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/35.jpg)
35
Another PDE (1)
Divide by .
![Page 36: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/36.jpg)
36
Ansatz for
![Page 37: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/37.jpg)
37
Boundary Conditions
![Page 38: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/38.jpg)
38
Yet Another PDE (1)
Divide by .
![Page 39: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/39.jpg)
39
Yet Another PDE (2)
![Page 40: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/40.jpg)
40
Expansion in
![Page 41: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/41.jpg)
41
Grouping in
(𝑔𝑡+𝑘𝑔 𝛽𝜃+12 𝜂
2𝑔𝛽2+𝜂2𝑔𝛼− 𝜆𝑔𝜂2
𝑘2𝜃2− 𝜆𝑔𝜂2 𝛽2−2 𝜆𝑔𝑘 𝛽𝜃 )+(𝑔𝛽𝑡−𝑘𝑔 𝛽+2𝛼𝑘𝑔 𝜃+2𝜂2𝑔𝛼𝛽+2 𝜆𝑔𝜂2
𝑘2𝜃+2 𝜆𝑔𝑘 𝛽−4𝜆𝑔𝑘 𝜃𝛼−4 𝜆𝑔𝜂2𝛼𝛽)𝑥+(𝑔𝛼 𝑡−2𝛼𝑘𝑔+2𝜂 2𝑔𝛼2− 𝜆𝑔𝜂2
𝑘2−4 𝜆𝑔𝜂2𝛼2+4 𝜆𝑔𝑘𝛼)𝑥2=0
![Page 42: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/42.jpg)
42
The Three PDE’s (1)
![Page 43: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/43.jpg)
43
PDE in
![Page 44: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/44.jpg)
44
PDE in ,
![Page 45: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/45.jpg)
45
PDE in , ,
![Page 46: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/46.jpg)
46
Riccati Equation A Riccati equation is any ordinary differential
equation that is quadratic in the unknown function.
![Page 47: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/47.jpg)
47
Solving a Riccati Equation by Integration Suppose a particular solution, , can be found. is the general solution, subject to some
boundary condition.
![Page 48: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/48.jpg)
48
Particular Solution Either or is a particular solution to the ODE.
This can be verified by mere substitution.
![Page 49: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/49.jpg)
49
Substitution Suppose .
goes to 0 by the definition of
![Page 50: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/50.jpg)
50
Solving
1st order linear ODE
![Page 51: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/51.jpg)
51
Solving for
boundary condition:
![Page 52: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/52.jpg)
52
Solution (1)
![Page 53: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/53.jpg)
53
Solution (2)
![Page 54: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/54.jpg)
54
Solution (3)
![Page 55: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/55.jpg)
55
Solving
Let
![Page 56: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/56.jpg)
56
First Order Non-Constant Coefficients
![Page 57: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/57.jpg)
57
Integrating Factor (1)
We try to find an integrating factor s.t.
Divide LHS and RHS by .
By comparison,
![Page 58: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/58.jpg)
58
Integrating Factor (2)
![Page 59: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/59.jpg)
59
Solution
![Page 60: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/60.jpg)
60
,
![Page 61: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/61.jpg)
61
Solution
𝛽 (𝑡 )=𝑘𝜃𝜂2
(1+√1−𝛾 )exp ( 2𝑘
√1−𝛾(𝑇 −𝑡 ))−1
1+[1− 21−√1−𝛾 ]exp( 2𝑘
√1−𝛾(𝑇 −𝑡 ))
![Page 62: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/62.jpg)
62
Solving
With and solved, we are now ready to solve .
![Page 63: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/63.jpg)
63
Computing the Optimal Position
![Page 64: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/64.jpg)
64
The Optimal Position
![Page 65: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/65.jpg)
65
P&L for Simulated Data
The portfolio increases from $1000 to $4625 in one year.
![Page 66: Introduction to Algorithmic Trading Strategies Lecture 4](https://reader036.vdocument.in/reader036/viewer/2022081422/568162c8550346895dd35250/html5/thumbnails/66.jpg)
66
Parameter Estimation Can be done using Maximum Likelihood. Evaluation of parameter sensitivity can be
done by Monte Carlo simulation. In real trading, it is better to be conservative
about the parameters. Better underestimate the mean-reverting speed Better overestimate the noise
To account for parameter regime changes, we can use: a hidden Markov chain model moving calibration window