
How Market Makers Determine Bid and Ask Prices - Algorithm Explained
Market making is a fundamental function in today’s electronic financial markets, providing liquidity, reducing spreads, and enabling smoother trading for market participants. But how do market makers actually decide on the bid and ask prices they quote? This article provides a comprehensive deep-dive into the algorithms and mathematical models behind bid-ask price determination, including hands-on Python code, real-world trading examples, and essential interview questions for quant roles.
Introduction to Market Making and Inventory Risk
A market maker is a financial intermediary or trading firm that continuously quotes both buy (bid) and sell (ask) prices for a particular asset, thereby standing ready to buy or sell at those prices. Their presence ensures liquidity, narrows the bid-ask spread, and allows other market participants to transact efficiently.
Role of Market Makers
- Liquidity Provision: By always quoting two-sided markets, market makers ensure that buyers and sellers can transact without significant delays.
- Profit from Spread: Market makers earn the difference between the bid and ask, known as the spread, for each round-trip trade.
- Risk Management: They must manage the risk of holding inventory, especially in volatile markets.
Understanding Inventory Risk
The biggest challenge for market makers is inventory risk. When they buy at the bid and sell at the ask, they accumulate a position (inventory). If the market moves against them, they can incur losses. Therefore, optimal bid and ask prices should balance the trade-off between profit from the spread and risk from holding inventory.
Inventory Risk Example
Suppose a market maker is quoting a stock at a bid of $100 and an ask of $100.10. If they buy 1,000 shares at $100 (customer sells to them) and the price drops to $99.50, the market maker faces a loss if forced to sell at the new lower price. This is the essence of inventory risk, and it motivates the use of sophisticated algorithms to dynamically adjust quotes.
Mathematical Formulation of Bid-Ask Spread Models
Modern market making has evolved from simple constant-spread quoting to highly mathematical models that optimize bid and ask prices based on inventory, volatility, and other market factors. The Avellaneda-Stoikov model is one of the most influential frameworks in this area.
Avellaneda-Stoikov Model Overview
Proposed by Marco Avellaneda and Sasha Stoikov in 2008, this model uses stochastic control theory to determine optimal bid and ask quotes for market makers. It assumes Poisson arrival of market orders and incorporates inventory risk aversion.
Key Assumptions
- Asset price follows a Brownian motion: \(dS_t = \sigma dW_t\)
- Market orders arrive at bid and ask prices as Poisson processes.
- Market maker has exponential utility function: \(U(x) = -e^{-\gamma x}\), where \(\gamma\) is risk aversion.
Mathematical Formulation
Let’s define some core variables:
- \(S_t\): Current mid-price of the asset
- \(q_t\): Market maker's current inventory
- \(\gamma\): Risk aversion parameter
- \(\sigma\): Price volatility
- \(A\): Market order arrival rate parameter
- \(k\): Market order sensitivity to price
- \(\delta_b, \delta_a\): Distances from mid-price to bid and ask quotes, respectively
Model Equations
The model aims to maximize expected utility of terminal wealth, leading to the following optimal bid and ask quotes:
\[ \begin{aligned} \delta_b^* &= \frac{1}{k} \ln\left(1 + \frac{\gamma}{k}\right) + \frac{\gamma \sigma^2 (T-t) q_t}{2} \\ \delta_a^* &= \frac{1}{k} \ln\left(1 + \frac{\gamma}{k}\right) - \frac{\gamma \sigma^2 (T-t) q_t}{2} \end{aligned} \]
Where \(T-t\) is time left in the trading session. The first term is the reservation spread, and the second term adjusts the quotes based on inventory: if the market maker is long, they will set a lower ask (to sell inventory) and a higher bid (to discourage buying more).
Interpreting the Equations
- Spread widens with increasing risk aversion \(\gamma\) or volatility \(\sigma\).
- Inventory effect: If inventory \(q_t > 0\) (long), bids are lowered and asks are raised, encouraging inventory reduction.
- Time effect: As time \(t\) approaches \(T\), the inventory term shrinks, and quotes become more aggressive.
Other Models and Extensions
Many extensions exist, such as:
- Stochastic volatility models: Allowing \(\sigma\) to change over time.
- Market impact models: Taking into account the effect of the market maker’s own trades on price.
- Multi-asset models: Managing correlated inventory across several assets.
Python Simulation of a Simple Market-Making Algorithm
To illustrate how market makers use these models in practice, let’s implement a simple Avellaneda-Stoikov-style algorithm in Python. We’ll simulate the mid-price as a random walk and dynamically adjust bid and ask quotes based on current inventory.
Setup and Parameters
import numpy as np
import matplotlib.pyplot as plt
# Simulation parameters
T = 1.0 # total time (e.g., 1 day)
dt = 0.01 # time step
N = int(T/dt)
sigma = 2.0 # volatility
gamma = 0.01 # risk aversion
k = 1.5 # order book depth parameter
A = 140 # base arrival rate
S0 = 100.0 # initial mid price
q = 0 # initial inventory
cash = 0 # initial cash
inventory_history = []
price_history = []
cash_history = []
bid_history = []
ask_history = []
np.random.seed(42)
S = S0
Simulation Loop
for t in range(N):
time_left = T - t*dt
# Avellaneda-Stoikov optimal spread and adjustment for inventory
reservation_spread = (1.0/k) * np.log(1 + gamma / k)
inventory_adjust = 0.5 * gamma * sigma**2 * time_left * q
bid = S - reservation_spread + inventory_adjust
ask = S + reservation_spread + inventory_adjust
bid_history.append(bid)
ask_history.append(ask)
price_history.append(S)
inventory_history.append(q)
cash_history.append(cash)
# Simulate mid price movement (Brownian motion)
S += sigma * np.sqrt(dt) * np.random.randn()
# Simulate market order arrivals (Poisson process)
lambda_bid = A * np.exp(-k * (bid - S))
lambda_ask = A * np.exp(-k * (S - ask))
if np.random.rand() < lambda_bid * dt:
# Buy at bid (customer sells to us)
q += 1
cash -= bid
if np.random.rand() < lambda_ask * dt:
# Sell at ask (customer buys from us)
q -= 1
cash += ask
Results and Visualization
plt.figure(figsize=(14,5))
plt.subplot(2,1,1)
plt.plot(price_history, label='Mid Price')
plt.plot(bid_history, label='Bid Quote', linestyle='--')
plt.plot(ask_history, label='Ask Quote', linestyle='--')
plt.title('Market Maker Quotes and Price')
plt.legend()
plt.subplot(2,1,2)
plt.plot(inventory_history, label='Inventory')
plt.plot(cash_history, label='Cash')
plt.title('Inventory and Cash Over Time')
plt.legend()
plt.tight_layout()
plt.show()
This simulation shows how the market maker dynamically adjusts quotes based on both mid-price movement and their own inventory. When inventory grows, the bid and ask shift to incentivize reducing risk.
Real-Life Examples from High-Frequency Trading Firms
Market making is the bread and butter of many high-frequency trading (HFT) firms. These firms deploy sophisticated algorithms—often based on models like Avellaneda-Stoikov but extended with machine learning, real-time analytics, and ultra-fast execution—to provide continuous liquidity.
Famous HFT Market Makers
- Citadel Securities: One of the largest market makers globally, active in equities, options, and more. Uses proprietary technology to quote prices on virtually every US-listed stock.
- Jane Street: Known for its quantitative approach and presence in ETFs, options, and cryptocurrencies.
- Virtu Financial: Operates in 235+ venues worldwide, providing liquidity in thousands of financial instruments.
- IMC Trading, Optiver, Hudson River Trading: All deploy advanced market making strategies on global exchanges.
Real-World Adjustments to Algorithms
These firms don’t just use textbook models—they enhance them with:
- Order flow prediction: Machine learning to forecast bursts of buy/sell orders.
- Market microstructure analysis: Factoring in order book depth, hidden liquidity, and latency dynamics.
- Cross-asset hedging: Managing inventory risk across correlated assets (e.g., ETF vs. components).
- Adaptive risk aversion: Dynamically changing \(\gamma\) based on market conditions.
- Latency arbitrage: Leveraging speed to react faster than competitors.
Case Study: ETF Market Making
Consider an ETF market maker quoting both the ETF and its underlying basket. If the ETF trades at a discount to the basket, the market maker can buy ETF shares, redeem them for the basket, and sell components, capturing a near riskless profit. Their bid and ask quotes constantly adjust to both the ETF price and the real-time value of the basket, using algorithms similar to Avellaneda-Stoikov but with added complexities.
Interview Questions on Market Making for Quant Roles
For those aspiring to quant or trading roles at HFT firms, understanding market making algorithms is essential. Here are some common interview questions, along with brief explanations:
Core Market Making Questions
- Q1: How does inventory risk affect the bid-ask spread quoted by a market maker?
A: Higher inventory risk (more shares held) leads market makers to widen the spread and skew quotes to encourage inventory reduction—lower bids if long, higher asks if short. - Q2: Explain the intuition behind the Avellaneda-Stoikov model.
A: The model balances profit from collecting spread with the risk of adverse price movement due to holding inventory, using stochastic control to optimize quotes. - Q3: What factors influence the optimal bid and ask in a market making algorithm?
A: Mid-price, inventory, volatility, risk aversion, time to maturity, order arrival rates, and market microstructure factors all play a role.
Mathematical and Coding Questions
- Q4: Derive the optimal bid and ask formulas in the Avellaneda-Stoikov model.
A: (See equations above; expected utility maximization using Hamilton-Jacobi-Bellman equations.) - Q5: Implement a basic market making simulation in Python.
A: (See Python code section in this article.) - Q6: How would you extend the model to account for stochastic volatility?
A: Allow \(\sigma\) to be time-varying, possibly modeled by a GARCH or Heston process, and adjust control equations accordingly.
Advanced and Behavioral Questions
- Q7: How would you defend your market making algorithm against competitors in a highly competitive environment?
A: By minimizing latency, using adaptive models, incorporating machine learning for order flow prediction, and dynamically hedging risk. - Q8: How do real-world trading costs (latency, fees, slippage) affect the optimal quotes?
A: They widen the optimal spread to compensate for additional risks and costs, and may require adjusting the algorithm to avoid unprofitable trades.
Conclusion
Market making is a complex, high-stakes discipline at the heart of modern financial markets. The determination of bid and ask prices is governed by a blend of stochastic control theory, real-time analytics, and robust risk management. The Avellaneda-Stoikov model provides a foundational mathematical framework, but real-world firms augment it with high-frequency data, adaptive algorithms, and cutting-edge technology. For quants, understanding these principles—both theoretically and practically—is vital for success in today’s trading environment.
Whether you are a student, aspiring quant, or practitioner, a deep grasp of market making algorithms, inventory risk management, and the nuances of real-world implementation will set you apart in this competitive field.
