How market making works: an interactive sandbox
Electronic market makers quote both sides of an order book and earn the spread while managing inventory risk and adverse selection. This page is 13 in-browser simulations, from the limit order book to Avellaneda–Stoikov, Glosten–Milgrom, and Kyle's λ. Drag the sliders to see each effect.
Watch the order book breathe, the inventory drift, and the P&L distribution narrow once you skew. The math is short. The intuition is built by playing.
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.
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$.
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.
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.
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}$.
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.
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$ is the reservation price — the mid you actually quote around once inventory bias is in. $\delta^{*}$ is the optimal half-spread.
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.
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.
Hedging
If asset $B$ correlates with the inventory you're forced to hold in $A$, hedge with $B$. The variance-minimizing ratio is
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
Kyle's λ
A single-auction model with one informed trader, noise traders, and a competitive maker. Price impact is linear in net order flow $y$:
Microprice
A free signal on top of the book: weight the best bid and ask by the opposite side's size.
When the bid stack is thick, the next print is more likely at the ask — so the microprice leans up.