What does Order Books, Hawkes Processes and Toxic Flow conclude, in numbers, about “Inventory Risk and Optimal Market Making: the Avellaneda–Stoikov Equations”?
Answer: The Avellaneda–Stoikov reservation price \(s - q\gamma\sigma^2(T-t)\) and total-spread formula check out, but the spread formula depends on exponential arrival intensities, an expansion in inventory and a first-order approximation of the order-arrival term. The exact solution of Guéant and co-authors shows that optimal quotes hardly depend on time away from the horizon; with the paper's parameters and one unit of time remaining, the approximation already overstates the reservation-price shift at inventory 1 about eightfold (−0.400 against −0.052). Re-running the paper's simulation gives results close to the paper's; quoting by the exact solution raises mean profit at \(\gamma = 1\) from 31.2 to 63.9. There is no adverse selection in the model, which is the starting point of the experiment designed in Chapter 8.
Scope of the numbers: Why does a market maker quote a spread? Why do orders arrive in clusters? Can "toxic" order flow be measured from trade data? This book presents mathematical models for teaching and research and is not investment or trading advice. Marked boxes separate published evidence, runnable Python calculations (16 programs), classical sources and the author's models and hypotheses; all data in the book are fictional or simulated.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 31.2, 63.9
| gamma | strategy | mean spread | profit | sd(profit) | final q | sd(q) | profit/sd |
|---|---|---|---|---|---|---|---|
| 0.01 | inventory | 1.35 | 68.6 | 9.3 | -0.03 | 5.3 | 7.4 |
| 0.01 | symmetric | 1.35 | 69.2 | 14.5 | +0.07 | 9.0 | 4.8 |
| 0.01 | exact ODE | 1.34 | 68.8 | 10.2 | +0.01 | 5.6 | 6.8 |
| 0.1 | inventory | 1.49 | 64.8 | 6.5 | +0.07 | 2.9 | 9.9 |
| 0.1 | symmetric | 1.49 | 68.6 | 14.3 | +0.01 | 8.8 | 4.8 |
| 0.1 | exact ODE | 1.34 | 67.9 | 7.3 | +0.04 | 3.0 | 9.2 |
| 1.0 | inventory | 3.03 | 31.2 | 4.8 | -0.03 | 1.6 | 6.5 |
| 1.0 | symmetric | 3.03 | 44.0 | 10.8 | -0.07 | 5.2 | 4.1 |
| 1.0 | exact ODE | 1.21 | 63.9 | 5.6 | -0.02 | 1.6 | 11.4 |
Key formula
Show the full program
# Re-running the simulation design of Avellaneda & Stoikov (2008): s0 = 100, T = 1,
# sigma = 2, dt = 0.005, A = 140, k = 1.5; the mid moves +-sigma sqrt(dt) each step, a
# quote at distance delta is filled with probability A exp(-k delta) dt. Strategies:
# inventory - AS quotes around the reservation price s - q g sig^2 (T - t)
# symmetric - quotes symmetric about the mid; spread = inventory strategy's mean spread
# exact - quotes from the exact ODE solution (Gueant et al. 2013, |q| <= 30)
# 1,000 sessions per row, common random numbers across strategies within a session.
import math, random, statistics
S0, T, SIG, DT, A, K = 100.0, 1.0, 2.0, 0.005, 140.0, 1.5
NSTEP = round(T / DT)
def exact_table(g, Q=30, sub=25):
a = K * g * SIG ** 2 / 2; eta = A * (1 + g / K) ** -(1 + K / g)
c = math.log(1 + g / K) / g; h = DT / sub; v = [1.0] * (2 * Q + 1); tab = [None]
def f(w):
return [-a * (i - Q) ** 2 * w[i] + eta * ((w[i - 1] if i else 0.0)
+ (w[i + 1] if i < 2 * Q else 0.0)) for i in range(2 * Q + 1)]
for _ in range(NSTEP): # tab[j]: tau = j * DT
for _ in range(sub):
k1 = f(v); k2 = f([x + h / 2 * y for x, y in zip(v, k1)])
k3 = f([x + h / 2 * y for x, y in zip(v, k2)])
k4 = f([x + h * y for x, y in zip(v, k3)])
v = [x + h / 6 * (p + 2 * q + 2 * r + s)
for x, p, q, r, s in zip(v, k1, k2, k3, k4)]
m = max(v); v = [x / m for x in v]
tab.append({q: (math.log(v[q + Q] / v[q + Q + 1]) / K + c if q < Q else 99.0,
math.log(v[q + Q] / v[q + Q - 1]) / K + c if q > -Q else 99.0)
for q in range(-Q, Q + 1)})
return tab
def run(g, kind, seed, half=None, tab=None):
rng = random.Random(seed); s, x, q, spreads = S0, 0.0, 0, []
for j in range(NSTEP):
tau = T - j * DT
if kind == "inventory":
r = s - q * g * SIG ** 2 * tau
sp = g * SIG ** 2 * tau + 2 / g * math.log(1 + g / K)
bid, ask = r - sp / 2, r + sp / 2
elif kind == "symmetric":
bid, ask = s - half, s + half
else:
db, da = tab[NSTEP - j][max(-30, min(30, q))]
bid, ask = s - db, s + da
spreads.append(ask - bid)
u1, u2, u3 = rng.random(), rng.random(), rng.random()
if u1 < A * math.exp(-K * (ask - s)) * DT:
q -= 1; x += ask
if u2 < A * math.exp(-K * (s - bid)) * DT:
q += 1; x -= bid
s += SIG * math.sqrt(DT) * (1 if u3 < 0.5 else -1)
return x + q * s, q, statistics.fmean(spreads)
if __name__ == "__main__":
print("gamma strategy mean spread profit sd(profit) final q sd(q) profit/sd")
for g in (0.01, 0.1, 1.0):
inv = [run(g, "inventory", sd) for sd in range(1000)]
half = statistics.fmean(r[2] for r in inv) / 2; tab = exact_table(g)
rows = {"inventory": inv,
"symmetric": [run(g, "symmetric", sd, half=half) for sd in range(1000)],
"exact ODE": [run(g, "exact", sd, tab=tab) for sd in range(1000)]}
for name, rs in rows.items():
p = [r[0] for r in rs]; qq = [r[1] for r in rs]
m, sd = statistics.fmean(p), statistics.stdev(p)
print(f" {g:<5} {name:10s} {statistics.fmean(r[2] for r in rs):6.2f} "
f" {m:6.1f} {sd:6.1f} {statistics.fmean(qq):+6.2f}"
f" {statistics.stdev(qq):5.1f} {m / sd:6.1f}")Single source and citation
Fan, Y. (2026). High-Frequency Limit Order Book Microstructure, Hawkes Self-Exciting Point Processes and Adverse-Selection Flow Toxicity (Version 1.0.0), Chapter 2: Inventory Risk and Optimal Market Making: the Avellaneda–Stoikov Equations. 5D Library. https://doi.org/10.5281/zenodo.23828065
DOI: 10.5281/zenodo.23828065 · Read the monograph · 5DL-B-045 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026045,
author = {Fan, Yafu},
title = {High-Frequency Limit Order Book Microstructure, Hawkes Self-Exciting Point Processes and Adverse-Selection Flow Toxicity},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
doi = {10.5281/zenodo.23828065},
url = {https://doi.org/10.5281/zenodo.23828065}
}Other chapter answers in this book
- Chapter 1 · Information Asymmetry and the Bid–Ask Spread: Glosten–Milgrom and Kyle
- Chapter 3 · Why Orders Arrive in Clusters: Hawkes Processes, the Signature Plot and the Epps Effect
- Chapter 4 · Measuring Toxicity: the Probability of Informed Trading, VPIN and the Flash-Crash Dispute
- Chapter 5 · Book Imbalance and Queues: Order Flow Imbalance, Queue Imbalance and Queue Position
- Chapter 6 · How to Split a Large Order: Almgren–Chriss Optimal Execution
- Chapter 7 · Reading the Classics: the Market Director, the Conspicuous Mound and the Market Exchange
- Chapter 8 · Practice and a Pre-Registered Test