Rigorous Avellaneda–Stoikov optimal market-making solver (PDE value function + adverse selection).
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7649416526b700e5ab40ad7a42ac8e3db3811a228e975dafb3d22965e250275
|
|
| MD5 |
150c8bfdd422d1436101504b449bdec3
|
|
| BLAKE2b-256 |
921c732e5102b6cde2948f816b753523aff6f175101d0bd415835b1d2aa88431
|
Provenance
The following attestation bundles were made for avellaneda_stoikov-0.1.0.tar.gz:
Publisher:
publish.yml on Gavr625/avellaneda-stoikov
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
avellaneda_stoikov-0.1.0.tar.gz -
Subject digest:
f7649416526b700e5ab40ad7a42ac8e3db3811a228e975dafb3d22965e250275 - Sigstore transparency entry: 2006284544
- Sigstore integration time:
-
Permalink:
Gavr625/avellaneda-stoikov@ea4adf5747a58f3d52edea4901edc1fededc1bfd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Gavr625
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea4adf5747a58f3d52edea4901edc1fededc1bfd -
Trigger Event:
push
-
Statement type:
File details
Details for the file avellaneda_stoikov-0.1.0-py3-none-any.whl.
File metadata
- Download URL: avellaneda_stoikov-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1279a49358e880731f0a74ce9e31c5d897c0a738a219188e2d2cad96c0430862
|
|
| MD5 |
1a1d2522107aa11406123a58f8dbf7a8
|
|
| BLAKE2b-256 |
22ff55bad1903703bc2a62c0a5a4aff34b973b4e92138ddc16d7dfd66f29bfc0
|
Provenance
The following attestation bundles were made for avellaneda_stoikov-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Gavr625/avellaneda-stoikov
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
avellaneda_stoikov-0.1.0-py3-none-any.whl -
Subject digest:
1279a49358e880731f0a74ce9e31c5d897c0a738a219188e2d2cad96c0430862 - Sigstore transparency entry: 2006284555
- Sigstore integration time:
-
Permalink:
Gavr625/avellaneda-stoikov@ea4adf5747a58f3d52edea4901edc1fededc1bfd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Gavr625
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea4adf5747a58f3d52edea4901edc1fededc1bfd -
Trigger Event:
push
-
Statement type: