feat(diffusion): add HestonProcess — stochastic volatility model with vectorised MC and analytical pricing - #82
Open
hass-nation wants to merge 1 commit into
Conversation
Implements the Heston (1993) bivariate stochastic volatility model: dS = μS dt + √V·S·dW^S dV = κ(θ−V) dt + σ√V·dW^V, Corr(dW^S, dW^V) = ρ dt New public API -------------- • sample(n) / sample_paths(n, paths) / sample_at(times) — simulation • 4 variance schemes: full-truncation (default), reflection, partial-truncation, quadratic-exponential (Andersen 2008) • Antithetic variates (exact mirror identity, no approximation) • expected_variance / variance_of_variance / expected_log_return — exact moments • characteristic_function(u, t) — Heston (1993) CF, exp(−dT) formulation • price_european(strike, r) — MC pricer with put-call parity • price_european_fft(r) — Carr-Madan FFT, 4096 strikes in ~0.5 ms • implied_vol_smile(r) — BS IV surface via Brent inversion • variance_swap_rate(t) — closed-form fair variance strike • realized_variance(path) — time-average of simulated variance • fit(log_returns, dt) — MLE calibration from return series • fit_to_smile(strikes, prices, r, t) — smile calibration via FFT Also adds Python type annotations to all 6 existing diffusion files (closes crflynn#62) and exports HestonProcess from the package __all__. Tests: 257 new tests across 28 test classes (674 total, 0 regressions) Coverage: 98% on heston.py mypy: clean (8 source files) Speedup: sample_paths ~36x faster than serial sample() calls Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the Heston (1993) stochastic volatility model to the diffusion process collection and addresses two long-standing issues:
stochastic.processes.diffusionmodule.Why Heston?
The Heston model is the industry-standard stochastic volatility model for options pricing and risk management:
DiffusionProcess(bivariate, correlated).stochasticuseful for the full options-pricing workflow.New Public API
Numerical Schemes
The Feller condition 2κθ > σ² is checked; a
UserWarningfires when violated (sampling still works).Performance
sample_paths(full-truncation)sample()price_european_fftFiles Changed
stochastic/processes/diffusion/heston.pytests/processes/diffusion/test_heston.pystochastic/processes/diffusion/__init__.pyHestonProcessstochastic/processes/diffusion/diffusion.pystochastic/processes/diffusion/extended_vasicek.pystochastic/processes/diffusion/vasicek.pystochastic/processes/diffusion/cox_ingersoll_ross.pystochastic/processes/diffusion/ornstein_uhlenbeck.pystochastic/processes/diffusion/constant_elasticity_variance.pyCHANGELOG.rstREADME.rstTests
References
🤖 Generated with Claude Code