ArturSepp
StochVolModels
Python

Python implementation of pricing analytics and Monte Carlo simulations for stochastic volatility models including log-normal SV model, Heston

Last updated Jul 9, 2026
225
Stars
45
Forks
0
Issues
+1
Stars/day
Attention Score
90
Language breakdown
Python 100.0%
โ–ธ Files click to expand
README

๐Ÿš€ StochVolModels Package: stochvolmodels

stochvolmodels package implements pricing analytics and Monte Carlo simulations for valuation of European call and put options and implied volatilities of different stochastic volatility models including Karasinski-Sepp log-normal stochastic volatility model and Heston stochastic volatility model.

| ๐Ÿ“Š Metric | ๐Ÿ”ข Value | |-----------|----------| | PyPI Version | PyPI | | Python Versions | Python | | License | License| | CI Status | CI |

๐Ÿ“ˆ Package Statistics

| ๐Ÿ“Š Metric | ๐Ÿ”ข Value | |-----------|----------| | Total Downloads | Total | | Monthly | Monthly | | Weekly | Weekly | | GitHub Stars | GitHub stars | | GitHub Forks | GitHub forks |

StochVolModels

The StochVol package provides: 1) Analytics for Black-Scholes and Normal vols 2) Interfaces and implementation for stochastic volatility models, including Karasinski-Sepp log-normal SV model and Heston SV model using analytical method with Fourier transform and Monte Carlo simulations 3) Visualization of model implied volatilities

For the analytic implementation of stochastic volatility models, the package provides interfaces for a generic volatility model with the following features. 1) Interface for analytical pricing of vanilla options using Fourier transform with closed-form solution for moment generating function 2) Interface for Monte-Carlo simulations of model dynamics

Illustrations of using package analytics for research work is provided in top-level package

which contains computations and visualisations for several papers

Installation

Install using
pip install stochvolmodels
Upgrade using
pip install --upgrade stochvolmodels
Clone using
git clone https://github.com/ArturSepp/StochVolModels.git

Core Dependencies

  • python >= 3.8
  • numba >= 0.56.4
  • numpy >= 1.22.4
  • scipy >= 1.10
  • pandas >= 2.2.0
  • matplotlib >= 3.2.2
  • seaborn >= 0.12.2
Optional dependencies: qis ">=2.3.1" (for running code in my_papers)

Table of contents

1. Log-normal stochastic volatility model 2. Heston stochastic volatility model 1. Computing model prices and vols 2. Running model calibration to sample Bitcoin options data 3. Comparison of model prices vs MC 4. Analysis and figures for the paper

Running model calibration to sample Bitcoin options data

Implemented Stochastic Volatility models

The package provides interfaces for a generic volatility model with the following features. 1) Interface for analytical pricing of vanilla options using Fourier transform with closed-form solution for moment generating function 2) Interface for Monte-Carlo simulations of model dynamics 3) Interface for visualization of model implied volatilities

The model interface is in stochvolmodels/pricers/model_pricer.py

Log-normal stochastic volatility model

The analytics for Karasinski-Sepp log-normal stochastic volatility model is based on the paper

Log-normal Stochastic Volatility Model with Quadratic Drift by Artur Sepp and Parviz Rakhmonov

The dynamics of the log-normal stochastic volatility model:

$$dS{t}=r(t)S{t}dt+\sigma{t}S{t}dW^{(0)}_{t}$$

$$d\sigma{t}=\left(\kappa{1} + \kappa{2}\sigma{t} \right)(\theta - \sigma{t})dt+ \beta \sigma{t}dW^{(0)}{t} + \varepsilon \sigma{t} dW^{(1)}_{t}$$

$$dI{t}=\sigma^{2}{t}dt$$

where $r(t)$ is the deterministic risk-free rate; $W^{(0)}{t}$ and $W^{(1)}t$ are uncorrelated Brownian motions, $\beta\in\mathbb{R}$ is the volatility beta which measures the sensitivity of the volatility to changes in the spot price, and $\varepsilon>0$ is the volatility of residual volatility. We denote by $\vartheta^{2}$, $\vartheta^{2}=\beta^{2}+\varepsilon^{2}$, the total instantaneous variance of the volatility process.

Implementation of Lognormal SV model is contained in

stochvolmodels/pricers/logsv_pricer.py

Heston stochastic volatility model

The dynamics of Heston stochastic volatility model:

$$dS{t}=r(t)S{t}dt+\sqrt{V{t}}S{t}dW^{(S)}_{t}$$

