Skip to main content

ChernoffPy

Option pricing with certified error bounds. Know how much to trust your price.

CI PyPI Python Coverage License: MIT

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

  1. Chernoff, P. (1968), J. Functional Analysis.
  2. Galkin, O. & Remizov, I. (2025), Israel Journal of Mathematics.
  3. Butko, Ya. (2020), Lecture Notes in Mathematics.

License

MIT. See LICENSE.

Metadata

Release files for chernoffpy 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chernoffpy 0.2.1
File Size Uploaded Provenance
chernoffpy-0.2.1.tar.gz 63.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for chernoffpy 0.2.1
File Interpreter ABI Platform
chernoffpy-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 131.4 kB

Release files / chernoffpy-0.2.1.tar.gz

Download URL chernoffpy-0.2.1.tar.gz
Size 63.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e616652befe8f3bf457ddf0624153feb52697ca026ead2623b8f53b5ee439187
BLAKE2b-256 checksum
How to use checksums
eb1a6a16457c2efdd2bcb2eb990fa04c7b2755c6657637a23c199227b67e5977
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / chernoffpy-0.2.1-py3-none-any.whl

Download URL chernoffpy-0.2.1-py3-none-any.whl
Size 68.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
043626eb183f57b98f03eadf328003960112c091d80dbc5fda9ffe8d7da95c04
BLAKE2b-256 checksum
How to use checksums
ac66ffb84dac0c524725748e947e46f34700bb5edec03ba55805146033f6d524
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for chernoffpy 0.2.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page