You are on page 1of 21

Mathematics and Statistics of Algorithmic

Trading
University of Oxford

Álvaro Cartea
alvaro.cartea@maths.ox.ac.uk
http://www.cartea.net

January 14, 2020

1 / 21
Optimal Execution

I How do we trade in or out of a large position?


I Optimal Execution with Temporary Impact and Inventory Control
I Liquidation
I Acquisition
I Optimal Liquidation with Temporary and Permanent Impact and
Inventory Control
Notes based on textbook “Algorithmic and High-Frequency Trading”
with S. Jaimungal and J. Penalva.

2 / 21
Model Setup

I ν = (νt ){0≤t≤T } is the trading rate, the speed at which the agent is
liquidating or acquiring shares. It is also the variable the agent
controls in the optimisation problem,
I Q ν = (Qtν ){0≤t≤T } is the agent’s inventory, which is clearly affected
by how fast she trades,
I S ν = (Stν ){0≤t≤T } is the midprice process, and is also affected in
principle by the speed of her trading,
I Ŝ ν = (Ŝtν ){0≤t≤T } corresponds to the price process at which the
agent can sell or purchase the asset, i.e. the execution price, by
walking the LOB , and
I X ν = (Xtν ){0≤t≤T } is the agent’s cash process resulting from the
agent’s execution strategy.

3 / 21
Model Setup

dQtν = ±νt dt , Q0ν = q , (1a)

while the midprice is assumed to satisfy the following SDE,

dStν = ±g (νt ) dt + σ dWt , S0ν = S , (1b)

where
I W = (Wt ){0≤t≤T } is a standard Brownian motion,

I g : R+ → R+ denotes the permanent impact that the agent’s


trading action incurs on the midprice.
The execution price satisfies the SDE

Ŝtν = Stν ± 21 ∆ + f (νt ) , Ŝ0ν = Ŝ ,



(1c)

where
I f : R+ → R+ denotes the temporary impact that the agent’s trading
action has on the price they can execute the trade at.
I ∆ ≥ 0 is the bid-ask spread, assumed here to be a constant.
4 / 21
SMH on Oct 1, 2013
SMH on Oct 1, 2013 0.04
at 10:59:59.960
40.45

Price Impact
0.03
40.4
40.35
Price

0.02
40.3
40.25 0.01
40.2
0
0 0.5 1 1.5 2 0 0.5 1 1.5 2
Volume x 10
4 Volume 4
x 10
-4
0.04 10
Mean Impact
Linear Regression

Price Impact
Price Impact

0.03 -5
10

0.02
-6
10
0.01

-7
0 10
0 0.5 1 1.5 2 10 12 14 16
Volume 4
x 10 Time

5 / 21
Optimal Liquidation with Temporary Impact

6 / 21
Liquidation
hR i
T
H(t, S, q) = sup Et,S,q t
(Su − k νu ) νu du ,
ν∈A

where Et,S,q [ · ] denotes expectation conditional on St = S and Qt = q,


and A is the set of admissible strategies.

Assume f (ν) = k ν, and g (ν) = 0, i.e. only temporary price impact


(walking the LOB).

Use the DPP which suggests that H satisfies the DPE

∂t H + 12 σ 2 ∂SS H + sup {(S − k ν) ν − ν ∂q H} = 0 . (2)


ν

The agent must liquidate all the inventory by time T , hence impose
t→T t→T
H(T , S, q) −−−→ −∞, for q > 0, and H(T , S, 0) −−−→ 0 .

7 / 21
Liquidation
The FOC applied to DPE (12):

ν∗ = 1
2k (S − ∂q H) , (3)

which is the optimal trading speed in feedback control form. Now


2
∂t H + 1
2 σ 2 ∂SS H + 1
4k (S − ∂q H) = 0 (4)

for the value function. Propose ansatz (trial solution)

H(t, q) = q S + h(t, q) , (5)

where h(t, q) is still to be determined, though we know that it must blow


up as t → T .
Thus
1 2
∂t h + 4k (∂q h) = 0 .
Interestingly, the volatility of the asset’s midprice drops out of the
problem.
8 / 21
Again, make ansatz h(t, q) = q 2 h2 (t) allows us to factor out q and
obtain
∂t h2 + k1 h22 = 0 , (6)
which we solve by integrating between t and T to obtain
 −1