$$dV{t}=\kappa (\theta - V{t})dt+ \vartheta \sqrt{V{t}}dW^{(V)}{t}$$

where $W^{(S)}$ and $W^{(V)}$ are correlated Brownian motions with correlation parameter $\rho$

Implementation of Heston SV model is contained in

stochvolmodels/pricers/heston_pricer.py

Running log-normal SV pricer

Basic features are implemented in

examples/runlognormalsv_pricer.py

Imports:

import numpy as np  import stochvolmodels as sv from stochvolmodels import LogSVPricer, LogSvParams, OptionChain

Computing model prices and vols

# instance of pricer
logsv_pricer = LogSVPricer()

define model params

params = LogSvParams(sigma0=1.0, theta=1.0, kappa1=5.0, kappa2=5.0, beta=0.2, volvol=2.0)

1. compute the price

modelprice, vol = logsvpricer.price_vanilla(params=params, ttm=0.25, forward=1.0, strike=1.0, opti) print(f"price={model_price:0.4f}, implied vol={vol: 0.2%}")

2. prices for slices

modelprices, vols = logsvpricer.price_slice(params=params, ttm=0.25, forward=1.0, strikes=np.array([0.9, 1.0, 1.1]), optiontypes=np.array(['P', 'C', 'C'])) print([f"{p:0.4f}, implied vol={v: 0.2%}" for p, v in zip(model_prices, vols)])

3. prices for option chain with uniform strikes

optionchain = OptionChain.getuniform_chain(ttms=np.array([0.083, 0.25]), ids=np.array(['1m', '3m']), strikes=np.linspace(0.9, 1.1, 3)) modelprices, vols = logsvpricer.computechainpriceswithvols(optionchain=optionchain, params=params) print(model_prices) print(vols)

Running model calibration to sample Bitcoin options data

btcoptionchain = chains.getbtctestchaindata()
params0 = LogSvParams(sigma0=0.8, theta=1.0, kappa1=5.0, kappa2=None, beta=0.15, volvol=2.0)
btccalibratedparams = logsvpricer.calibratemodelparamstochain(optionchain=btcoptionchain,
                                                                    params0=params0,
                                                                    constraintstype=ConstraintsType.INVERSEMARTINGALE)
print(btccalibratedparams)

logsvpricer.plotmodelivolsvsbidask(optionchain=btcoption_chain, params=btccalibratedparams)

image info

Comparison of model prices vs MC

btcoptionchain = chains.getbtctestchaindata()
uniformchaindata = OptionChain.touniformstrikes(obj=btcoptionchain, num_strikes=31)
btccalibratedparams = LogSvParams(sigma0=0.8327, theta=1.0139, kappa1=4.8609, kappa2=4.7940, beta=0.1988, volvol=2.3694)
logsvpricer.plotcompmmainverseoptionswithmc(optionchain=uniformchaindata,
                                                  params=btccalibratedparams,
                                                  nb_path=400000)
image info

Analysis and figures for the paper

All figures shown in the paper can be reproduced using py scripts in

examples/plotsforpaper

Running Heston SV pricer

Examples are implemented here

examples/runhestonsv_pricer.py examples/run_heston.py

Content of run_heston.py

import numpy as np import matplotlib.pyplot as plt from stochvolmodels import HestonPricer, HestonParams, OptionChain

define parameters for bootstrap

params_dict = {'rho=0.0': HestonParams(v0=0.22, theta=0.22, kappa=4.0, volvol=0.75, rho=0.0), 'rho=-0.4': HestonParams(v0=0.22, theta=0.22, kappa=4.0, volvol=0.75, rho=-0.4), 'rho=-0.8': HestonParams(v0=0.22, theta=0.22, kappa=4.0, volvol=0.75, rho=-0.8)}

get uniform slice

optionchain = OptionChain.getuniform_chain(ttms=np.array([0.25]), ids=np.array(['3m']), strikes=np.linspace(0.8, 1.15, 20)) optionslice = optionchain.get_slice(id='3m')

run pricer

pricer = HestonPricer() pricer.plotmodelslicesinparams(optionslice=optionslice, paramsdict=paramsdict)

plt.show()

Supporting Illustrations for Public Papers

As illustrations of different analytics, this package includes module

with codes for computations and visualisations featured in several papers for

1) "Log-normal Stochastic Volatility Model with Quadratic Drift" by Artur Sepp and Parviz Rakhmonov: https://www.worldscientific.com/doi/10.1142/S0219024924500031

