*In this article series Imanol Pérez, a PhD researcher in Mathematics at Oxford University, and an expert guest contributor to QuantStart outlines the basics of high-frequency trading. In this article Imanol uses the theory of stochastic optimal control to optimally execute a large trade order.*

It is well known that when a large order is trying to be executed—either a sell or buy order—the market price is affected. If the order is a large sell order, the price will be dragged down, while large buy orders will increase it. After analysing in our first two articles how market microstructure works, the reason becomes quite clear: large market orders won't be filled by the limit orders placed at the best price, and when these limit orders are filled, the market order will *walk the book*, therefore affecting the price of the share.

In this article we will study how we can optimally buy or sell a large amount of shares of a particular stock. This should be carried out by splitting the *parent order* into separate pieces called *child orders*. One should split the parent order considering the trade-off between fast execution, which has negative impact on the stock price, and slow execution, which will leave the trader exposed to market risk. We will see that writing the problem as a stochastic optimal control problem will allow us to come up with a satisfactory answer to the problem.

## Defining our model

We will begin by defining our model. For now, we will assume that the trader wants to execute a given inventory. The inverse problem—the one where the trader wants to *acquire* a large number of shares—can be solved in a similar way.

- $\nu$ will be the trading speed. This is the variable the trader can control, and the objective is to select it in an optimal way.
- $Q^\nu$ is the inventory of the trader, which depends on the trading speed. More specifically, it will be given by $$\begin{cases}dQ_t^\nu = - \nu_t dt,\\ Q_0^\nu = q\end{cases}$$ where $q$ denotes the initial inventory of the trader.
- $S^\nu$ is the midprice of the stock. It is also going to depend on the trading speed $\nu$, since a fast speed will negatively affect the price, as discussed. We will assume that it has the following dynamics: $$\begin{cases}dS_t^\nu = \sigma dW_t\\S_0^\nu = S\end{cases}$$ with $W$ a standard Brownian motion.
- $\hat{S}^\nu$ will denote the price at which the agent can sell the asset—the execution price, after possibly walking the Limit Order Book. It will be given by $$\hat{S}_t^\nu = S_t^\nu - \left (\frac{1}{2}\Delta + k \nu_t\right )$$ with $k>0$ is some parameter and $\Delta$ is the bid-ask spread, which will be assumed to be non-negative.
- $X^\nu$ is the amount of cash the trader has, after executing the initial inventory at the speed $\nu$.

## Finding the optimal liquidation speed

Let $\mathcal{A}$ be the set of all predictable non-negative bounded processes. This will be our set of admissible strategies—that is, the liquidation speed $\nu$ will have to be picked from $\mathcal{A}$. Suppose that we want to liquidate a portfolio of $\mathcal{P}$ shares by a terminal time $T$. Then, our objective will be to minimise the following expectation:

$$\mathbb{E}_{t, S, q} \left [\int_t^T \hat{S}_u^\nu \nu_u du + (\mathcal{P}-Q_T^\nu) S_T+ \alpha (\mathcal{P}-Q_T^\nu)^2\right ],$$ over all possible strategies $\nu \in \mathcal{A}$, and where $\alpha>0$. That is, we would like to find the *value function*

$$H(t,S,q)=\inf_{\nu\in \mathcal{A}}\mathbb{E}_{t, S, q} \left [\int_t^T \hat{S}_u^\nu \nu_u du + (\mathcal{P}-Q_T^\nu) S_T + \alpha (\mathcal{P}-Q_T^\nu)^2\right ].$$

The first term inside the expectation represents the amount of cash we obtain by following some strategy $\nu$. The second term, on the other hand, indicates that the trader must execute all the shares that were not liquidated at time $T$. Finally, the third term is a terminal penalty, where we penalise not liquidating all shares by time $T$.

Without going into details, one can use the Hamilton-Jacobi-Bellman equation to deduce that the value function $H$ must satsify the following Partial Differential Equation:

$$\begin{cases}\partial_t H + \frac{1}{2}\sigma^2\partial_{SS}H + \inf_{\nu\in \mathcal{A}} \{(S+k\nu)\nu - \nu \partial_q H\}\\H(T,S,q)=(\mathcal{P}-q)S+\alpha (\mathcal{P}-q)^2\end{cases}.$$

One could show using the PDE (see [1] for details) that the optimal liquidation speed is given by

$$\nu_t^\ast = \dfrac{\mathcal{P}}{T+\frac{k}{\alpha}}.$$

As we see, stochastic analysis provides an excellent tool to exploit how market microstructure works in order to come up with strategies for the optimal execution problem.

## Article Series

- High Frequency Trading I: Introduction to Market Microstructure
- High Frequency Trading II: Limit Order Book
- High Frequency Trading III: Optimal Execution