1 1
h2 (t) = − (T − t) .
h2 (T ) k

The optimal strategy must ensure that the terminal inventory is zero and
this is equivalent to requiring h2 (T ) → −∞ as t → T . In this way the
value function heavily penalises non-zero final inventory. An alternative
way to obtain this condition is to calculate the inventory path along the
optimal strategy and impose that the terminal inventory be zero. To see
this, use the ansatz (5) to reduce (3) to

νt∗ = − k1 h2 (t) Qtν , (7)

9 / 21

then integrate dQtν = −νt∗ dt over [0, t] to obtain the inventory profile
along the optimal strategy:
t ∗ t
dQtν (T − t) − k/h2 (T )
Z Z
h2 (s) ∗
∗ = ds ⇒ Qtν = N.
0 Qtν 0 k T − k/h2 (T )

To satisfy the terminal inventory condition QTν = 0, and also ensure that
the correction h(t, q) is negative, we must have

h2 (t) → −∞ as t → T . (8)

Hence
h2 (t) = −k (T − t)−1 ,
so that

 t
Qtν = 1 − N, (9)
T
and
N
νt∗ = . (10)
T
The result is TWAP.

10 / 21
Optimal Acquisition with Temporary Impact

11 / 21
Acquisition

Objective is to acquire N shares by time T .


Thus, the agent’s expected costs from strategy νt are
hR i
T
EC ν = E t Ŝt νu du + (N − QTν ) ST + α (N − QTν )2 . (11)
| {z } | {z } | {z }
Terminal Cash Terminal execution at mid Terminal Penalty

To simplify notation, let Y = (Yt )0≤t≤T denote the shares remaining to


be purchased:

Ytν = N − Qtν , so that dYtν = −νt dt ,

and write the value function as


hR i
T 2
H(t, S, y ) = inf Et,S,y t Ŝu νu du + YTν ST + α (YTν ) .
ν∈A

12 / 21
Applying the DPP, H satisfies the DPE

0 = ∂t H + 21 σ 2 ∂SS H + inf {(S + kν) ν − ν∂y H} , (12)


ν

with H(T , S, y ) = y S + α y 2 . Optimal speed:

ν∗ = 1
2k (∂y H − S) , (13)

and upon substitution into the DPE above, we obtain


2
∂t H + 12 σ 2 ∂SS H − 1
4k (∂y H − S) = 0 .

Make ansatz

H(t, S, y ) = y S + h0 (t) + h1 (t) y + h2 (t) y 2 , (14)

where h2 (t), h1 (t), h0 (t) and

h2 (T ) = α and h1 (T ) = h0 (T ) = 0 .

13 / 21
Moreover, upon substituting the ansatz into the above non-linear PDE
we find that

0 = ∂t h2 − k1 h22 y 2 + ∂t h1 − 2k
1 1 2
  
h2 h1 y + ∂t h0 − 4k h1 .

I Equation must be valid for each y , so each term in curly braces


must individually vanish.
I Due to h1 (T ) = 0, we obtain h1 (t) = 0.
I Similarly, since h0 (T ) = 0 and h1 (t) = 0 we obtain h0 (t) = 0.
I Finally, because h2 (T ) = α we have

1 1 −1

h2 (t) = k (T − t) + α .

Thus, the optimal speed is


k −1 ∗
νt∗ = (T − t) + Ytν .

α (15)

14 / 21
Inventory path
We obtain the optimal inventory path by solving

k −1 ∗
dYtν = − (T − t) + Ytν dt

α

for Ytν . Recall that Ytν = N − Qtν , so
∗ t
Qtν = k
N. (16)
T+ α

I For any finite α > 0 and finite k > 0,


I it is always optimal to leave some shares to be executed at the
terminal date, and
I the fraction of shares left to execute at the end decreases with the
relative price impact at the terminal date, k/α.

Substitute for Qtν into the expression for νt∗ , so that

N
νt∗ = k
. (17)
T+ α

15 / 21
Optimal Liquidation with Temporary and
Permanent Price Impact

16 / 21
Liquidation with Permanent Price Impact

