End-to-end Dupire local-volatility modeling pipeline on an SPX option chain snapshot. Starts from raw quotes, infers the forward/discount curve from put-call parity, fits an arbitrage-aware SVI implied-variance surface, derives the Dupire local volatility, prices vanillas under the local-vol model with both Monte Carlo and a Crank–Nicolson PDE, and validates the PDE Greeks against Black–Scholes.
Local_Volatility/
├── data/
│ └── data.csv # SPX option chain snapshot (one or more quote dates)
├── src/local_vol/ # Library code (importable as `local_vol`)
│ ├── config.py # Calibration knobs and Dupire safety floors
│ ├── data_loader.py # Load + clean the option chain
│ ├── black_scholes.py # BS pricer, vega, delta, full greeks
│ ├── forward_curve.py # Parity-implied F(T), D(T), r_eff, q_eff (+ diagnostics)
│ ├── implied_vol.py # Solve implied vols from mid/bid/ask prices
│ ├── smile.py # Build OTM smile (best-side selection)
│ ├── svi.py # Quasi-explicit SVI calibration with arbitrage penalties
│ ├── local_volatility.py # Dupire local vol from SVI + LV interpolator
│ ├── pricing.py # MC + Crank–Nicolson PDE pricers under LV
│ ├── greeks.py # PDE finite-difference greeks
│ ├── evaluation.py # Pricing-error diagnostics vs market
│ ├── validation.py # PDE-recovers-BS unit tests
│ └── plotting.py # Smile / surface / 3D plots
├── notebooks/
│ ├── 01_data_exploration.ipynb
│ ├── 02_forward_and_iv.ipynb
│ ├── 03_svi_calibration.ipynb
│ ├── 04_local_vol_surface.ipynb
│ ├── 05_pde_pricing.ipynb
│ └── 06_greeks_validation.ipynb
├── scripts/
│ └── run_full_pipeline.py # End-to-end command-line entry point
├── requirements.txt
└── README.md
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Run the full pipeline on the snapshot in data/data.csv
python scripts/run_full_pipeline.py --data data/data.csvOr open the notebooks under notebooks/ and step through the analysis.
- Preprocess the option chain: filter crossed quotes, compute mids, spreads, log-moneyness, and time-to-maturity.
- Infer F(T), D(T) for each maturity by fitting
C-P ≈ pv * (F - K)on near-ATM strikes (put-call parity). - Recompute implied vols from mid / bid / ask prices using the inferred forward and discount, providing per-quote IV bid/ask spreads used as calibration weights.
- Build the OTM smile: for each (T, K), keep the OTM side; near ATM pick the side with the tighter bid/ask spread.
- Calibrate SVI in the quasi-explicit
(a, p, q, m, η)form per maturity, with penalties for:- Negative risk-neutral density (Gatheral butterfly),
- Roger-Lee wing slopes
b(1 ± ρ) > 2, - Calendar crossedness against the previous slice.
- Compute Dupire local vol via numerical derivatives of total variance
w(T, y); enforce calendar arbitrage-freeness via isotonic regression inTpery-column. - Price under local vol using either a log-Euler Monte Carlo or a
Crank–Nicolson PDE in
x = ln(S/S0). - Validate the PDE against Black–Scholes for constant sigma (recovers prices and the four major greeks).
data/data.csv is an SPX option chain snapshot with bid/ask/IV/greek columns
per (QUOTE_DATE, EXPIRE_DATE, K). The loader cleans bracketed column
names (e.g. [C_IV]) and converts IV percent values to decimals
automatically.