stochvolmodels/mypapers/logsvmodelwtihquadratic_drift

2) "What is a robust stochastic volatility model" by Artur Sepp and Parviz Rakhmonov, SSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4647027

stochvolmodels/mypapers/volatilitymodels

3) "Valuation and Hedging of Cryptocurrency Inverse Options" by Artur Sepp and Vladimir Lucic, SSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4606748

stochvolmodels/mypapers/inverseoptions

4) "Unified Approach for Hedging Impermanent Loss of Liquidity Provision" by Artur Sepp, Alexander Lipton and Vladimir Lucic, SSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4887298

stochvolmodels/mypapers/ilhedging

5) "Stochastic Volatility for Factor Heath-Jarrow-Morton Framework" by Artur Sepp and Parviz Rakhmonov, SSRN: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4646925

stochvolmodels/mypapers/svforfactorhjm

Project Structure

StochVolModels/
โ”œโ”€โ”€ stochvolmodels/
โ”‚   โ”œโ”€โ”€ pricers/
โ”‚   โ”‚   โ”œโ”€โ”€ model_pricer.py         # Generic model interface
โ”‚   โ”‚   โ”œโ”€โ”€ logsv_pricer.py         # Log-normal SV implementation  
โ”‚   โ”‚   โ””โ”€โ”€ heston_pricer.py        # Heston SV implementation
โ”‚   โ”œโ”€โ”€ data/
โ”‚   โ”‚   โ””โ”€โ”€ option_chain.py         # Option chain data structures
โ”‚   โ””โ”€โ”€ my_papers/                  # Research paper implementations
โ”‚       โ”œโ”€โ”€ logsvmodelwithquadraticdrift/
โ”‚       โ”œโ”€โ”€ volatility_models/
โ”‚       โ”œโ”€โ”€ inverse_options/
โ”‚       โ”œโ”€โ”€ il_hedging/
โ”‚       โ””โ”€โ”€ svforfactor_hjm/
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ runlognormalsv_pricer.py
โ”‚   โ”œโ”€โ”€ runhestonsv_pricer.py
โ”‚   โ”œโ”€โ”€ run_heston.py
โ”‚   โ””โ”€โ”€ plotsforpaper/
โ””โ”€โ”€ README.md

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this package in your research, please cite the relevant papers:

@misc{sepp2024stochvolmodels,
  title={StochVolModels: Python Implementation of Stochastic Volatility Models},
  author={Sepp, Artur},
  year={2024},
  howpublished={\url{https://github.com/ArturSepp/StochVolModels}},
  note={Python package for pricing analytics and Monte Carlo simulations}
}

@article{sepprakhmonov2023, title={Log-normal stochastic volatility model with quadratic drift}, author={Sepp, Artur and Rakhmonov, Parviz}, journal={International Journal of Theoretical and Applied Finance}, volume={26}, number={8}, year={2023}, url={https://www.worldscientific.com/doi/epdf/10.1142/S0219024924500031} }

@article{sepprakhmonov2023b, title={What is a robust stochastic volatility model}, author={Sepp, Artur and Rakhmonov, Parviz}, year={2023}, note={Working paper}, url={http://ssrn.com/abstract=4647027} }

@article{lucicsepp2024, title={Valuation and hedging of cryptocurrency inverse options}, author={Lucic, Vladimir and Sepp, Artur}, journal={Quantitative Finance}, volume={24}, number={7}, pages={851--869}, year={2024}, url={https://www.tandfonline.com/doi/full/10.1080/14697688.2024.2364804} }

@article{sepprakhmonov2024, title={Stochastic volatility for factor Heath-Jarrow-Morton framework}, author={Sepp, Artur and Rakhmonov, Parviz}, year={2025}, journal={Review of Derivatives Research}, note={Accepted}, url={http://ssrn.com/abstract=4646925} }

Acknowledgments

Special thanks to co-authors and collaborators:

  • Parviz Rakhmonov
  • Vladimir Lucic
  • Alexander Lipton
For additional research and advanced analytics, see the companion modules and papers included in this package.

BibTeX Citations for StochVolModels (Stochastic Volatility Models) Package

If you use StochVolModels in your research, please cite it as:

@software{stochvolmodels2024,
  author={Sepp, Artur},
  title={StochVolModels: Python implementation of pricing analytics and Monte Carlo simulations for stochastic volatility models},
  year={2024},
  url={https://github.com/ArturSepp/StochVolModels},
}
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท ArturSepp/StochVolModels ยท Updated daily from GitHub