Skip to main content

Financial derivatives pricing via Chernoff operator splitting with certified error bounds

Project description

ChernoffPy

Financial derivatives pricing via Chernoff operator splitting with certified error bounds.

CI PyPI Python Coverage License: MIT

ChernoffPy prices options by applying Chernoff product formulas to transformed pricing PDEs. The library includes European, barrier, double-barrier, American, Heston, and Bates pricing, plus calibration tools and certified error-bound utilities.

Project Documents

For package usage, start with this README and the docs in docs/.

For project-level governance and audit state, use:

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)

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 alongside price

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

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
  • Calibration helpers (flat/skew/SVI)
  • Certified bounds based on Chernoff convergence rates
  • 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.

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

chernoffpy-0.2.0.tar.gz (58.1 kB view details)

Uploaded Source

Built Distribution

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

chernoffpy-0.2.0-py3-none-any.whl (64.2 kB view details)

Uploaded Python 3

File details

Details for the file chernoffpy-0.2.0.tar.gz.

File metadata

  • Download URL: chernoffpy-0.2.0.tar.gz
  • Upload date:
  • Size: 58.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chernoffpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e8e4b432a504cbd94a1a67a6bb1a4c2999ef348e54dfff131831141e5e120339
MD5 876b14b768cf6a4107e2042ddb52c5b0
BLAKE2b-256 5bac62cf8548de9895bf74f90e0f7d6828fca34ccd6c18d8c93d8f05a0c9c6dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for chernoffpy-0.2.0.tar.gz:

Publisher: ci.yml on sergeeey/MarkovChains

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

File details

Details for the file chernoffpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: chernoffpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 64.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chernoffpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 218e1d53713ee3055aebdad5a25c7619bf30cf7d5033370cfe60726d44122def
MD5 458791e68102394c1fb4427018727d66
BLAKE2b-256 49002fc61a30c607d7eec3340dae82860af41426513f2dd2cd790936229d9818

See more details on using hashes here.

Provenance

The following attestation bundles were made for chernoffpy-0.2.0-py3-none-any.whl:

Publisher: ci.yml on sergeeey/MarkovChains

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