The agent’s performance criterion is


h RT i
H ν (t, x, S, q) = Et,x,S,q XTν + QTν (STν − α QTν ) − φ t (Quν )2 du
|{z} | {z } | {z }
Terminal Cash Terminal Execution Inventory Penalty
(18)
and the value function

H(t, x, S, q) = sup H ν (t, x, S, q) .


ν∈A

The DPP implies that the value function should satisfy the HJB equation

0 = ∂t + 21 σ 2 ∂SS H − φ q 2


+ sup {(ν (S − f (ν)) ∂ − g (ν) ∂ − ν ∂ ) H} , (19)


x S q
ν

subject to the terminal condition H(T , x, S, q) = x + S q − α q 2 .

17 / 21
Assume that f (ν) = k ν and g (ν) = b ν for constants k ≥ 0 and b ≥ 0
and obtain
(S ∂x − b ∂S − ∂q )H
ν ∗ = 21k . (20)
∂x H
Hence
2
[(S ∂x − b ∂S − ∂q )H]
0 = ∂t + 21 σ 2 ∂SS H − φ q 2 + 1

4k .
∂x H
Make ansatz H(t, x, S, q) = x + S q + h(t, S, q) with terminal condition
h(T , S, q) = −α q 2 . Hence
2
0 = ∂t + 21 σ 2 ∂SS h − φ q 2 + 1

4k [b (q + ∂S h) + ∂q h] .

18 / 21
Since the above PDE contains no explicit dependence on S and the
terminal condition is independent of S, then ∂S h(t, S, q) = 0 and
2
0 = ∂t h(t, q) − φ q 2 + 1
4k [b q + ∂q h(t, q)] .
Use separation of variables h(t, q) = h2 (t) q 2 where h2 (t) to write
2
0 = ∂t h2 − φ + k1 h2 + 12 b ,

(21)
subject to h2 (T ) = −α. This ODE is of Riccati type and can be
integrated exactly. Let h2 (t) = − 21 b + χ(t), then
∂t χ 1
2
= ,
kφ − χ k
s.t. χ(T ) = 12 b − α. Next, integrating over [t, T ]
√ √
k φ + χ(T ) k φ + χ(t)
log √ − log √ = 2γ (T − t) ,
k φ − χ(T ) k φ − χ(t)
so that
p 1 + ζ e 2γ (T −t)
χ(t) = kφ ,
1 − ζ e 2γ(T −t)
where r √
φ α − 12 b + k φ
γ= and ζ = √ . (22)
k α − 12 b − k φ
19 / 21
From (20), the optimal speed to trade at is
r
∗ φ 1 + ζ e 2γ (T −t) ν ∗
νt = − Q . (23)
k 1 − ζ e 2γ(T −t) t
In addition
Z t 
∗ χ(t) ν ∗ ∗ χ(s)
dQtν = Qt dt , so that Qtν = N exp ds .
k 0 k
To obtain the inventory process
Z t
1 t p 1 + ζe 2γ(T −s)
Z
χ(s)
ds = kφ ds
0 k k 0 1 − ζe 2γ(T −s)
ζ e γ(T −t) − e −γ(T −t)
= log ,
ζ e γT − e −γT
hence
∗ ζ e γ(T −t) − e −γ(T −t)
Qtν = N. (24)
ζ e γT − e −γT
In the limit α → +∞
∗ sinh (γ(T − t))
Qtν −−−−−→ N,
α→+∞ sinh (γT )
which is independent of b.
20 / 21
1 10
φ=0 φ=0
φ = 0.001 φ = 0.001
0.8 φ = 0.01 8 φ = 0.01

Trading Speed
φ = 0.1 φ = 0.1

Inventory
0.6 6

0.4 4

0.2 2

0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Time Time

(a) α = 0.01

1 12
φ=0 φ=0
φ = 0.001 φ = 0.001
0.8 φ = 0.01 10 φ = 0.01

Trading Speed
φ = 0.1 φ = 0.1
Inventory

8
0.6
6
0.4
4
0.2 2

0 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Time Time

(b) α = +∞
Figure : Other model parameters are k = 10−3 , b = 10−3 .

21 / 21

You might also like