Skip to main content

Risk-Neutral Density Estimation Tools

Project description

risk-neutral

PyPI version Python Version Build Status Coverage Status 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

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.0.tar.gz (3.7 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.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: riskneutral-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 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.0.tar.gz
Algorithm Hash digest
SHA256 6a106b1c1a63067bfe91ee4f40e8d8e0e59a9255e4ad2880da0bcc8bffc31b03
MD5 ea99f85d046885d52d512eb9cd43e7b4
BLAKE2b-256 c72c69cf56a0a175844f64a6ea5164a8d538c200b28acff906f3ccd59f195eed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: riskneutral-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa24f7f75bc546f932d874a3d2f1a31d5e572897bd8a2ca5548b177db73fc238
MD5 b963fe4aba3f5312058080d664a3c19b
BLAKE2b-256 4e4d84bb83f55d398599fab3e82db39985659eaf1d47f34ee648900d57778ec4

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