Skip to main content

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

Metadata

Release files for riskneutral 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for riskneutral 0.1.2
File Size Uploaded Provenance Actions
riskneutral-0.1.2.tar.gz 19.2 kB Without provenance Details for riskneutral-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for riskneutral 0.1.2
File Interpreter ABI Platform Actions
riskneutral-0.1.2-py3-none-any.whl Python 3 none any Details for riskneutral-0.1.2-py3-none-any.whl

Total release size: 39.5 kB

Release files / riskneutral-0.1.2.tar.gz

Download URL riskneutral-0.1.2.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0b07de2d8046c8a95d769c712cd7c49432b44646d707c5bcade619484f5d3000
BLAKE2b-256 checksum
How to use checksums
26660710a4e4baeeff97c0a01b0270dbff3c427f3f92e0fd2faa4ffc37de5ff4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.14

Release files / riskneutral-0.1.2-py3-none-any.whl

Download URL riskneutral-0.1.2-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a082206ad259e3d7fe471c4eff591bf429e897157a62cf600d6cf5864949a58
BLAKE2b-256 checksum
How to use checksums
22e72bc70b8cf530f7bda5be1416f25c98f9c7d63013ddab4ed05c533f90491b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.14

Security for riskneutral 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page