The Physics of Market Making: Inventory & Risk
Why the 'Spread' is not profit-it is insurance premium. Avellaneda-Stoikov math, Toxic Flow, and the physics of getting run over.
🎯 What You'll Learn
- Deconstruct the Avellaneda-Stoikov Equation (Quote Skewing)
- Analyze Inventory Risk as a function of Volatility ($ \sigma^2 $)
- Identify Toxic Flow (Adverse Selection) using VPIN
- Calculate the 'Fair Value' adjustment based on Inventory
- Simulate a Grid Trading Strategy in Python
📚 Prerequisites
Before this lesson, you should understand:
Introduction
Amateur Market Makers think their job is to “Buy Low, Sell High.” Professional Market Makers know their job is to return to zero inventory before the price moves against them.
Market Making is not trading. It is Storage. You are being paid a fee (Spread) to store volatile assets (Inventory) for milliseconds. If you store them too long, the radiation (Volatility) kills you.
The Physics: Inventory Risk (Stoikov)
If you hold +100 BTC, and the price drops 100. To prevent this, you must sell ASAP. How? By lowering your ask price.
The Avellaneda-Stoikov Equation (Simplified):
- : Reservation Price (Where you center your quotes).
- : Current Mid Price.
- : Current Inventory (Positive = Long, Negative = Short).
- : Risk Aversion Parameter.
- : Volatility (Variance).
Interpretation: If you are Long (), your “Fair Price” is lower than the market Mid Price. You skew your quotes down to attract buyers and discourage sellers.
Deep Dive: Toxic Flow (Adverse Selection)
Imagine you are playing Poker. You have a pair of Kings. Someone goes All-In against you. Do you call? Depends on who it is.
- If it’s a drunk tourist -> Call.
- If it’s Phil Ivey -> Fold.
Physics of Flow:
- Uninformed Flow (Retail): Random walk. Good for MMs.
- Toxic Flow (Insider/HFT): Directional. They know the price is about to move. If you trade with them, you have already lost.
Detection: Volume-Synchronized Probability of Informed Trading (VPIN). If order imbalance spikes, WIDEN spreads immediately.
Code: The Skew Algorithm
A simple python logic for adjusting quotes based on inventory.
class MarketMaker:
def __init__(self, target_inv=0, risk_aversion=0.1):
self.inventory = 0
self.target = target_inv
self.gamma = risk_aversion
def get_quotes(self, mid_price, volatility):
# 1. Calculate Reservation Price
# If huge long inventory, reservation price drops below mid_price
inventory_skew = -(self.inventory - self.target) * self.gamma * volatility
reserv_price = mid_price + inventory_skew
# 2. Add Spread
# Wider spread if volatility is high
half_spread = volatility * 2.0
bid = reserv_price - half_spread
ask = reserv_price + half_spread
return bid, ask
# Simulation
mm = MarketMaker()
# Case 1: Neutral. Mid=100. Bid=99, Ask=101.
# Case 2: Long 1000 shares. Reservation=90. Bid=89, Ask=91.
# (MM is practically BEGGING to sell, and refusing to buy).
Practice Exercises
Exercise 1: The Skew (Beginner)
Scenario: Mid Price 0.10. Task: You are Long 5000 shares (Limit reached). Where do you place your quotes? (Answer: You might quote Bid 99.10 to aggressively dump inventory and stop buying).
Exercise 2: Volatility Expansion (Intermediate)
Scenario: Volatility doubles. Task: According to the equations, what happens to your Spread and your Inventory Aversion? (Both increase).
Exercise 3: VPIN Analysis (Advanced)
Task: Look at a chart of the 2010 Flash Crash. Notice how Volume spiked while Price collapsed. What did the HFTs do? (They turned off. Liquidity evaporated because went to infinity).
Knowledge Check
- What is the “Reservation Price”?
- Why does High Volatility force MMs to widen spreads?
- What is “Toxic Flow”?
- How does Inventory Skewing help mean reversion?
- Why is “holding period” the enemy of a Market Maker?
Answers
- The indifference price. The price at which the MM is equally happy buying or selling, given their current inventory.
- Insurance. The risk of holding inventory is higher, so the premium (spread) must be higher to compensate.
- Informed trading. Orders that predict future price movements (e.g., entering right before a pump).
- Rebalancing. By lowering prices when Long, MMs sell more and buy less, returning to 0.
- Exposure. The longer you hold, the more likely the price drifts away from your entry. MMs want to hold for 0 seconds.
Summary
- Inventory: Is Risk.
- Skewing: The primary defense mechanism.
- Toxic Flow: The primary predator.
Questions about this lesson? Working on related infrastructure?
Let's discuss