algorithmic trading: order-flow - sebastian...

28
Algorithmic Trading: Order-Flow Sebastian Jaimungal University of Toronto many thanks to ´ Alvaro Cartea, Oxford Nov, 2016 (c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 1 / 28

Upload: hahanh

Post on 28-Jul-2018

288 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Algorithmic Trading: Order-Flow

Sebastian JaimungalUniversity of Toronto

many thanks to

Alvaro Cartea, Oxford

Nov, 2016

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 1 / 28

Page 2: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

I Trade volume and intensity is stochastic throughout the day

I All order-flow affects prices... not just “me”

I How can we use order-flow information and prediction toimprove execution performance?

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 2 / 28

Page 3: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

Figure: ORCL (2013) traded volume using 5 minute buckets.

Time

log(1+volume)

10:00 12:00 14:00 16:006

8

10

12

14

0

0.02

0.04

0.06

0.08

0.1

10:00 12:00 14:00 16:006

8

10

12

14

Time

log(1+volume)

10:00am 12:00pm 2:00pm 4:00pm0

0.5

1

1.5

2x 10

4

Time

Tradingrate

sellbuy

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 3 / 28

Page 4: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

FDA

A primer on Functional Data Analysis (FDA)

I Two general approachesI Smoothing Penalty methods:

ξ =n∑

i=1

(yi − x(ti ))2 + λ

∫D

[(Lx)(t)]2 dt

I for a roughness operator L – e.g., curvature

I smoothness parameter λ trades off fit to the data, androughness

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 4 / 28

Page 5: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

FDA

I Let’s look the Legendre polynomials Pn(t) basis, these aresolutions to Legendre’s ODE

d

dt

((1− t2)

d

dtPn(t)

)+ n(n + 1)Pn(t) = 0

and can be written as

Pn(t) =1

2n n!

dn

dtn

((t2 − 1)n

)They form an orthogonal basis w.r.t. the L2 inner product∫ 1

−1

Pm(t)Pn(t) dt =2

2 n + 1δmn .

−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 5 / 28

Page 6: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

FDA

I Take day i , and regress the observed values{yij : j = 1, . . . , ni} onto the basis, i.e.

αi = arg minα

ni∑j=1

(yij −

K∑k=1

αi ,k Pk(tij)

)2

this can be done using least-squares.

10:00 12:00 14:00 16:008

9

10

11

12

13

Time

log(1+volume)

(a) Oct-02-2014

10:00 12:00 14:00 16:008

9

10

11

12

13

Time

log(1+volume)

(b) Oct-03-2014

10:00 12:00 14:00 16:008

9

10

11

12

13

Time

log(1+volume)

(c) Oct-04-2014

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 6 / 28

Page 7: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

FDA

This provides a time-series of coefficients..

10 20 30 40 50 6012

13

14

15

16

17

Day

αi,0

10 20 30 40 50 60−1

−0.5

0

0.5

1

1.5

2

Day

αi,.

αi,1αi,2αi,3αi,4

FDA typically assumes that these are independent.. but there aremodifications that account for functional time-series.We will stick to the independent case.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 7 / 28

Page 8: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

fPCA

I The analog of Principal Component Anlysis (PCA) isfunctional PCA (fPCA)

I Define the covariance function

K (s, t) = cov (x(s) , x(t))

this is the analog of the covariance matrix of a multi-variatesequence of observations

I We aim to carry out the analog of diagonalizing a covariancematrix Σ

Σ = UᵀD U =M∑j=1

dj uj uᵀj with uᵀi uj = δij

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 8 / 28

Page 9: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

fPCA

I Mercer’s lemma states that if K (s, t) is continuous on D2,then there exists an orthonormal sequence of continuousfunctions {ψi (t), i = 1, . . . } (eignefunctions) such that

(Kψi )(t) = κi ψi (t),

where the kernel operator K acts on square-integrablefunctions f as follows

(K f )(t) =

∫DK (s, t) f (s) ds .

Moreover, the covariance function

K (s, t) =∞∑j=1

κj ψj(s)ψj(t) , with

∫Dψi (t)ψj(t) dt = δij

and∑∞

j=1 κj =∫D K (s, s) ds < +∞.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 9 / 28

Page 10: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

fPCA

I The Karhunen-Loeve expansion states that under theassumptions of Mercer’s lemma, we have

x(t) = µ(t) +∞∑j=1

√κj ξj ψj(t) ,

where,

ξj =1√κj

∫Dx(s)ψj(s) ds

is a random variable with

E[ξi ] = 0 and E[ξi ξj ] = δij , ∀i , j ∈ N ,

and the series converges uniformly on D w.r.t the L2 norm.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 10 / 28

Page 11: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

fPCA

I The eigenvalues κi can be interpreted as the variation of x(t)in the direction of ψi (t)

I We typically truncate the series to obtain a dimensionallyreduced approximation of x

x = µ+M∑j=1

√κj ξk ψk(t)

I But how to estimate the eigenfunctions and eigenvaluesfrom data?

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 11 / 28

Page 12: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

fPCA

I Let the sample mean function be denoted µ, i.e.,

µ(t) = 1n

n∑i=1

xi (t)

I The empirical approximation of K (s, t) is

K (s, t) = 1N

N∑i=1

(xi (s)− µ(s)) (xi (t)− µ(t)) .

I Mercer’s lemma then implies there exists an orthonormal basisof eigenfunctions ψj with eigenvalues κj such that

K (s, t) =∞∑j=1

κj ψj(s) ψj(t)

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 12 / 28

Page 13: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

fPCA

I Expand the (centered) observations and eigenfunctions ontothe basis functions

xi (t) =K∑

k=1

cikφj(t), and ψj(t) =K∑

k=1

bjkφj(t)

I Then one can show that

bj = W− 1

2u j

where u j solves the eigenproblem

(1NW

12 C

ᵀC W

12

)u j = κj u j

andWkl =< φk , φl > .

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 13 / 28

Page 14: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

Figure: INTL (2014) traded volume using 5 minute buckets.

0 2 4 6-1.5

-1

-0.5

0

0.5

1

Hour

log(1+Volume)

FPCA

FPCA 1FPCA 2FPCA 3

0 2 4 67

8

9

10

11

12

Hour

log(1+Volume)

FPCA 1 : 71.7%

0 2 4 67

8

9

10

11

12

Hour

log(1+

Volume)

FPCA 2 : 15.3%

0 2 4 67

8

9

10

11

12

Hour

log(1+

Volume)

FPCA 3 : 7.5%

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 14 / 28

Page 15: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

We assume a linear relationship between net order-flow andmidprice changes, thus for every trading day we perform theregression

∆Sn = b µn + εn ,

where

I ∆Sn = Snτ − S(n−1)τ is the change in midprice

I µn is net order-flow defined as the difference between thevolume of buy and sell MOs during the time interval[(n − 1)τ, nτ ], and

I εn is the error term (assumed normal)

I In the empirical analysis we choose τ = 5 min intervals.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 15 / 28

Page 16: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

50 100 150 200 2500

0.5

1

1.5

2x 10

-6

Trading Day of 2013

PermanentIm

pact

-2 -1 0 1 20

500

1000

1500

2000

2500

Net Order-Flow (×105)

Frequency

-0.1 -0.05 0 0.05 0.1-1

-0.5

0

0.5

1x 10

5

Price Change (∆S)

E[(µ+−

µ−

)|∆

S]

Figure: Order-Flow and effect on the drift of midprice of INTC.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 16 / 28

Page 17: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

I Assume that temporary price impact is linear in thetrading rate so that the execution price traders receive is

St = St − 12∆− k ν ,

I To estimate k we

I Take snapshots of the LOB every second,

I Determine the price per share for various volumes (by walkingthrough the LOB),

I Compute the difference between the price per share and thebest quote at that time,

I Perform a linear regression.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 17 / 28

Page 18: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

0 2 4 6

x 104

24.3

24.35

24.4

24.45

24.5

24.55

24.6

Volume

Price

0 1 2 3 4 5

x 104

0

0.005

0.01

0.015

0.02

0.025

0.03

Volume

Price

Impact

10 12 14 1610

-8

10-7

10-6

10-5

Time

Price

Impact(k)

Figure: Temporary price impact: INTC on Nov 1, 2013. (a) at 11:00am,(b) from 11:00am to 11:01am and (c) the entire day.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 18 / 28

Page 19: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

Table: Permanent and temporary price impact parameters for Nasdaqstocks, ADV of MOs, average midprice, σ volatility (hourly) of arithmeticprice changes, mean arrival (hourly) of MOs λ±, and average volume ofMOs E[η±]. Data are from Nasdaq 2013.

FARO SMH NTAP

mean stdev mean stdev mean stdev

ADV 23,914 14,954 233,609 148,580 1,209,628 642,376midprice 40.55 6.71 37.90 2.44 38.33 3.20

σ 0.151 0.077 0.067 0.039 0.078 0.045b 1.41E-04 9.61E-05 5.45E-06 4.20E-06 5.93E-06 2.31E-06k 1.86E-04 2.56E-04 8.49E-07 8.22E-07 3.09E-06 1.75E-06

b/k 1.02 0.83 7.43 6.24 2.04 0.77

λ+ 16.81 9.45 47.29 28.13 300.52 144.48E[η+] 103.56 21.16 377.05 118.05 308.45 53.09λ− 17.62 10.69 46.37 27.62 293.83 136.13

E[η−] 104.00 21.79 381.70 126.74 312.81 49.86

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 19 / 28

Page 20: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

I Temporary price impact

Sνt = Sνt − 12∆− a νt

I Price process is affected by order-flow from all agents, i.e.,permanent price impact

dSνt = b (µ+t− (νt + µ−

t))︸ ︷︷ ︸

net order-flow

dt + dMt

I Cash process is

X νt =

∫ t

0(Sνu − 1

2∆− a νu) νu du

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 20 / 28

Page 21: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-FlowI Agent aims to solve for

H(t, x , q, S ,µ) = supν∈A

Et,x,q,S,µ

[ terminal book-value︷ ︸︸ ︷X ν

T + (SνT − 12∆) qνT −

terminal inventory penalty︷ ︸︸ ︷α (qνT )2

− φσ2

∫T

t

(qνu )2du︸ ︷︷ ︸

running inventory penalty

]

I The DPP suggest that the value function should satisfy

0 = ∂tH + 12σ2∂SSH + L µH − φ q2

+ supν

{(S − 1

2∆− a ν)ν ∂xH

+ (S + b (µ+ − µ− − ν)) ∂SH − ν ∂qH}

subject to the terminal condition

H(T , x , q, S ,µ) = x + q (S − 12∆)− α q2

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 21 / 28

Page 22: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

PropositionSolving the DPE. The DPE admits the solution

H(t, x ,S ,µ, q) = x + q(S − 1

2∆)

+ h0(t, µ) + q h1(t, µ) + q2h2(t) , (1)

where

h2(t) = −√

k φζ eγ(T−t) − e−γ(T−t)

ζ eγ(T−t) − e−γ(T−t)− 1

2b , (2a)

h1(t,µ) = b

∫ T

t

(ζeγ(T−u) − e−γ(T−u)

ζeγ(T−t) − e−γ(T−t)

)Et,µ

[µ+u − µ−

u

]du , (2b)

h0(t,µ) =1

4k

∫ T

t

Et,µ

[h

21(t, µ

u)]du , (2c)

with the constants

γ =

√φ

k, and ζ =

α− 12b +√k φ

α− 12b −√k φ

. (2d)

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 22 / 28

Page 23: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

TheoremVerification. The candidate value function is indeed the solution to theoptimal control problem. Moreover, the optimal trading speed is given by

ν∗t = γζ eγ(T−t) + e−γ(T−t)

ζ eγ(T−t) − e−γ(T−t)Qν∗t

− b

2k

∫ T

t

(ζeγ(T−u) − e−γ(T−u)

ζeγ(T−t) − e−γ(T−t)

)E[µ+u − µ−

u | Fµt]du ,

(3)

is the admissible optimal control we seek, and Fµt denotes the natural filtration

generated by µ.

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 23 / 28

Page 24: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

I If the agent requires full liquidation

limα→∞

ν∗t = γcosh(γ (T − t))

sinh(γ (T − t))Qν∗t

− b

2k

∫ T

t

sinh(γ(T − u))

sinh(γ(T − t))E[µ+u − µ−

u |Fµt]du .

I And if running penalty is absent...

limφ→0

limα→∞

ν∗t =1

(T − t)Qν∗t −

b

2k

∫ T

t

(T − u)

(T − t)E[µ+u − µ−

u |Fµt]du .

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 24 / 28

Page 25: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

Simulation Study

I Assume that other market participants trades follow

dµ+t = −κ+ µ+t dt + η+1+N+

t−dN+

t ,

dµ−t = −κ− µ−t dt + η−1+N−

t−dN−t ,

whereI κ± ≥ 0 are the mean-reversion rates,

I N+t and N−t are independent homogeneous Poisson processes

with intensities λ+ and λ−, respectively,

I {η±1 , η±2 , . . . } are non-negative i.i.d. random variables with

distribution function F , with finite first moment, independentfrom all processes.

I In addition, we require κ± > λ± E[η±1 ] is ergodic

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 25 / 28

Page 26: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

I The solution to order-flow is

µ±s = e−κ±(s−t) µ±t +

∫ s

t

e−κ±(s−u) η±

1+N±u−

dN±u ,

so thatE[µ±s | Fµt ] = e−κ

±(s−t) (µ±t − ψ±)+ ψ± ,

where ψ± = 1κ± λ

± E[η±] .

I ψ± act as the expected long-run activity of buy and sell orders

I As a consequence, the optimal trading strategy is given by

limα→∞

ν∗t = γcosh(γ (T − t))

sinh(γ (T − t))Qν∗t

− b

2k

(∫ T

t

sinh(γ(T − u))

sinh(γ(T − t))e−κ(u−t) du

)(µ+

u − µ−u ) .

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 26 / 28

Page 27: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-Flow

Time (day)0 0.2 0.4 0.6 0.8 1N

etO

rder

-Flo

w(7

+ t!7! t) #105

-2

-1

0

1

2

Time (day)0 0.5 1

Tra

din

gSpee

d(8$ t)

-1000

0

1000

2000

3000

Time (day)0 0.2 0.4 0.6 0.8 1

Inve

nto

ry(Q

8$

t)

0

100

200

300

400

500

600

Time (day)0 0.5 1

Book-V

alue

#104

1.0155

1.016

1.0165

1.017

1.0175

1.018

1.0185

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 27 / 28

Page 28: Algorithmic Trading: Order-Flow - Sebastian Jaimungalsebastian.utstat.utoronto.ca/.../uploads/2017/11/RiO-Order-Flow.pdf · Algorithmic Trading: Order-Flow Sebastian Jaimungal University

Order-flow

Time0 0.5 1

Exce

ssBookva

lue

-2

0

2

4

6

0

0.02

0.04

0.06

0.08

0.1

Time0 0.5 1

Tra

din

gSpee

d(8$)

-1000

0

1000

2000

3000

0

0.02

0.04

0.06

0.08

0.1

0.12

Time0 0.5 1

Inve

nto

ry(Q

8$

)

0

100

200

300

400

500

0

0.1

0.2

0.3

Savings per Share (bp)-10 -5 0 5 10

Fre

q

0

200

400

600

800

1000

1200

(c) Cartea & Jaimungal, 2016 Algo Trading Nov, 2016 28 / 28