HJB Market Making

Hamilton-Jacobi-Bellman optimal market making with inventory control

The HJB market maker solves a PDE to find the optimal bid-ask spread at every inventory level and time step. Unlike Avellaneda-Stoikov (which uses a closed-form approximation), the HJB solution is numerically exact for the given model.

Solve the HJB PDE

python
import horizon as hz

solution = hz.solve_hjb(
    gamma=0.1,      # risk aversion
    sigma=0.02,     # price volatility
    kappa=1.5,      # order arrival sensitivity to spread
    A=140.0,        # baseline order arrival rate
    T=1.0,          # time horizon (normalized)
    n_grid=201,     # inventory grid points
    n_time=1000,    # time steps
)

Quote at current state

python
bid_delta, ask_delta = hz.hjb_quote(
    inventory=5,
    mid=0.50,
    solution=solution,
    t=0.3,          # current time (fraction of T)
)

bid = mid - bid_delta
ask = mid + ask_delta

The spread widens when inventory is large (encourages mean reversion) and narrows when inventory is near zero (captures more flow).

Order arrival rate

python
rate = hz.hjb_arrival_rate(delta=0.02, A=140.0, kappa=1.5)
# Expected fills per unit time at this spread

When to use

  • You’re market-making on a CLOB and want mathematically optimal quotes
  • Your inventory risk tolerance varies with time (e.g., tighter as market close approaches)
  • You want to compare against the simpler Avellaneda-Stoikov model

Next