Note
Go to the end to download the full example code or to run this example in your browser via JupyterLite.
Avellaneda and Stoikov: market making in a limit order book#
Marco Avellaneda and Sasha Stoikov (2008) let a market maker quote around a Brownian mid price \(s\), with fills arriving at rate \(A e^{-k\delta}\) at distance \(\delta\). A trader with exponential utility first computes the reservation price \(r = s - q\gamma\sigma^2(T - t)\), the mid price adjusted for its inventory \(q\), and then quotes a spread \(\gamma\sigma^2(T-t) + \frac{2}{\gamma}\ln(1 + \gamma/k)\) around it. The example reproduces the comparison of their Table 1: the inventory strategy gives up a little expected profit for a much smaller variance.
import matplotlib.pyplot as plt
import numpy as np
from financialkit.market_microstructure import AvellanedaStoikov, SymmetricQuotes, simulate_market_making
from financialkit.market_microstructure.visualizers import plot_market_making
s0, sigma, T, n_steps, A, k = 100.0, 2.0, 1.0, 200, 140.0, 1.5
One trading session#

Text(0.5, 1.0, 'inventory strategy, gamma = 0.1: profit 66.3')
Inventory against symmetric quoting#
The symmetric strategy quotes the same average spread centred on the mid price. Paper values for \(\gamma = 0.1\): profit 62.94 (sd 5.89) against 67.21 (sd 13.43).
print(f"{'gamma':>6s} {'strategy':>10s} {'spread':>7s} {'profit':>7s} {'sd':>6s} {'q(T)':>6s} {'sd q':>6s}")
for g in (0.01, 0.1, 0.5):
inv = simulate_market_making(AvellanedaStoikov(g, sigma, k, T), s0, sigma, T, n_steps, A, k, n_paths=1000, rng=6)
half = float(np.mean(inv.ask - inv.bid)) / 2
sym = simulate_market_making(SymmetricQuotes(half), s0, sigma, T, n_steps, A, k, n_paths=1000, rng=6)
for name, r in [("inventory", inv), ("symmetric", sym)]:
q = r.inventory[:, -1]
print(f"{g:6.2f} {name:>10s} {2 * half:7.2f} {r.pnl.mean():7.2f} {r.pnl.std():6.2f} {q.mean():6.2f} {q.std():6.2f}")
plt.show()
gamma strategy spread profit sd q(T) sd q
0.01 inventory 1.35 68.26 8.82 0.10 5.16
0.01 symmetric 1.35 68.37 13.53 0.10 8.56
0.10 inventory 1.49 64.84 6.55 0.04 2.88
0.10 symmetric 1.49 68.24 13.48 0.12 8.36
0.50 inventory 2.16 48.21 5.94 0.04 1.90
0.50 symmetric 2.16 59.40 12.13 0.17 6.94
Total running time of the script: (0 minutes 0.082 seconds)