Optimal High Frequency Market Making
Optimal High Frequency Market Making
Abstract
The paper implements and analyzes the high frequency market making pricing
model by Avellaneda and Stoikov (2008). This pricing model is integrated with a
proprietary inventory control model that dynamically adjusts the order size to mitigate
inventory risk, the risk that we bear due to our inventory. Then, we develop a trading
simulator to assess the P&L and inventory of our optimal pricing strategy in com-
parison to a baseline pricing model for five representative stocks. With the inventory
model, the optimal pricing model outperforms the baseline in inventory management
while ensuring profitability.
Contents
1 Introduction 2
2.1 Pricing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Inventory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Trading Simulator 6
4 Experiments 7
4.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 Markov Chain Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5 Conclusions 12
References 13
1
1 Introduction
Market makers are critical providers of liquidity in markets as they constantly place bid and
ask orders in the limit order book such that any market order will always be capable of being
filled. The goal of the market maker is to strategically place these bids and asks to capture the
spread, the difference between the bid and ask price, while also earning a rebate for providing
liquidity. On the other hand, market making has become one of the prevailing strategies for
high-frequency traders who profit by turning over positions in an extremely short period.
These high-frequency traders play integral roles in providing liquidity to markets, accounting
for more than 50% of total volume in the US-listed equities (SEC, 2014).
Various pricing models for market making have been proposed in the academic literature. Ho
and Stoll (1981) is one of the early studies that analyze the market making problem under a
stochastic control framework. Avellaneda and Stoikov (2008) extends the model proposed by
Ho and Stoll (1981), derives the optimal bid and ask quotes using asymptotic expansion and
applies it to high-frequency market making. Furthermore, Guéant, Lehalle, and Fernandez-
Tapia (2013) develops the model further by deriving the closed form solution of the optimal
bid and ask spread with boundary conditions on inventory size.
In this paper, we implement the high frequency market making pricing model proposed
by Avellaneda and Stoikov (2008). We choose this model for the ease of implementation
and analysis, and unlike recent models such as Guéant et al. (2013), it does not restrict the
permissible inventory size. Although this unconstrained inventory assumption lets the market
maker to keep trading regardless of their position, it is a shortcoming since it increases the
likelihood of accumulating a one-sided position and getting exposed to inventory risk, the risk
that we bear due to inventory. To complement the pricing model, we develop an inventory
control model that dynamically adjusts the order size based on the current position. This
integrated approach allows us to effectively control inventory risk while ensuring profitability.
A trading simulator is devised to assess the P&L and inventory of our optimal pricing strategy
compared to a baseline pricing model for five representative stocks.
The rest of the paper is organized as follows: Section 2 describes the pricing model and
the inventory model, section 3 explains a trading simulator on which the strategy is tested,
section 4 discusses the experiment and results, while section 5 concludes.
2
2.1 Pricing
We use the optimal market making model developed by Avellaneda and Stoikov (2008) as our
bid and ask quote-setting strategy. The framework is based on a utility-maximizing market
maker trading in a limit order book. This section presents a brief summary of the model.
We are interested in maximizing our expected exponential utility given our profit and loss at
terminal time T . Assuming the risk-free rate is zero and the mid-price of a stock follows a
standard brownian motion dSt = σdWt with initial value S0 = s and standard deviation σ,
Avellaneda and Stoikov (2008) formulates the market maker problem as:
u(s, x, q, t) = max Et −e−γ(XT +qT ST )
δ a ,δ b
3
Then, this nonlinear partial differential equation is solved using an asymptotic expansion for
a small inventory q. This results in the pricing equations that are relevant to our algorithm:
(
r(s, t) = s − qγσ 2 (T − t) → Indifference price
δ a + δ b = γσ 2 (T − t) + ln 1 + κγ
→ Spread around r(s, t)
It is important to notice that, since Avellaneda and Stoikov (2008) defines T as the terminal
time in which the trader optimizes its expected utility, the spread equation can be seen as a
linear function of (T − t) given by:
a b 2
γ
δ + δ = γσ (T − t) + ln 1 +
|{z}
A
| {z κ }
B
where A is the slope of the spread equation
B is the closing spread when t = T
If γ > 0, the spread equation becomes a decreasing function of time. The rationale behind this
optimal strategy is that tighter optimal spread enables the market marker to liquidate their
position before the market closes so as to avoid overnight risk. To implement the framework
developed by Avellaneda and Stoikov (2008) we must compute our indifference price and set
an optimal spread around it given by these two equations. We exploit the linearity of the
spread equation and our market data in order to adjust our spread to the best bid-ask spread
dynamics. The calibration strategy is explained in detail in the Experiments section of the
paper.
2.2 Inventory
To complement the pricing model, we develop a proprietary dynamic order size framework.
Unlike the strategy followed by Guéant et al. (2013), who stops quoting if the inventory
reaches the maximum permissible level, we are able to keep trading and earning rebates by
adjusting the order size based on our current position. Our order size model is given by the
following equation:
( (
max
φ t if q t < 0 φmax
t if qt > 0
φbid
t = max −ηqt
φask
t = max −ηqt
φt · e if qt > 0 φt · e if qt < 0
where φbid ask
t , φt are the bid and ask order size at time t
max
φt is the maximum order size at time t
η is a shape parameter
We select the shape parameter η = −0.005 to obtain dynamic order size model shown in
Figure 1. As we will later see, this function is very effective at controlling inventory risk.
The main reasoning behind its mechanics is that the framework controls inventory risk by
placing smaller order sizes in the direction of excess position accumulation.
4
100
80
Buy 100 shares Sell 100 shares
60
Order Size
Sell at function Buy at function
40
20
Position
2.3 Algorithm
As a market maker, we are interested in implementing an algorithm that places bid and ask
quotes in the limit order book at all times. However, we are aware that in very brief periods,
we must hold one-sided quotes for the sake of profitability. This situation occurs when both
buy and sell orders are not filled at the same time interval.
Therefore, our strategy iterates as follows. During the trading day, we quote a bid and ask
spread if we have no orders in the limit order book. If only one of these orders is filled, we
wait for 5 seconds for the outstanding order to be executed. If this does not happen, then
we cancel the order and place new bid and ask quotes. Finally, whenever we have two orders
in the limit order book, we update our quotes every second. The summary of the trading
algorithm is shown in Algorithm 1.
5
3 Trading Simulator
We build a trading simulator to assess our strategy. The principal constituent of the simulator
is market order dynamics because as a market maker, we only use limit orders which are
matched and filled by market orders. Given this model, we can simulate order executions
and run our market making strategy. For simplicity, we make the following assumptions: 1)
No latency, 2) No price impact, and 3) No competition with other market makers.
Analogous to the market making model, the intensity function is assumed to be a product
of time and depth components in the following form:
λ(t, ξ) = αt e−µξ
A piece-wise linear bathtub shape is adopted for the time component αt based on the empirical
result of intraday volume pattern as discussed in Cartea, Jaimungal, and Penalva (2015). The
depth component e−µξ is a decreasing function of depth ξ since the deeper a quote is, the
less likely it is for the order to be executed due to the lower priority. Figure 3 illustrates the
shape of these two components respectively.
6
3.2 Order Execution
The market order dynamics enables us to simulate an order execution as follow. At time
t, we generate a Bernoulli random number X ∼ Ber(λ(t, ξ)∆) with the depth of a limit
order ξ and time interval ∆. Then, X = 1 indicates the arrival of a market order and we
assume that the order is executed. To make the experiment more realistic, we also allow an
order to be partially filled by generating another random number from Gamma distribution
Y ∼ Gamma(κ, θ). Then, Y is multiplied by our order size to compute the executed order
size. For instance, Y ≥ 1 implies a full execution, while Y < 1 means a partial fill.
4 Experiments
We choose the week of June 12, 2017 to simulate our strategy, and trade from 9:30am - 4pm
each day. As the market maker may deal with a wide variety of stocks, we choose the S&P500
as a baseline and then four stocks to represent combinations of high and low volume as well
as high and low performance as shown in Table 1. With the technique described in section
2.1, the parameters are calibrated using the average of the opening and closing spreads from
each stock in the previous week. The data is retrieved from a simulator provided by Thesys
Technologies, and the time interval ∆ is set to 1 second. The maximum order size φmax t is
set to 100. The parameters of the simulator are set as µ = 100, κ = 2, θ = 1/1.65.
To assess the performance of the optimal strategy in section 2, we consider a baseline pricing
strategy in which the market maker always quotes at the best bid and ask prices that are
currently placed in the order book. Every other aspect of the baseline strategy remains
identical to the optimal strategy. Then, a Markov Chain model is used to further examine
probabilities that help measure performance of these strategies.
4.1 Results
Our primary interest is the profitability and the inventory management of the strategies.
Table 2 shows the average terminal P&L and position (inventory) of both strategies. The
optimal strategy achieves higher profits in AAPL and AMZN and comparable profits in
the rest of stocks, compared with the baseline strategy. Also, both strategies end each
trading day with a small position on average, indicating the success of inventory management.
Furthermore, the optimal strategy accomplishes the variance reduction of profits and position
per day as shown in Table 3. Not only does the optimal strategy reduce the terminal position,
but it also manages the inventory during a trading session while consistently making profits.
7
Table 2: Average terminal P&L and position
Optimal Baseline
P&L Position P&L Position
AAPL -1,378.01 -29.0 -1,625.25 -45.6
AMZN 58,331.04 8.4 13,522.2 -34.6
GE 703.12 -49.2 708.48 -38.4
IVV 217.58 -41.8 547.52 -36.8
M 534.04 -46.0 587.09 23.8
Table 3: The mean and standard deviation of profits and position per day
Figure 3 demonstrates the market and optimal spreads for AAPL and GE on June 12, 2017.
Note that the spreads are rounded to the nearest cent. As discussed in section 2, the spread
of the optimal pricing model is a linear function of time. At the beginning, the optimal
spread is wider than the market spread. Later in the trading day, around 2pm, there is a
turning point when the optimal spread becomes narrower than the market spread, meaning
that more orders are likely to be filled. This aggressiveness helps unwind the accumulated
position before the market closes and boost our profits if spreads are large enough.
8
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
Figure 4: AAPL
Figure 4 displays P&L and inventory size for APPL on each day in both strategies. Though
we observe the poorest performance overall on AAPL, we observe that the inventory size is
centered around 0. For the optimal strategy, the position remains between ±200 and the
density has sharper peak than that of the baseline strategy, which suggests more control of
inventory risk. In contrast to AAPL, for GE, P&L consistently increases over time. The same
trend of profits is observed in the baseline strategy, but the variance of profits is lower in
the optimal strategy. As is the case of AAPL, the optimal strategy outperforms the baseline
strategy in terms of controlling the inventory size.
We also compute the average number of buy and sell orders executed, shares bought and sold,
and quotes per day as shown in Table 4 and 5. For both strategies, the number of buy and
sell orders, as well as the number of shares bought and sold are well balanced, indicating that
the position stays around 0. In terms of quoting, the baseline strategy updates and posts
prices more frequently than the optimal strategy. However, the optimal strategy quotes more
efficiently because it has more buy (sell) orders executed per quote than the baseline strategy.
9
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
Figure 5: GE
Table 4: The average number of orders, shares, and quotes per day in the optimal strategy
Table 5: The average number of orders, shares, and quotes per day in the baseline strategy
10
4.2 Markov Chain Analysis
We apply a Markov Chain model to compute the probabilities that measure the performance
of strategies. Let us assume that the state space S consists of {0, 1, 2} = {Quoting, W aiting, Spread}
as depicted in Figure 6. Quoting means bid and ask prices are quoted, W aiting means one
of the orders is filled and the market maker is waiting for the outstanding order to be filled,
and Spread means both buy and sell orders are filled and the spread is captured. Note that
the transition probability from Spread to Quoting is 1, and there is no arrow from Spread
to W aiting because after making the spread, the market maker always quotes new bid and
ask prices. Table 6 summarizes the interpretation of each transition probability.
p(1, 0)
1 p(1, 2)
p(0, 2)
Spread
A quantity of interest for market makers is the probability of capturing the spread since it
is the main source of profit in the business. There are two scenarios in which the market
maker can capture the spread in each quote. The first case is that both buy and sell orders
are filled within the next time interval. The other case is that one of the order is filled, and
after 5 waiting periods, the outstanding order is filled. Therefore, the probability of making
the spread is
5
X
p? = p(0, 2) + p(0, 1)p(1, 1)n p(1, 2).
n=0
11
Another quantity of interest would be the probability of one-sided fill, which is the case where
only buy or sell is filled and the remaining order is cancelled after the waiting time. The
higher likelihood of one-side fill increases the inventory risk since the fill is imbalanced. The
probability of one-side fill after 5 waiting periods is defined as
The estimated probabilities are summarized in Table 7 and 8. The baseline strategy has
higher probability of making the spread than the optimal strategy because the baseline
strategy always quotes at the best bid and ask prices, which tend to be more aggressive than
the optimal prices. Yet, it is important to note that the higher probability of making the
spread may not always be indicative of the higher profit as it also depends on the size of
spreads. The optimal strategy, on the other hand, achieves lower probability of one-side fill.
This finding demonstrates that the optimal strategy can quote more efficiently and prevent
the position from accumulating.
5 Conclusions
In this project, we implement the high frequency market making pricing strategy proposed
by Avellaneda and Stoikov (2008). The inventory strategy that mitigates the inventory risk is
proposed to complement the pricing model. Furthermore, we develop the trading simulator to
experiment with our strategy on real high frequency data. With the inventory control model,
the optimal pricing model achieves more controlled inventory size while ensuring profitability.
A possible extension of our strategy can be to use a model to predict mid price and market
order arrivals so that the market makers can profit regardless of the market movement and
the size of spreads.
12
References
Avellaneda, M., & Stoikov, S. (2008). High-frequency trading in a limit order book.
Quantitative Finance, 8 (3), 217-224. Retrieved from https://doi.org/10.1080/
14697680701381228
Cartea, A., Jaimungal, S., & Penalva, J. (2015). Algorithmic and high-frequency trading.
Cambridge, United Kingdom: Cambridge University Press.
Guéant, O., Lehalle, C.-A., & Fernandez-Tapia, J. (2013). Dealing with the inventory risk: a
solution to the market making problem. Mathematics and Financial Economics, 7 (4),
477–507. Retrieved from https://doi.org/10.1007/s11579-012-0087-0
Ho, T., & Stoll, H. R. (1981). Optimal dealer pricing under transactions and return uncer-
tainty. Journal of Financial Economics, 9 , 47–73.
U.S. Securities and Exchange Commission. (2014). Equity Market Structure Literature Re-
view, Part II: High Frequency Trading.
13
Appendix: Results for All Stocks
Optimal Strategy on June 12, 2017
Figure 7: AAPL
Figure 8: AMZN
14
(a) P&L (b) Position
Figure 9: GE
15
(a) P&L (b) Position
Figure 11: M
16
Results for the Complete Week: Optimal and Baseline
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
17
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
Figure 14: GE
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
18
(a) Cumulative P&L in the optimal strategy (b) Cumulative P&L in the baseline strategy
(c) The density of inventory size in the optimal strategy (d) The density of inventory size in the baseline strategy
Figure 16: M
19