01Systems & simulation
Market Maker Simulator
An exchange simulator with a price-time priority matching engine, inventory-aware Avellaneda–Stoikov quoting and a dashboard that streams order-book activity over WebSockets.
Interactive Dashboard
Project Overview
This simulator implements the Avellaneda–Stoikov (2008) optimal market-making framework in discrete time, running as a live full-stack application. A FastAPI backend ticks at ~20 Hz, advancing a stochastic mid-price, processing Poisson noise-trader arrivals, and streaming JSON snapshots over WebSocket to a React dashboard that renders the full picture in real time.
Limit Order Book
Price-time priority LOB with matching engine built from scratch in Python.
A–S Agent
Optimal reservation price and spread computed from γ, σ, k, and remaining horizon T−t.
Regime Switching
Two-state Markov volatility process with configurable transition probabilities.
Live Dashboard
WebSocket-streamed Recharts panels: LOB depth, PnL, inventory, Sharpe, drawdown, and fill heatmap.
Model & Mechanics
The Avellaneda–Stoikov model treats market making as a stochastic control problem: the MM chooses bid and ask quotes to maximise expected utility of terminal wealth, penalising inventory risk. Key quantities:
- Reservation price, shifts the centre of quotes away from the mid when inventory builds, pulling the MM toward flat risk as horizon risk (σ, T−t) grows: r = s − q·γ·σ²·(T−t)
- Optimal spread, balances inventory risk against fill probability via γ (risk aversion) and k (fill-intensity decay): δ = γ·σ²·(T−t) + (2/γ)·ln(1 + γ/k)
- Fill intensity: noise-trader arrivals are Poisson with rate λ = A·e−kδ, so spreads wider than 1/k see exponentially fewer fills.
- Regime switching: volatility flips between low (σ_low) and high (σ_high) states via a two-state Markov chain; transition probabilities are hot-swappable from the dashboard.
- Adverse selection, tracked per fill using mid-price moves over a configurable lookahead window, signed against the MM, displayed in the toxicity monitor.
About This Project
Overview
The simulator stitches together a price-time priority limit order book, an Avellaneda–Stoikov quoting agent with inventory penalty and hard inventory caps, and a stochastic mid driven by a two-state Markov volatility regime. The stack is built as a learning project and portfolio piece for quant-style roles, demonstrating both the mathematical formulation and full-stack implementation.
Technologies Used
- Python: Core simulation engine, covering LOB, matching logic, Poisson flow, A–S agent, and metrics
- FastAPI: Async backend running the simulation loop and exposing REST + WebSocket endpoints
- WebSockets: Real-time JSON snapshot streaming to the frontend on every simulation tick
- React + TypeScript (Vite): Strongly-typed frontend consuming the WebSocket stream
- Recharts: Live charting for LOB depth, PnL, inventory, Sharpe, drawdown, spread analytics, and fill heatmap
- Pydantic: Type-safe parameter validation on the API for hot-swappable γ, k, arrival rates, and regime probabilities
- pytest: Test suite covering LOB matching, A–S formula correctness, and metric calculations
- Docker Compose + Railway: Local development and cloud deployment
Key Features
- Live LOB depth chart with bid/ask/mid/reservation-price overlays updated at ~20 Hz
- PnL decomposition (mark-to-market vs realised) and inventory trajectory
- Rolling Sharpe, maximum drawdown, and adverse-selection toxicity monitor
- Fill heatmap by price offset and side; spread analytics (optimal vs realised)
- Interactive parameter controls for γ, k, arrival rates, inventory caps, and regime dynamics
References
Avellaneda & Stoikov (2008), Quantitative Finance; Guéant, Lehalle & Fernandez-Tapia (2013); Cartea, Jaimungal & Penalva (2015), Algorithmic and High-Frequency Trading (Cambridge). See the repo README for full citations.