xnonnormal_option_prices.py is a self-contained comparison harness that
computes European option prices (call/put/straddle), Black–Scholes implied
volatilities, and distribution moments when the terminal log-price or
price follows many different parametric families rather than the usual
normal law. xfit_distributions.py plus fit_distributions.py simulate data
from a configurable Gaussian mixture and fit several of the same families via
SciPy or bespoke MLE routines, saving fit diagnostics to CSV/PNG.
- Distribution catalog: normal, logistic,
Laplace (double exponential),
hyperbolic secant,
Champernowne,
generalized error (GED),
Johnson SU,
Tukey lambda,
hyperbolic,
generalized hyperbolic (GH),
variance gamma (VG),
normal-inverse Gaussian (NIG),
CGMY/tempered stable,
Natural Exponential Family - Generalized Hyperbolic Secant (NEF–GHS), generalized/secant hyperbolic (GSH/SGSH),
skew‑t (Jones–Faddy),
skew normal,
asymmetric Laplace, noncentral t, Student t, etc.
See
distributions.mdfor a table summarizing parameters, symmetry, and tail behavior,papers.mdfor research on pricing options with these distributions, andother_projects.mdfor related projects. - Option pricing: numeric integration of payoffs under the specified
density with consistent risk-neutral drifts and variance matching. The driver
defaults to pricing a straddle and back-solving the equivalent call price via
parity (use
option_typeto switch among"c","p", or"straddle"). - Log-return vs. price mode: set
log_price_mode/log_pricetoFalse(the default inxnonnormal_option_prices.py) to treat the requested family as a terminal-price distribution; the code currently supports normal, lognormal, Laplace, logistic, hypsecant, Champernowne, Tukey lambda, Weibull, generalized gamma, GB2, GED, Johnson SU, Student t, skew-t, noncentral t, CGMY, NIG, VG, GH, NEF-GHS, and the GSH/SGSH families in this mode. - Implied vols: converts the resulting call (or put/straddle via parity)
back to a Black–Scholes implied volatility using
scipy.optimize.brentq. - Diagnostics: tables of prices, implied vols, log-return and terminal-price moments, implied-vol smoothness metrics, plus optional plots saved to PNG.
- Data fitting:
xfit_distributions.pysimulates a Gaussian mixture, fits a list of candidate densities (SciPy + custom fits like CGMY, GSH, SGSH, NEF–GHS, VG), records fit statistics to CSV, and optionally plots true vs. fitted densities.
- Python 3.11+
numpy,pandas,scipy,matplotlib(for plotting)
Install dependencies with:
python -m pip install -r requirements.txt(Create requirements.txt if needed; current scripts only rely on NumPy,
Pandas, SciPy, and Matplotlib.)
python xnonnormal_option_prices.pyKey settings (all at the top of the file, no CLI flags yet):
s0,r,q,t,sigma: market inputs.option_type:"c","p", or"straddle"(default is"straddle").requested: list of distribution families to study (e.g.["normal", "hypsecant", "vg"]); setmax_distto truncate the list.- Distribution-specific parameter grids such as
vg_thetas,gh_shapes,sgsh_shapes, etc. strike_min/max/stepandstrike_table_stride(set stride to0to hide strike-by-strike tables and just emit summary statistics).log_price_modetoggles log-return vs. direct price densities.PLOT_*and CSV constants control whether prices/vols are printed, plotted, or saved (option_prices.csv,implied_vols.csv,density.png,vol.png).print_iv_statsoptionally summarizes implied-vol curvature stats by distribution.
Each run prints:
- Optional price and implied-volatility tables (depending on
strike_table_stride). - Log-return or terminal-price moment tables (matching
log_price_mode). - A "Terminal price moments" block (always shown).
- Diagnostics for any distributions that failed calibration/integration.
If PLOT_* filenames are set, density/volatility curves are saved instead of
shown. CSV files use the same labels as the console tables for easy filtering.
An example implied-vol plot generated by the script is shown below:
python xfit_distributions.pyWorkflow (matching the current script defaults):
- Simulates
nobs = 1000draws from a two-component Gaussian mixture[(0.1, -0.3, 3.0), (0.9, 0.3, 1.0)]. - Prints descriptive statistics for the sample.
- Fits each distribution listed in
candidates(["normal", "skew_normal", "gsh", "sgsh", "t", "nct"]by default) viafit_distribution. - Logs per-fit metrics (log-likelihood, KS statistic/p-value, parameter count, timing, and parameter estimates).
- Saves
fit_summary.csvwith standardized columns (distribution,scipy_name,loglike,mean_density, …,params,param_names) plusfit_densities.pngcomparing the empirical histogram, ground-truth mixture, and each fitted pdf.
Tweak nobs, components, candidates, or DENSITY_PLOT_FILE to explore
other scenarios. Custom fitters registered in fit_distributions.py’s
CUSTOM_FITTERS dictionary (CGMY, GSH, SGSH, NEF–GHS, VG, etc.) can be added
to the candidates list as needed.
- Custom MLE routines in
fit_distributions.pyare registered via theCUSTOM_FITTERSdictionary; add new entries there to extendxfit_distributions.py. - New option-pricing densities require:
- Implementing pdf/MGF/tail helpers inside
distributions.py. - Adding their pricing logic to
option_pricing.py. - Registering them in
xnonnormal_option_prices.py’srequestedbuilder.
- Implementing pdf/MGF/tail helpers inside
This is an exploratory research tool rather than production code. Numerical
integration tolerances, parameter grids, and plotting defaults are tuned for
robustness but can be slow for very heavy-tailed densities—feel free to adjust
quad_limit, strike grids, or distribution lists as needed.
Contributions and suggestions for additional distributions or calibration methods are welcome.
