avellaneda-stoikov
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)
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)—(δ⁺, δ⁻),Noneon 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.
Metadata
Release files for avellaneda-stoikov 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| avellaneda_stoikov-0.1.0.tar.gz | 59.0 kB | With provenance | Details for avellaneda_stoikov-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| avellaneda_stoikov-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for avellaneda_stoikov-0.1.0-py3-none-any.whl |
Total release size: 67.0 kB
Release files / avellaneda_stoikov-0.1.0.tar.gz
| Download URL | avellaneda_stoikov-0.1.0.tar.gz |
|---|---|
| Size | 59.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7649416526b700e5ab40ad7a42ac8e3db3811a228e975dafb3d22965e250275
|
|
BLAKE2b-256 checksum How to use checksums |
921c732e5102b6cde2948f816b753523aff6f175101d0bd415835b1d2aa88431
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.
Transparency logRelease files / avellaneda_stoikov-0.1.0-py3-none-any.whl
| Download URL | avellaneda_stoikov-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1279a49358e880731f0a74ce9e31c5d897c0a738a219188e2d2cad96c0430862
|
|
BLAKE2b-256 checksum How to use checksums |
22ff55bad1903703bc2a62c0a5a4aff34b973b4e92138ddc16d7dfd66f29bfc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.
Transparency logSecurity for avellaneda-stoikov 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for avellaneda_stoikov-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.