Market-Making Sandbox

How market makers print money

Citadel Securities. Jane Street. Virtu. Optiver. Hudson River. A handful of electronic market-making firms clear tens of billions of dollars a year by quoting both sides of an order book and capturing the spread millions of times a day. In a Trump-era tape that re-prices on every tariff, every Fed leak, every truth-social post — the spread machine runs hotter. Volatility is their revenue.

This page is 13 interactive sandboxes. Every chart is a live in-browser simulation — drag the sliders, watch the order book breathe, the inventory drift, the P&L distribution narrow once you skew. From the limit order book up through Avellaneda–Stoikov, Glosten–Milgrom, and Kyle's $\lambda$. The math is short. The intuition is built by playing.

Sibling to microprice-sandbox · source
01

The limit order book

Everything starts here. Buyers post bids, sellers post asks; the best bid and best ask sandwich the spread. Orders arrive, get filled, get cancelled. The market maker's job is to sit in the book on both sides and earn the spread without getting run over by directional flow.

Why it matters: The book is the data structure every model in this page assumes. Mid-price, micro-price, and depth are the three numbers a maker reads off it constantly.
02

The naive market maker

Simplest possible strategy: quote at mid $\pm\,\delta$ and wait. Buy orders hit your ask, sell orders hit your bid. Each round-trip earns you the full spread $2\delta$.

The catch: with no inventory management, this works only if price stays still. The next section breaks that assumption.
03

Inventory risk

Now let the mid price diffuse. Your P&L is spread capture plus $q \cdot \Delta s$ where $q$ is your inventory. Inventory and price moves are now what blows you up.

The distribution widens. Mean P&L might stay positive, but the tails are owned by inventory drift.
04

Skew the quotes

Push quotes by $-\gamma\,q$: when long, lower both quotes so you sell faster than you buy. A linear rule already mean-reverts inventory hard.

Inventory tames itself. P&L histogram narrows dramatically; mean barely moves.
05

Spread vs. fill rate

Wider spreads earn more per fill but get fewer fills. Fill intensity decays roughly exponentially in distance from mid: $\lambda(\delta) = A\,e^{-k\delta}$. There's an interior optimum.

There's an interior optimum. Past the peak, every extra basis point of spread costs more in lost fills than it earns.
06

Adverse selection

Not all flow is equal. A fraction of trades arrives because the price is about to move against your quote. They look identical to noise on arrival — and they cost you.

Toxicity tax. As informed share rises, the maker's P&L distribution shifts left even with symmetric spreads.
07

Avellaneda–Stoikov

The optimal-control answer to skew + spread, jointly. The maker maximizes expected utility of terminal wealth under inventory risk. Two famous formulas drop out:

$$r(s, q, t) = s - q\,\gamma\,\sigma^{2}(T - t)$$
$$\delta^{*} = \tfrac{1}{2}\gamma\,\sigma^{2}(T - t) + \tfrac{1}{\gamma}\,\ln\!\Big(1 + \tfrac{\gamma}{k}\Big)$$

$r$ is the reservation price — the mid you actually quote around once inventory bias is in. $\delta^{*}$ is the optimal half-spread.

It just works. Inventory std shrinks ~2× vs symmetric, mean P&L is comparable — the whole point is variance.
08

Queue position

At a price level, fills are FIFO. Your position in the queue matters: orders ahead get filled first, but they also bear the adverse selection first when the level is about to clear.

Queue position is information. Front of queue = more fills but worse conditional P&L.
09

Latency

A maker's quotes are only as fresh as her connection. While she's updating, the world moves and stale quotes get picked off.

The latency tax is convex. Speed is bought at the margin to avoid getting sniped on jumps.
10

Hedging

If asset $B$ correlates with the inventory you're forced to hold in $A$, hedge with $B$. The variance-minimizing ratio is

$$h^{*} = \rho\,\frac{\sigma_A}{\sigma_B}$$
Hedge until residual variance is convex around $h^{*}$. Anything left is the price of basis risk.
11

Glosten–Milgrom

Sequential trade model. The maker is uncertain about true value $V \in \{V_L, V_H\}$. Each arriving trade is either informed (knows $V$) or uninformed (random). The maker updates beliefs after every fill, and quotes

$$\text{ask} = \mathbb{E}[V \mid \text{buy}], \qquad \text{bid} = \mathbb{E}[V \mid \text{sell}]$$
Spread is a Bayesian premium. It exists even with no inventory cost: it's the maker's protection against being on the wrong side of an informed trade.
12

Kyle's $\lambda$

A single-auction model with one informed trader, noise traders, and a competitive maker. Price impact is linear in net order flow $y$:

$$p = \mu + \lambda\,y, \qquad \lambda = \frac{\sigma_v}{2\,\sigma_u}$$
Depth is the inverse of information asymmetry. More noise traders dilute information; deeper markets ($1/\lambda$) absorb size with less impact.
13

Microprice

A free signal on top of the book: weight the best bid and ask by the opposite side's size.

$$\text{microprice} = \text{ask}\cdot I + \text{bid}\cdot(1-I), \quad I = \frac{q_b}{q_b + q_a}$$

When the bid stack is thick, the next print is more likely at the ask — so the microprice leans up.

Sibling project: microprice-sandbox reproduces Avellaneda–Stoikov with this signal in the loop.