Skip to main content

Risk-Neutral Density Estimation Tools

Project description

risk-neutral

PyPI version Python Version License: MIT

Risk-Neutral Density Estimation Tools

A Python library for pricing options under various risk-neutral density assumptions, computing option-implied densities, and extracting model parameters from market data.

Features

  • Option Pricers: Black–Scholes–Merton (BSM), Mixture of Log-Normals for American Options (AMLN), Edgeworth Expansion (EW), Shimko Spline Method, and Mixture of Log-Normals (MLN).
  • Density Models: Compute risk-neutral probability density functions for priced assets under different distributional assumptions.
  • Density Extraction: Calibrate density model parameters to market option prices via optimization (BSM, AM, EW, MLN) or direct implied-volatility inversion (Shimko).
  • Utilities: Implied volatility computation (compute_implied_vol), volatility-curve fitting (fit_iv_curve).

Installation

Simply

pip install riskneutral

or

pip install git+https://github.com/Moe-Dada/risk_neutral.git

Or clone and install locally:

git clone https://github.com/Moe-Dada/risk_neutral.git
cd risk_neutral
pip install .

Quickstart

Option Pricing

from riskneutral.core_pricing import MarketParams, BSMParams, BSMPricer

# Market parameters: spot, risk-free rate, dividend yield
data = MarketParams(s0=100.0, r=0.05, y=0.02)
# BSM parameters: strike, time to expiry, volatility
params = BSMParams(k=100.0, te=1.0, sigma=0.2)
pricer = BSMPricer(market=data, params=params)
prices = pricer.price()
print(prices)  # {'d1': ..., 'd2': ..., 'call': ..., 'put': ...}

Switch pricer class for different models:

  • AMPricer (Mixture of Log-Normals for American Options)
  • EWPricer (Edgeworth Expansion)
  • ShimkoPricer (Shimko Spline Method)
  • MLNPricer (Mixture of Log-Normals)

Density Computation

import numpy as np
from riskneutral.density_computations import EwDensity, EWParams, MarketParams

mp = MarketParams(s0=100.0, r=0.05, y=0.02)
params = EWParams(k=100.0, te=1.0, sigma=0.2, skew=0.0, kurt=3.0)
model = EwDensity(market=mp, params=params)
x = np.linspace(50, 150, 200)
pdf = model.pdf(x)

Other density classes:

  • ShimkoDensity (local-volatiltity skew)
  • AmDensity (mixture-lognormal)
  • MlnDensity (two-component lognormal mixture)

Density Extraction

import numpy as np
from riskneutral.density_extraction import DensityData, BsmDensityExtractor, BsmExtractConfig
from riskneutral.core_pricing import BSMPricer, BSMParams, MarketParams

# Simulate market option prices under BSM
r, y, te, s0, sigma = 0.03, 0.01, 0.5, 100.0, 0.25
strikes = np.array([90, 100, 110])
market_calls = np.array([
    BSMPricer(MarketParams(s0, r, y), BSMParams(K, te, sigma)).price()["call"]
    for K in strikes
])

data = DensityData(
    r=r, y=y, te=te, s0=s0,
    market_calls=market_calls,
    call_strikes=strikes
)
extractor = BsmDensityExtractor(data, BsmExtractConfig(lam=0.0))
result = extractor.extract()
print("Estimated mu, zeta:", result.params)

For other extractors, see AmDensityExtractor, EwDensityExtractor, MlnDensityExtractor, or use ShimkoDirectExtractor for implied-volatility-based extraction.

Examples

  • See the examples/ folder for complete scripts demonstrating pricing, density computation, and extraction workflows.
  • See examples/examples_density_computations_and_plots.py for density plots.

For example:

  • Shimko's Spline Method: shimko_density_plot
  • Mixture of Log-Normals: mln_density_plot
  • Edgeworth's Expansion: ew_density_plot
  • Mixture of Log-Normals for American Optionamerican_mln_density_plot

Testing

Run the full test suite with:

pytest

Contributing

Contributions and issues are welcome! Please open an issue or submit a pull request on GitHub.

License

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

References

  • Prof. Kam Hamdieh @ [https://profiles.rice.edu/faculty/kam-hamidieh], Hamidieh, K., 2014. Estimating the tail shape parameter from option prices. Available at SSRN 1940117.
  • Dada, Moses O (2025) Three essays on volatility and tail-risk. Doctoral thesis, University of Essex. DOI [https://doi.org/10.5526/ERR-00040865]
  • E. Jondeau and S. Poon and M. Rockinger (2007): Financial Modeling Under Non-Gaussian Distributions Springer-Verlag, London
  • R. Jarrow and A. Rudd (1982) Approximate valuation for arbitrary stochastic processes. Journal of Finanical Economics, 10, 347-369
  • C.J. Corrado and T. Su (1996) S&P 500 index option tests of Jarrow and Rudd’s approximate option valuation formula. Journal of Futures Markets, 6, 611-629

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

riskneutral-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

riskneutral-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file riskneutral-0.1.1.tar.gz.

File metadata

  • Download URL: riskneutral-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for riskneutral-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7486d196e228217ebb71bd89601955b0317b3521918aac72acef66a8254b2823
MD5 2037c6bfca0fa8e8be5861d10e65ab15
BLAKE2b-256 58d3a9b82fe0e3527b3b88654b000da48af6cb1d0440175fabb6d50b59233e9d

See more details on using hashes here.

File details

Details for the file riskneutral-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: riskneutral-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for riskneutral-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 816ad485363bcfb02529377ee066f07a751697098a5276f0dc5388f0803c559a
MD5 5f780dead6aa410d4f29cf201d3298d6
BLAKE2b-256 3832bbca830da0a20fc71d31728f77d24686b9a7773048ec33979bb29bd383c9

See more details on using hashes here.

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