Financial derivatives pricing via Chernoff operator splitting with certified error bounds
Project description
ChernoffPy
Option pricing with certified error bounds. Know how much to trust your price.
Most pricers give you a number. ChernoffPy gives you a number plus a provable upper bound on the error — no closed-form reference needed.
ChernoffPy prices European, barrier, American, Heston, and Bates options via Chernoff operator-splitting with convergence rates from Galkin-Remizov theory (2025). It is designed as a research and validation library — not a QuantLib replacement, but the only open-source tool that can tell you how wrong your numerical price might be.
Installation
pip install chernoffpy
pip install "chernoffpy[fast]"
pip install "chernoffpy[gpu]"
pip install "chernoffpy[all]"
Quick Start
European Option
from chernoffpy import CrankNicolson
from chernoffpy.finance import EuropeanPricer, MarketParams
market = MarketParams(S=100, K=100, T=1.0, r=0.05, sigma=0.20)
pricer = EuropeanPricer(CrankNicolson())
result = pricer.price(market, n_steps=50, option_type="call")
print(result.price)
Barrier Option (DST)
from chernoffpy import CrankNicolson
from chernoffpy.finance import BarrierDSTPricer, BarrierParams, MarketParams
market = MarketParams(S=100, K=100, T=1.0, r=0.05, sigma=0.20)
params = BarrierParams(barrier=90, barrier_type="down_and_out")
result = BarrierDSTPricer(CrankNicolson()).price(market, params, n_steps=80, option_type="call")
print(result.price)
Certified Error Bound
from chernoffpy import CrankNicolson
from chernoffpy.finance import CertifiedEuropeanPricer, MarketParams
market = MarketParams(S=100, K=100, T=1.0, r=0.05, sigma=0.20)
res = CertifiedEuropeanPricer(CrankNicolson()).price_certified(market, n_steps=50, option_type="call")
print(res.price, res.certified_bound.bound)
Price to Tolerance (adaptive)
Tell the library your accuracy requirement — it figures out the computation budget automatically:
from chernoffpy import CrankNicolson
from chernoffpy.finance import CertifiedEuropeanPricer, MarketParams, GridConfig
market = MarketParams(S=100, K=100, T=1.0, r=0.05, sigma=0.20)
grid = GridConfig(N=2048, L=12.0, taper_width=3.0)
pricer = CertifiedEuropeanPricer(CrankNicolson(), grid)
# "I need the price accurate to 1 cent"
result = pricer.price_to_tolerance(market, target_error=0.01, option_type="call")
print(f"Price: {result.price:.4f}")
print(f"Bound: {result.certified_bound.bound:.2e}")
print(f"Met: {result.verification['target_met']}")
Heston / Bates
from chernoffpy import CrankNicolson
from chernoffpy.finance import HestonFastPricer, BatesPricer, BatesParams
from chernoffpy.finance.heston_params import HestonParams
heston = HestonParams(S=100, K=100, T=1.0, r=0.05, v0=0.04, kappa=2.0, theta=0.04, xi=0.3, rho=-0.7)
print(HestonFastPricer(CrankNicolson()).price(heston, n_steps=50, option_type="call").price)
bates = BatesParams(S=100, K=100, T=1.0, r=0.05, v0=0.04, kappa=2.0, theta=0.04, xi=0.3, rho=-0.7,
lambda_j=0.5, mu_j=-0.1, sigma_j=0.2)
print(BatesPricer(CrankNicolson()).price(bates, n_steps=50, option_type="call").price)
Choosing the Right Pricer
Which pricer for which option type?
| Option type | Recommended pricer | Notes |
|---|---|---|
| European call/put | EuropeanPricer |
Fastest; use CertifiedEuropeanPricer for guaranteed error bounds |
| Single barrier (down/up, in/out) | BarrierDSTPricer |
Recommended — DST avoids Gibbs artifacts near barrier |
| Single barrier (high performance) | BarrierPricer |
FFT-based, slightly faster but possible Gibbs at barrier |
| Double barrier | DoubleBarrierDSTPricer |
DST, no artifacts; DoubleBarrierPricer for FFT variant |
| American (no dividends) | AmericanPricer |
Payoff projection method; use CrankNicolson() or PadeChernoff() |
| American (discrete dividends) | AmericanPricer + DividendSchedule |
Puts support absolute/proportional dividends; calls require proportional=True |
| Stochastic volatility (Heston) | HestonFastPricer |
Faster than HestonPricer; use HestonPricer only for custom grids |
| Jump-diffusion (Heston + jumps) | BatesPricer |
Heston model with Merton jump component |
| Local volatility | LocalVolPricer |
Dupire surface; use flat_vol, linear_skew, or custom LocalVolParams |
| With guaranteed error bound | CertifiedEuropeanPricer / CertifiedBarrierDSTPricer |
Returns certified_bound; use price_to_tolerance() for automatic accuracy control |
Which Chernoff function (scheme) to use?
| Scheme | Order | Stability | When to use |
|---|---|---|---|
BackwardEuler() |
O(1/n) | A-stable ✓ | Debugging, large time steps |
CrankNicolson() |
O(1/n²) | A-stable ✓ | Default choice — best speed/accuracy trade-off |
PadeChernoff(1, 2) |
O(1/n³) | A-stable ✓ | High accuracy, smooth payoffs |
PadeChernoff(2, 2) |
O(1/n⁴) | A-stable ✓ | Maximum accuracy |
PhysicalG() |
O(1/n) | A-stable ✓ | Explicit scheme, large grids |
PhysicalS() |
O(1/n²) | A-stable ✓ | Explicit, 2nd order |
PadeChernoff(2, 1) |
O(1/n²) | ⚠ NOT A-stable | Avoid — high-frequency divergence |
Rule of thumb: start with CrankNicolson(). Switch to PadeChernoff(1, 2) if you need tighter certified bounds.
Quick decision flowchart
Vanilla option? → EuropeanPricer
Needs error bound? → CertifiedEuropeanPricer
Barrier present? → BarrierDSTPricer (single)
→ DoubleBarrierDSTPricer (double)
Early exercise? → AmericanPricer
Discrete dividends? → AmericanPricer + DividendSchedule (calls: proportional only)
Stoch. volatility? → HestonFastPricer
Stoch. vol + jumps? → BatesPricer
Custom vol surface? → LocalVolPricer
Three Levels of Pricing
| API | What you get |
|---|---|
pricer.price(market, n_steps=50) |
A price |
pricer.price_certified(market, n_steps=50) |
A price + provable error bound |
pricer.price_to_tolerance(market, target_error=0.01) |
A price within your tolerance, automatically |
No other open-source option pricing library offers certified error bounds.
See examples/certified_pricing.ipynb for a full walkthrough.
Features
- European pricing and Greeks
- Barrier and double-barrier options (FFT and DST)
- American options with early exercise and discrete dividends (American calls support proportional dividends only)
- Local volatility and implied volatility
- Heston stochastic volatility and Bates jump-diffusion (with CFL stability guard)
- Calibration helpers (flat/skew/SVI)
- Certified error bounds based on Galkin-Remizov convergence rates
- Adaptive
price_to_tolerance()— automatic accuracy control - Accuracy warnings when grid may be too coarse for the requested regime
- Optional acceleration via Numba (
[fast])
Mathematical Basis
ChernoffPy uses the Chernoff product formula
exp(tL) f = lim_{n->inf} F(t/n)^n f
with practical schemes (Backward Euler, Crank-Nicolson, Padé).
Certified-bound utilities are motivated by convergence-rate estimates in
Galkin & Remizov (2025, Israel Journal of Mathematics).
Development
pip install -e ".[dev]"
pytest tests/ -q
References
- Chernoff, P. (1968), J. Functional Analysis.
- Galkin, O. & Remizov, I. (2025), Israel Journal of Mathematics.
- Butko, Ya. (2020), Lecture Notes in Mathematics.
License
MIT. See LICENSE.
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 chernoffpy-0.2.1.tar.gz.
File metadata
- Download URL: chernoffpy-0.2.1.tar.gz
- Upload date:
- Size: 63.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e616652befe8f3bf457ddf0624153feb52697ca026ead2623b8f53b5ee439187
|
|
| MD5 |
8f3021f754be0ea03b496fe74667c41f
|
|
| BLAKE2b-256 |
eb1a6a16457c2efdd2bcb2eb990fa04c7b2755c6657637a23c199227b67e5977
|
File details
Details for the file chernoffpy-0.2.1-py3-none-any.whl.
File metadata
- Download URL: chernoffpy-0.2.1-py3-none-any.whl
- Upload date:
- Size: 68.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
043626eb183f57b98f03eadf328003960112c091d80dbc5fda9ffe8d7da95c04
|
|
| MD5 |
7d358e691b0138c302dcfbabb1a8eabd
|
|
| BLAKE2b-256 |
ac66ffb84dac0c524725748e947e46f34700bb5edec03ba55805146033f6d524
|