Skip to main content

Module models

Module models 

Source
Expand description

§Models

The library provides implementations for several variations of the classic inventory management problem.

§1. Avellaneda-Stoikov (Standard)

The classic model for a market maker optimizing bid/ask quotes to maximize utility of terminal wealth while penalizing inventory risk.

  • Dynamics: $dS_t = \sigma dW_t$, $dq_t = dN_t^{buy} - dN_t^{sell}$.
  • Intensity: $\lambda(\delta) = A e^{-\kappa \delta}$.
  • Objective: Maximize $\mathbb{E}[ -e^{-\gamma (X_T + q_T S_T)} ]$.
  • Hamiltonian: Involves terms for cash flow from spreads and a quadratic penalty for inventory risk $\frac{1}{2} \gamma \sigma^2 q^2$.

§Solutions

  • Exact Solution (AvellanedaExact): Implements the spectral method solution derived by Guéant, Lehalle, and Tapia.
    • Ansatz: The value function is transformed via $u(t, x, q, s) = -\exp(-\gamma(x + qs)) v_q(t)^{-\frac{\gamma}{\kappa}}$.
    • ODE System: The function $v_q(t)$ satisfies the linear system $\dot{v}(t) = M v(t)$ (or $\dot{v} = -Mv$ depending on time direction) where $M$ is a tridiagonal matrix: $$ \dot{v}q(t) = \alpha q^2 v_q(t) - \eta (v{q-1}(t) + v_{q+1}(t)) $$ with $\alpha = \frac{\kappa}{2} \gamma \sigma^2$ and $\eta = A (1 + \frac{\gamma}{\kappa})^{-(1 + \frac{\kappa}{\gamma})}$.
    • Solution: $v(t) = \exp(-M(T-t)) \mathbf{1}$.
    • Optimal Quotes: $$ \delta^b(t, q) = \frac{1}{\kappa} \ln\left(\frac{v_q(t)}{v{q+1}(t)}\right) + \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) $$ $$ \delta^a(t, q) = \frac{1}{\kappa} \ln\left(\frac{v_q(t)}{v{q-1}(t)}\right) + \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) $$
  • Approximation (Stationary): Implements the closed-form asymptotic approximation for stationary spreads (infinite horizon): $$ \delta_b(q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \frac{2q + 1}{2} \sqrt{\frac{\sigma^2 \gamma}{2\kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$ $$ \delta_a(q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) - \frac{2q - 1}{2} \sqrt{\frac{\sigma^2 \gamma}{2\kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$
  • Approximation (Near Maturity): Taylor expansion of optimal quotes for $t$ close to $T$: $$ \delta^_b(t, q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \frac{1+2q}{2} \gamma \sigma^2 (T-t) $$ $$ \delta^_a(t, q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \frac{1-2q}{2} \gamma \sigma^2 (T-t) $$

§2. Avellaneda with Drift (AvellanedaDrift)

Extends the standard model by adding a drift term $\mu$ to the mid-price process: $dS_t = \mu dt + \sigma dW_t$.

  • Effect: The inventory penalty is adjusted by the expected drift profit/loss $q \mu$. The market maker skews quotes to accumulate inventory in the direction of the drift.
  • Exact Solution (AvellanedaDriftExact): Solves the modified ODE system where the diagonal terms of the transition matrix include the drift adjustment.
    • ODE System: $$ \dot{v}q(t) = (\alpha q^2 - \beta q) v_q(t) - \eta (v{q-1}(t) + v_{q+1}(t)) $$ where $\beta = \kappa \mu$.
    • Solution: $v(t) = \exp(-M(T-t)) \mathbf{1}$.
    • Approximation (Stationary): $$ \delta_b(q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \left( \frac{2q+1}{2} - \frac{\mu}{\gamma \sigma^2} \right) \sqrt{\frac{\sigma^2 \gamma}{2 \kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$ $$ \delta_a(q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) - \left( \frac{2q-1}{2} - \frac{\mu}{\gamma \sigma^2} \right) \sqrt{\frac{\sigma^2 \gamma}{2 \kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$

§3. Avellaneda with Market Impact (AvellanedaImpact)

Extends the standard model by adding a linear permanent market impact $\xi$.

  • Dynamics: Trading activity permanently moves the mid-price.
    • Buy fill: $S \to S + \xi$ (or similar, depending on formulation).
  • Effect: Trading becomes more expensive as it moves the price against the market maker.
  • Exact Solution (AvellanedaImpactExact): Solves the modified ODE system where the transition terms account for the immediate wealth loss due to impact.
    • ODE System: $$ \dot{v}q(t) = \alpha q^2 v_q(t) - \tilde{\eta} (v{q-1}(t) + v_{q+1}(t)) $$ where $\tilde{\eta} = \eta e^{-\frac{\kappa \xi}{2}}$.
    • Terminal Condition: Accounts for liquidation cost $\frac{1}{2}\xi q^2$: $$ v_q(T) = e^{-\frac{1}{2}\kappa \xi q^2} $$
    • Solution: $v(t) = \exp(-M(T-t)) v(T)$.
    • Approximation (Stationary): $$ \delta_b(q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \frac{\xi}{2} + \frac{2q+1}{2} e^{\frac{\kappa \xi}{4}} \sqrt{\frac{\sigma^2 \gamma}{2 \kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$ $$ \delta_a(q) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \frac{\xi}{2} - \frac{2q-1}{2} e^{\frac{\kappa \xi}{4}} \sqrt{\frac{\sigma^2 \gamma}{2 \kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$

§4. Heston Model (Heston)

Extends the standard model by incorporating stochastic volatility for the asset price.

  • Dynamics:
    • Price: $dS_t = \sqrt{v_t} dW_t^S$
    • Variance: $dv_t = \kappa_v (\theta_v - v_t) dt + \xi_v \sqrt{v_t} dW_t^v$
  • State Space: The value function depends on both inventory $q$ and variance $v$: $V(t, q, v)$.
  • Implementation:
    • Uses the Guéant ansatz for the inventory dimension to reduce the problem dimensionality.
    • Solves the resulting PDE on a 2D grid (Inventory $\times$ Variance).
    • Drift Handling: Uses upwinding for the mean-reverting drift of the variance process to ensure stability.
    • PDE System: The value function $V(t, q, v)$ satisfies the semi-linear PDE: $$ \partial_t V + \kappa_v (\theta_v - v) \partial_v V + \frac{1}{2} \xi_v^2 v \partial_{vv} V - \frac{1}{2} \gamma v q^2 + \sup_{\delta} \mathcal{H}(\delta, V) = 0 $$ where the Hamiltonian $\mathcal{H}$ accounts for the optimal limit order intensities: $$ \mathcal{H}(\delta, V) = \sum_{k \in {b, a}} \frac{\lambda(\delta_k)}{\gamma} \left( 1 - \exp\left[-\gamma\left(\delta_k + \Delta_k V\right)\right] \right) $$ with $\Delta_b V = V(t, q+1, v) - V(t, q, v)$ and $\Delta_a V = V(t, q-1, v) - V(t, q, v)$.
    • Approximation (Heuristic): Adapting the stationary approximation by substituting the instantaneous variance $v_t$ for $\sigma^2$: $$ \delta_b(q, v) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) + \frac{2q + 1}{2} \sqrt{\frac{v \gamma}{2\kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$ $$ \delta_a(q, v) \approx \frac{1}{\gamma} \ln\left(1 + \frac{\gamma}{\kappa}\right) - \frac{2q - 1}{2} \sqrt{\frac{v \gamma}{2\kappa A} \left(1 + \frac{\gamma}{\kappa}\right)^{1 + \frac{\kappa}{\gamma}}} $$

§5. Hawkes Model (AvellanedaHawkes)

Extends the standard model by replacing the constant order arrival intensity $A$ with a self-exciting Hawkes process. The state variable $\lambda_t$ governs how often market orders arrive.

  • Dynamics:
    • Price: $dS_t = \sigma dW_t$
    • Intensity: $d\lambda_t = \beta (\mu - \lambda_t) dt + \alpha \lambda_t dt$
  • State Space: $[q, \lambda]$ where $q$ is inventory and $\lambda$ is the current intensity.
  • Implementation:
    • The intensity dimension is discretized on a grid and transported via an upwind finite-difference scheme encoded in the solver’s jump interface.
    • Fill-rate intensities use $\lambda$ instead of the constant $A$: $\Lambda(\delta) = \lambda e^{-\kappa \delta}$.

§6. Heston + Hawkes (HestonHawkes)

Merges stochastic volatility (Heston) with self-exciting order flow (Hawkes) into a single three-dimensional model.

  • State Space: $[q, v, \lambda]$
  • Dynamics:
    • Inventory: $dq = +1$ (buy fill) or $-1$ (sell fill)
    • Variance: $dv_t = \kappa_v (\theta - v_t) dt + \xi \sqrt{v_t} dW^v_t$
    • Intensity: $d\lambda_t = \beta (\mu_\lambda - \lambda_t) dt + \alpha \lambda_t dt$
  • Demonstrates seamless N=3 extensibility of the Model trait.

§Source Layout

ModulePath
Model traitsrc/models/traits.rs
Avellaneda-Stoikovsrc/models/avellaneda.rs
Avellaneda + Driftsrc/models/avellaneda_drift.rs
Avellaneda + Hawkessrc/models/avellaneda_hawkes.rs
Avellaneda + Impactsrc/models/avellaneda_impact.rs
Hestonsrc/models/heston.rs
Heston + Hawkessrc/models/heston_hawkes.rs
American Putsrc/models/american_put.rs
Analytical (exact / approx)src/analytical/

Modules§

american_put
avellaneda
avellaneda_drift
avellaneda_hawkes
avellaneda_impact
bilateral_hawkes
bilateral_hawkes_order_flow_imbalance
heston
heston_hawkes
kelly_hjb
traits

Enums§

TerminalCondition
Terminal condition applied to the value function at expiry.