Learn / Track VII / lesson 2 of 4
Market making: the Avellaneda–Stoikov model
Quoting both sides and earning the spread — and the inventory risk and adverse selection that try to take it back.
A market maker posts a bid and an ask, buys from sellers and sells to buyers, and aims to earn the spread many times a day. Two forces fight that income:
- Inventory risk: after a run of fills on one side, you hold a position exposed to price moves.
- Adverse selection: the counterparties most eager to trade with you are often the ones who know where the price is going.
The Avellaneda–Stoikov model
Avellaneda and Stoikov (2008) derived optimal quotes for a market maker with inventory , risk aversion , mid price following Brownian motion with volatility , and time remaining in the session.
First, the reservation price — the price at which the market maker is indifferent to holding one more unit:
If you are long (), your reservation price sits below the mid, so you quote lower: more eager to sell, less eager to buy. If short, it sits above. This is inventory skew.
Second, the optimal total spread around :
where describes how quickly fill probability falls as you quote further from the mid (order arrival intensity decays like ). The bid is placed at and the ask at .
Reading the formulas
- Higher volatility → wider spread and stronger skew: inventory is riskier.
- Higher risk aversion → stronger skew, faster inventory mean reversion.
- Larger (fill probability falls off quickly) → tighter spread, because quoting wide means you rarely trade.
- As shrinks, the inventory terms fade: near the end of the horizon you mainly want to get flat.
There is no session end, so practitioners usually replace with a fixed horizon parameter, estimate from recent short-horizon returns, and estimate from how often quotes at different distances get filled. Funding rates add a carry term to the reservation price.
Adverse selection and protection
The model assumes fills are random. In reality, fills cluster just before the price moves against you. Practical defences:
- widen or pull quotes when volatility or order-book imbalance spikes,
- skew quotes using short-term signals (micro-price, trade flow),
- cap inventory hard and flatten with a market order if breached,
- cancel quickly; stale quotes are free options for faster traders.
Backtesting a market maker on candles. Fills depend on queue position, cancels and latency, none of which exist in OHLC data. Use tick or order-book data, and assume you are at the back of the queue unless you can show otherwise.
Put it to work
Build this idea
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build an Avellaneda-Stoikov market making bot for perps from strategies/Dynamic-Spread-Market-Making-Strategy.md with inventory skew management, order deduplication, a max-inventory kill switch, and paper trading by default- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch