Heston stochastic-volatility model: Monte Carlo simulation and option pricing
Project description
MCHeston
Heston stochastic-volatility model: Monte Carlo simulation and option pricing in pure Python (NumPy / SciPy).
Features
- Seven simulation schemes, all path-vectorised: Euler, Milstein, Quadratic-Exponential (QE), QE + martingale-correction (QE-M), Truncated-Gaussian (TG), TG + martingale-correction (TG-M), and Broadie-Kaya drift-interpolation.
- Three exact / semi-analytic pricers: Heston (1993) original Fourier inversion, the Albrecher et al. "Little Trap" stable formulation, and Carr-Madan damped-exponential.
- All exact methods agree to within 1e-10 on the Andersen (2008) reference prices.
Installation
pip install MCHeston
For development (tests, build tooling):
pip install MCHeston[dev]
Quick start
import numpy as np
from mcheston import HestonModel
# Define the model
model = HestonModel(
S0=100, # spot price
v0=0.04, # initial variance
r=0.0, # risk-free rate
kappa=0.5, # variance mean-reversion speed
theta=0.04, # long-run variance
sigma=1.0, # volatility of variance
rho=-0.9, # correlation
lambda_=0.0, # market price of vol risk
)
# Exact price via stable Fourier inversion
price, err = model.priceCallFourier(K=100, T=10.0, formulation="stable")
print(f"Exact price: {price:.4f}")
# Monte Carlo with the recommended QE-M scheme
rng = np.random.default_rng(seed=42)
price, std_err, ci_half, v_zero_count = model.priceCallMC(
K=100, T=10.0, n=80, num_paths=100_000, method="QEM", rng=rng,
)
print(f"MC price: {price:.4f} +/- {ci_half:.4f} (95% CI)")
API at a glance
HestonModel(S0, v0, r, kappa, theta, sigma, rho, lambda_=0.0,
gamma1=0.5, gamma2=0.5, alpha=4.5)
# Path simulation - all return (S_paths, v_zero_count)
model.simulateEuler(T, n, num_paths, rng=None)
model.simulateMilstein(T, n, num_paths, rng=None)
model.simulateQE(T, n, num_paths, C=1.5, rng=None)
model.simulateQEM(T, n, num_paths, C=1.5, rng=None)
model.simulateTG(T, n, num_paths, rng=None)
model.simulateTGM(T, n, num_paths, rng=None)
model.simulateBroadieKaya(T, n, num_paths, rng=None)
# Monte Carlo pricing
model.priceCallMC(K, T, n, num_paths, method, rng=None, conf_level=0.95)
# returns: (price, std_err, ci_half_width, v_zero_count)
# Exact pricing
model.priceCallFourier(K, T, formulation="stable", upper=200.0)
# returns: (price, numerical_error)
model.priceCallCarrMadan(K, T, alpha=1.5, upper=200.0, formulation="stable")
# returns: (price, numerical_error)
method for priceCallMC is one of:
"Euler", "Milstein", "QE", "QEM", "TG", "TGM", "BroadieKaya".
When to use which scheme
- QE-M is the recommended default. Fast, accurate, and robust to Feller violations.
- Broadie-Kaya has the smallest discretisation bias (it samples v_T from its exact non-central chi-squared distribution) but is slower per step.
- Euler / Milstein should not be used when the Feller condition
2*kappa*theta >= sigma^2is violated - they pick up large positive bias from the variance hitting zero.
References
- Heston, S. L. (1993). A closed-form solution for options with stochastic volatility with applications to bond and currency options. Review of Financial Studies, 6(2), 327-343.
- Andersen, L. B. G. (2008). Simple and efficient simulation of the Heston stochastic volatility model. Journal of Computational Finance, 11(3), 1-42.
- Broadie, M., & Kaya, O. (2006). Exact simulation of stochastic volatility and other affine jump diffusion processes. Operations Research, 54(2), 217-231.
- Albrecher, H., Mayer, P., Schoutens, W., & Tistaert, J. (2007). The little Heston trap. Wilmott Magazine, January, 83-92.
- Carr, P., & Madan, D. (1999). Option valuation using the fast Fourier transform. Journal of Computational Finance, 2(4), 61-73.
License
MIT. See LICENSE.
Author
Youssef Raad (@YoussefRaad-mathecon)
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 mcheston-0.1.0.tar.gz.
File metadata
- Download URL: mcheston-0.1.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9efe01772d1ecac1e2f77d7490921a1151a6ab6f1135ba75d4a26dd8be8fc69
|
|
| MD5 |
daabc10e2073eda59dceba5c0a6899aa
|
|
| BLAKE2b-256 |
23275e9b240b3914618d18d1913934f2dd88d2d0895f93b1b8fcc1b97d2c8f91
|
File details
Details for the file mcheston-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcheston-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33a763b1e94db1c06eee21126780d5ce8f77e21dc3ece67be33868acb2b8bc01
|
|
| MD5 |
db75ada36be84242eaad67ae8f2cdae3
|
|
| BLAKE2b-256 |
48c422a0c93fb8aae386d195d3b3f1b129f47a56297fff17b6afb2b7e5a8e583
|