Optimal spread (Avellaneda–Stoikov)
The best total spread for a market maker has two parts: a charge for the inventory risk it takes on, and a part set by how quickly fills dry up as quotes move away from the mid.
01The formula
- the total width between the maker's ask and bid quotes
- risk aversion
- volatility of the mid price per unit of time
- time left in the session
- how fast the chance of a fill drops as you quote further from the mid
02See it move
03Where it is used
- Market makerSets its quote width from estimates of σ and k, widening when volatility rises or when fills are insensitive to price.
- Quant researcherEstimates k by fitting how often orders at different distances from the mid get filled.
- Risk managerSees how a higher γ widens quotes and lowers fill rates, and agrees the trade-off with the desk.
04Why traders use it
Quote too tight and you get filled often but earn little and carry risk; quote too wide and you never trade. This formula gives the balance point for given volatility and order flow.
05Worked example
With σ = 2.0, 0.50 of the day left, γ = 0.10 and k = 1.5, the total spread is $1.491: $0.200 for inventory risk and $1.291 from the shape of order arrivals.
06How it is built
- Assume market orders hit a quote at distance from the mid at rate .
- Each fill earns but changes inventory, which costs risk through the reservation price.
- Solving the maker's optimisation gives each quote at from the reservation price.
- Adding the bid and ask sides gives the total spread; as the second term tends to , the spread of a risk-neutral maker.
07The common mistake
Quoting this spread around the mid. In the model it is centred on the reservation price, so with inventory the two quotes are skewed, not symmetric.
08In Python and LaTeX
import numpy as np sigma, tau, gamma, k = 2.0, 0.5, 0.1, 1.5 spread = gamma * sigma**2 * tau + 2 / gamma * np.log(1 + gamma / k) print(round(spread, 3))
\delta^a + \delta^b = \gamma\,\sigma^2\,(T - t) + \frac{2}{\gamma}\ln\!\left(1 + \frac{\gamma}{k}\right)09Where it fits
Rather not code the maths yourself? Describe your trading idea and let AI build the bot.
Build a bot with AgenKitThe worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.