Phase 18 - Lesson 18.7

Capstone 7 - Market-Making / HFT Simulation

Quote a two-sided market, earn the spread, manage inventory, and confront adverse selection - the Avellaneda–Stoikov intuition in a simulated order book.

⏱ 140 min● Research🔗 Prereqs: Phases 8, 16; Capstone 6
↖ Phase 18 hub
Builds on: Integrates Stochastic Processes (Phase 8) and HFT (Phase 16), extending the microstructure of Capstone 6.
Leads to: Completes the trading stack (signal → execution → market-making) feeding the final capstone (18.8).

Learning Objectives

Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.

Key Vocabulary

Market maker
A trader who continuously posts bid and ask quotes, earning the spread by providing liquidity.
Bid–ask spread
The gap between the best buy and sell quotes; the market maker’s gross compensation per round trip.
Inventory risk
The risk from holding a net long/short position accumulated by one-sided fills; exposed to price moves.
Adverse selection
The tendency to be filled by better-informed traders precisely when the price is about to move against you.
Reservation price
An inventory-adjusted fair value around which the maker centers quotes (Avellaneda–Stoikov).
Quote skew
Shifting bid/ask asymmetrically to encourage trades that reduce inventory.

Intuition & Motivation

Intuition
A market maker is a shopkeeper for liquidity: post a bid (buy price) and an ask (sell price), and earn the spread when both sides trade. But the spread is not free money. Two risks eat it. Inventory risk: if only buyers hit your ask, you accumulate a short position and are exposed to the price rising. Adverse selection: the traders who lift your quote are often the ones who know something - you get filled right before the price moves against you.

Good market-making is therefore inventory management, not prediction. The Avellaneda–Stoikov intuition centers quotes on an inventory-adjusted reservation price and skews them to lean against your position - quoting more aggressively on the side that reduces inventory. The goal is to capture spread while keeping inventory near zero, not to bet on direction. And none of it survives contact with reality unless latency, fill probabilities, and costs are modeled honestly.

The brief

Simulate a single-asset order book with a mid-price random walk and probabilistic fills. Implement an inventory-aware quoting rule and measure P&L, its decomposition into spread capture vs. inventory P&L, and the inventory path. Deliverable: code, a P&L/inventory plot, and a note on how adverse selection and latency would degrade the results. No profitability is promised; the point is understanding the risk structure.

Required theory recap

Earning the spread - and the two risks that offset it

If you buy at the bid \(S-\tfrac{\delta}{2}\) and sell at the ask \(S+\tfrac{\delta}{2}\) on a round trip, you capture the spread \(\delta\). The problem: fills are one-sided. When only your ask trades, you go short; the mid can then rise and your inventory loses money. Inventory P&L can easily swamp spread capture if you don’t manage it.

\[\text{P\&L} = \underbrace{\textstyle\sum \tfrac{\delta}{2}\,|\text{fills}|}_{\text{spread capture}} \;+\; \underbrace{q_t\,\Delta S_t}_{\text{inventory P\&L (risky)}}.\] (18.14)

Inventory-aware quoting: skew toward flat

The Avellaneda–Stoikov idea: don’t center your quotes on the mid, center them on an inventory-adjusted reservation price that drifts against your position. If you are long, lower both quotes (making your ask more attractive) to sell inventory; if short, raise them. This skew continuously pushes inventory back toward zero.

\[r_t = S_t - q_t\,\gamma\,\sigma^2 (T-t),\qquad \text{bid}=r_t-\tfrac{\delta}{2},\ \ \text{ask}=r_t+\tfrac{\delta}{2}.\] (18.15)
Worked Example - Why skewing quotes controls inventory
1
Suppose you accumulate \(q=+50\) (long) after buyers sold to you at your bid.
2
Reservation price (18.15) drops by \(q\gamma\sigma^2(T-t)\gt 0\), so both bid and ask move down.
3
Your ask is now closer to the mid → more likely to be lifted → you sell and reduce \(q\).
4
Your bid is now further from the mid → less likely to be hit → you buy less, avoiding more length.
5
Net effect: inventory mean-reverts toward zero, so the risky \(q_t\Delta S_t\) term in (18.14) stays small - you keep the spread, shed the direction.

Adverse selection and the honesty caveats

The uncomfortable truth: the counterparties who trade against a stale quote are disproportionately informed. In a naive simulation with random, uninformed flow, spread capture looks like easy money. Add adverse selection - make fills slightly more likely just before adverse mid moves - and the edge shrinks or vanishes. Real market-making also lives or dies on latency (can you update quotes before being picked off?) and queue position. A simulation that omits these overstates profitability, exactly like omitting transaction costs (Capstone 5).

▶ Reference architecture for the market-making sim
mm/book.py -> mid_path(sigma, seed); fill_prob(distance, intensity) mm/quote.py -> reservation_price(S,q,gamma,sigma,tau); quotes(delta) mm/sim.py -> step loop: post quotes -> sample fills -> update q, cash mm/pnl.py -> decompose P&L into spread capture vs inventory P&L (18.14) mm/stress.py -> add adverse selection + latency; watch the edge erode

