Skip to main content

Rigorous Avellaneda–Stoikov optimal market-making solver (PDE value function + adverse selection).

Project description

avellaneda-stoikov

PyPI CI License: MIT

A rigorous Avellaneda–Stoikov optimal market-making solver — the PDE value function with adverse selection, asymmetric fill rates, and inventory-aware quoting.

pip install avellaneda-stoikov

Quickstart

from avellaneda_stoikov import ASParams, solve_value_function, optimal_depths

p = ASParams(sigma=0.6, lam_plus=1.0, lam_minus=1.0,
             kappa_plus=100.0, kappa_minus=100.0,
             phi=1e-4, alpha=1e-3, q_max=5, T=60.0, n_steps=600)

t_grid, h_grid = solve_value_function(p)          # solve once
ask, bid = optimal_depths(h_grid, t_grid, p.q_max, t=0.0, q=2,
                          kappa_plus=p.kappa_plus, kappa_minus=p.kappa_minus)
print(ask, bid)   # optimal ask/bid depths when long 2 units (ask < bid: skew to sell)

The model

Solves the Avellaneda–Stoikov / Cartea Ch. 10 market-making problem. Ansatz H(t,x,S,q)=x+q·S+h(t,q); the HJB reduces to an ODE system in inventory q, integrated backward from h(T,q) = −α·q². Optimal feedback depths:

δ⁺* = 1/κ⁺ + ε⁺ + h(t,q) − h(t,q−1)     (ask)
δ⁻* = 1/κ⁻ + ε⁻ + h(t,q) − h(t,q+1)     (bid)

inventory skew

Why this one

Most open-source A-S implementations are minimal and unmaintained. This one adds:

  • Adverse selection (ε⁺/ε⁻, Cartea §10.4) — quote wider when fills predict mid moves.
  • Asymmetric fill rates κ⁺ ≠ κ⁻ solved directly in the PDE.
  • Finite-difference PDE solver (not just the closed-form approximation).
  • Inventory skew, boundary and overshoot handling, validated by tests.

Typed, mypy --strict, tested, MIT.

API

  • ASParams(...) — model + strategy parameters (validate()).
  • solve_value_function(p) -> (t_grid, h_grid) — solve once.
  • optimal_depths(h_grid, t_grid, q_max, t, q, kappa_plus, kappa_minus, epsilon_plus=0, epsilon_minus=0)(δ⁺, δ⁻), None on a boundary.
  • reservation_price_and_spread(...)(r, bid, ask).

References

  • Avellaneda & Stoikov (2008), High-frequency trading in a limit order book.
  • Cartea, Jaimungal & Penalva, Algorithmic and High-Frequency Trading, Ch. 10.

Honest note

Extracted from a live trading bot. This is the solver — calibration (estimating λ, κ, ε), execution and risk are left to you; that's where the edge lives. Out of scope for now: regime switching, order-flow drift (§10.5), non-linear fill models.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avellaneda_stoikov-0.1.0.tar.gz (59.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

avellaneda_stoikov-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file avellaneda_stoikov-0.1.0.tar.gz.

File metadata

  • Download URL: avellaneda_stoikov-0.1.0.tar.gz
  • Upload date:
  • Size: 59.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for avellaneda_stoikov-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7649416526b700e5ab40ad7a42ac8e3db3811a228e975dafb3d22965e250275
MD5 150c8bfdd422d1436101504b449bdec3
BLAKE2b-256 921c732e5102b6cde2948f816b753523aff6f175101d0bd415835b1d2aa88431

See more details on using hashes here.

Provenance

The following attestation bundles were made for avellaneda_stoikov-0.1.0.tar.gz:

Publisher: publish.yml on Gavr625/avellaneda-stoikov

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file avellaneda_stoikov-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for avellaneda_stoikov-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1279a49358e880731f0a74ce9e31c5d897c0a738a219188e2d2cad96c0430862
MD5 1a1d2522107aa11406123a58f8dbf7a8
BLAKE2b-256 22ff55bad1903703bc2a62c0a5a4aff34b973b4e92138ddc16d7dfd66f29bfc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for avellaneda_stoikov-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Gavr625/avellaneda-stoikov

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page