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.
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.
- Explain how a market maker earns the bid–ask spread and what risks offset it.
- Describe inventory risk and how skewing quotes manages it.
- Explain adverse selection and why informed flow erodes market-making profit.
- Implement a simple inventory-aware quoting rule and simulate its P&L and inventory.
- Distinguish spread capture from directional bets and require realistic latency/fill assumptions.
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
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
- Mid-price dynamics (Phase 8): \(dS=\sigma\,dW\) - a driftless random walk over short horizons.
- Reservation price (Phase 16): \(r=S-q\,\gamma\sigma^2(T-t)\), shifted by inventory \(q\) and risk-aversion \(\gamma\).
- Optimal spread (Phase 16): widens with volatility, risk-aversion, and order-arrival intensity.
- Adverse selection (Phase 16): informed flow makes fills correlate with subsequent adverse moves.
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.
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.
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).
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.
- 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.
- 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
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.
(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.
Lesson Summary
Retrieval Practice
Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.
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.
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
- I can explain the core ideas in my own words
- I worked the derivations/examples by hand
- I completed the interactive workbench(es)
- I passed the knowledge check
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.
- Algorithmic and High-Frequency Trading (Cartea, Jaimungal & Penalva, 2015) current - Ch. 10-11 - Market-making, the Avellaneda–Stoikov model, inventory risk, and adverse selection.
- Brownian Motion and Stochastic Calculus (Karatzas & Shreve, 2nd ed., GTM 113) foundational - Ch. 1 - Random-walk mid-price dynamics and the stochastic setting for inventory evolution.
- Monte Carlo Methods in Financial Engineering (Paul Glasserman, 2004) foundational - Ch. 3-4 - Simulating order flow and fills to study the P&L distribution of a quoting strategy.