The base sim is seeded and reproducible (17.3); the stress module deliberately adds the realism (adverse selection, latency) that separates a toy from a claim.

Common Mistakes to Avoid
  • Centering quotes on the mid and ignoring inventory - a run of one-sided fills builds a large risky position.
  • Reporting spread capture without the inventory P&L term; the latter can dominate (18.14).
  • Simulating only random, uninformed flow and concluding market-making is easy - adverse selection is the whole difficulty.
  • Omitting latency and queue position, so quotes are magically always fresh.
  • Treating market-making as a directional bet; it is a spread-capture, inventory-control business.
  • Claiming profitability from a frictionless sim - the same optimism as a zero-cost backtest.
Quant Practitioner Tips
  • Skew quotes off an inventory-adjusted reservation price (18.15) to keep inventory near zero.
  • Always decompose P&L into spread capture and inventory P&L; watch the risky term.
  • Stress-test with adverse selection and latency before believing any edge.
  • Set inventory limits and widen or pull quotes as inventory grows - risk management first.
  • Report results as risk-structure understanding, not a profit claim; require realistic fills and costs.

Interactive: inventory-aware quoting reduces inventory risk

Implement the reservation-price skew and a small simulation step, and confirm that skewing quotes keeps inventory closer to zero than symmetric quoting under one-sided pressure.

Knowledge Check

Q1 Easy
A market maker’s gross compensation comes from:
Predicting direction
Earning the bid–ask spread by providing liquidity on both sides
Paying the spread
Holding large inventory
Q2 Medium
When a market maker accumulates a long inventory, the Avellaneda–Stoikov reservation price:
Rises above the mid
Falls below the mid, making the ask more attractive so inventory is sold down
Stays at the mid
Becomes undefined
Q3 Hard
Why does a market-making simulation with only random, uninformed order flow overstate profitability?
It underestimates the spread
It omits adverse selection - real fills come disproportionately from informed traders right before adverse moves
Random flow is illegal
It uses too many paths

Practical Exercise

Decompose a market maker’s P&L and explain risk management. (a) Write P&L as spread capture plus inventory P&L and say which term is risky. (b) Describe two concrete controls that keep inventory bounded. (c) Explain, in one paragraph, why a frictionless simulation showing steady profits is not evidence the strategy is profitable, referencing adverse selection and latency.

▶ Show full solution

(a) \(\text{P\&L}=\sum\tfrac{\delta}{2}|\text{fills}| + \sum_t q_t\,\Delta S_t\) (18.14). The first term (spread capture) is roughly steady and positive; the second (inventory P&L) is the risky term - a mark-to-market on whatever net position you carry, which can dwarf the spread when inventory is large and the mid moves.

(b) Controls: (1) quote skew off an inventory-adjusted reservation price (18.15), continuously leaning against the position; (2) hard inventory limits - widen the spread, pull the quote on the building side, or hedge in the underlying when \(|q|\) exceeds a threshold.

(c) A frictionless sim assumes your quotes are always fresh and your counterparties are random. Reality violates both. Adverse selection means informed traders lift stale quotes just before the mid moves against you, systematically turning fills into losses that random-flow sims never show. Latency means you cannot always cancel or reprice before being picked off, and queue position determines whether you even get the good fills. Omitting these is the microstructure analogue of ignoring transaction costs - the profits are an artifact of an unrealistic model, not an edge.

After the reveal, answer for yourself: How is the ‘frictionless overstatement’ here the same intellectual error as a zero-cost backtest in Capstone 5?

Lesson Summary

Market-making earns the bid–ask spread for providing liquidity, but two risks offset it: inventory risk from one-sided fills and adverse selection from informed flow. The Avellaneda–Stoikov approach centers quotes on an inventory-adjusted reservation price \(r=S-q\gamma\sigma^2(T-t)\) and skews them to drive inventory toward zero - capturing spread rather than betting on direction. P&L splits into spread capture plus a risky inventory term, and any profit claim requires modeling adverse selection, latency, and costs honestly.

Retrieval Practice

Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.

▶ Show retrieval prompts & answers
Q: How does a market maker manage inventory risk with quotes?
A: By centering quotes on an inventory-adjusted reservation price \(r=S-q\gamma\sigma^2(T-t)\) and skewing: when long, both quotes drop so the ask is lifted and inventory falls; when short, they rise. This mean-reverts inventory toward zero, containing the risky \(q_t\Delta S_t\) P&L term.
Q: What is adverse selection and why does it undermine naive market-making sims?
A: The tendency to be filled by better-informed traders just before the price moves against you. Simulations with only random uninformed flow miss this, so spread capture looks like free money; adding adverse selection (and latency) erodes or eliminates the apparent edge.

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.