66
Introduction to Algorithmic Trading Strategies Lecture 4 Optimal Pairs Trading by Stochastic Control Haksun Li [email protected] www.numericalmethod.com

Introduction to Algorithmic Trading Strategies Lecture 4

  • Upload
    komala

  • View
    90

  • Download
    4

Embed Size (px)

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 Presentation

Citation preview

Page 1: Introduction to Algorithmic Trading Strategies Lecture  4

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

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

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

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

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

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

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

8

Instantaneous Correlation Let denote the instantaneous correlation

coefficient between and .

Page 9: Introduction to Algorithmic Trading Strategies Lecture  4

9

Univariate Ito’s Lemma

Assume is twice differentiable of two real variables

We have

Page 10: Introduction to Algorithmic Trading Strategies Lecture  4

10

Log example For G.B.M., ,

Page 11: Introduction to Algorithmic Trading Strategies Lecture  4

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

12

Multivariate Example

Page 13: Introduction to Algorithmic Trading Strategies Lecture  4

13

What is the Dynamic of Asset At?

Page 14: Introduction to Algorithmic Trading Strategies Lecture  4

14

Dynamic of Asset At

Page 15: Introduction to Algorithmic Trading Strategies Lecture  4

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

16

Self-Financing Portfolio Dynamic

Page 17: Introduction to Algorithmic Trading Strategies Lecture  4

17

Power Utility Investor preference:

Page 18: Introduction to Algorithmic Trading Strategies Lecture  4

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

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

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

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

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

23

Value function Terminal condition:

DP equation:

By Ito’s lemma:

Page 24: Introduction to Algorithmic Trading Strategies Lecture  4

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

25

HJB for Our Portfolio Value

Page 26: Introduction to Algorithmic Trading Strategies Lecture  4

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

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

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

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

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

31

Dis-equilibrium Let . Rewrite:

Multiply by .

Page 32: Introduction to Algorithmic Trading Strategies Lecture  4

32

Simplification Note that The PDE becomes

Page 33: Introduction to Algorithmic Trading Strategies Lecture  4

33

The Partial Differential Equation (3)

𝐺𝑡𝐺𝑉𝑉 𝜂2+𝐺𝑥𝑏𝐺𝑉𝑉 𝜂2+12 𝐺𝑥𝑥𝐺𝑉𝑉 𝜂 4−

12 (𝐺𝑉 𝑏+𝐺𝑉𝑥𝜂2 )

2=0

Page 34: Introduction to Algorithmic Trading Strategies Lecture  4

34

Ansatz for G

Page 35: Introduction to Algorithmic Trading Strategies Lecture  4

35

Another PDE (1)

Divide by .

Page 36: Introduction to Algorithmic Trading Strategies Lecture  4

36

Ansatz for

Page 37: Introduction to Algorithmic Trading Strategies Lecture  4

37

Boundary Conditions

Page 38: Introduction to Algorithmic Trading Strategies Lecture  4

38

Yet Another PDE (1)

Divide by .

Page 39: Introduction to Algorithmic Trading Strategies Lecture  4

39

Yet Another PDE (2)

Page 40: Introduction to Algorithmic Trading Strategies Lecture  4

40

Expansion in

Page 41: Introduction to Algorithmic Trading Strategies Lecture  4

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

42

The Three PDE’s (1)

Page 43: Introduction to Algorithmic Trading Strategies Lecture  4

43

PDE in

Page 44: Introduction to Algorithmic Trading Strategies Lecture  4

44

PDE in ,

Page 45: Introduction to Algorithmic Trading Strategies Lecture  4

45

PDE in , ,

Page 46: Introduction to Algorithmic Trading Strategies Lecture  4

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

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

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

49

Substitution Suppose .

goes to 0 by the definition of

Page 50: Introduction to Algorithmic Trading Strategies Lecture  4

50

Solving

1st order linear ODE

Page 51: Introduction to Algorithmic Trading Strategies Lecture  4

51

Solving for

boundary condition:

Page 52: Introduction to Algorithmic Trading Strategies Lecture  4

52

Solution (1)

Page 53: Introduction to Algorithmic Trading Strategies Lecture  4

53

Solution (2)

Page 54: Introduction to Algorithmic Trading Strategies Lecture  4

54

Solution (3)

Page 55: Introduction to Algorithmic Trading Strategies Lecture  4

55

Solving

Let

Page 56: Introduction to Algorithmic Trading Strategies Lecture  4

56

First Order Non-Constant Coefficients

Page 57: Introduction to Algorithmic Trading Strategies Lecture  4

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

58

Integrating Factor (2)

Page 59: Introduction to Algorithmic Trading Strategies Lecture  4

59

Solution

Page 60: Introduction to Algorithmic Trading Strategies Lecture  4

60

,

Page 61: Introduction to Algorithmic Trading Strategies Lecture  4

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

62

Solving

With and solved, we are now ready to solve .

Page 63: Introduction to Algorithmic Trading Strategies Lecture  4

63

Computing the Optimal Position

Page 64: Introduction to Algorithmic Trading Strategies Lecture  4

64

The Optimal Position

Page 65: Introduction to Algorithmic Trading Strategies Lecture  4

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

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