volsurface
Build an arbitrage-free implied volatility surface from raw option quotes, then extract Dupire local volatility for pricing path-dependent products.
Pipeline: raw bid/ask quotes → cleaning → implied forwards and discount factors from put-call parity → OTM implied vols → per-expiry SVI smiles → global SSVI and eSSVI surfaces → static-arbitrage checks → Dupire local vol.
Quickstart
pip install volsurface-lab # from PyPI; the import is still `import volsurface`
pip install -e ".[dev]" # or, from a clone, for development
pytest
python examples/synthetic_demo.py # offline, against a known true surface
python examples/snapshot.py # save today's CBOE ^SPX / ^NDX close to data/ (any time)
python examples/real_data_study.py # fit every saved snapshot (M3)
from volsurface import fit_surface, fit_errors
from volsurface.data import load_cboe_chain
quotes, spot, as_of = load_cboe_chain("^SPX") # or load_yfinance_chain (pip install -e ".[data]")
fit = fit_surface(quotes, spot, max_rel_spread=0.3)
print(fit.ssvi_params, fit.ssvi_arbitrage.summary())
print(fit_errors(fit))
fit.ssvi_surface.implied_vol(K=0.9 * spot, T=1.0)
fit.ssvi_surface.local_vol(K=0.9 * spot, T=1.0)
Method
Forwards from the market, not from assumptions. For each expiry, put-call parity C − P = DF·(F − K) is linear in strike, so a regression on near-the-money strikes gives the discount factor (−slope) and forward (intercept/DF). Dividend and funding assumptions are therefore implied by the options themselves.
OTM quotes only. Out-of-the-money options are the most liquid, and for American-style options they carry the least early-exercise premium. Implied vols are computed for bid, mid, and ask so fit quality can be judged against the spread.
SVI per expiry (Gatheral 2004): w(k) = a + b(ρ(k − m) + √((k − m)² + σ²)), where w is total implied variance and k = ln(K/F). The fit is vega-weighted, multi-start, and penalises negative variance and violations of Roger Lee's wing bound b(1 + |ρ|) ≤ 2.
SSVI surface (Gatheral & Jacquier 2014) with power-law curvature φ(θ) = η / (θ^γ (1 + θ)^(1−γ)). The ATM total-variance term structure θ(T) is taken from the SVI slices, forced to be non-decreasing, and interpolated in T with a monotone cubic (PCHIP), so it is continuously differentiable and the local vol has no jumps at the expiries. η is reparameterised as η = s·2/(1 + |ρ|), s ∈ (0, 1], so every candidate satisfies the no-arbitrage bound η(1 + |ρ|) ≤ 2, γ ≤ ½. The fitted surface is free of static arbitrage by construction.
eSSVI (Hendriks & Martini 2019) lets the skew vary with maturity: ρ(θ) = ρ₀ + (ρ₁ − ρ₀)·√min(θ/θ_ref, 1). Every slice stays butterfly-free through η = s·2/(1 + max(|ρ₀|, |ρ₁|)). Calendar arbitrage is no longer excluded by construction, so a decrease of w in θ is penalised during the fit and reported by the diagnostics. The fit starts from the SSVI solution, so its total weighted error is never worse than SSVI's.
Arbitrage-free SVI (after Gatheral & Jacquier 2014, §5) for the steep SPX put wing that
no single SSVI can reach. Each expiry gets its own 5-parameter SVI slice, started from the
eSSVI slice (an SSVI slice is exactly an SVI slice). Slices are fitted from the longest
expiry down, so each shorter slice only has to stay below the next longer one, and with
residuals in implied-vol units so low-vega wing quotes count. Butterfly (g ≥ margin) and
calendar (w ≤ next slice − margin) violations are penalised on k = z·√θ, z ∈ [−6, 4]
standard deviations, the region prices and paths reach; any slice still infeasible on a
fine grid is refitted with a 10× penalty. Between expiries w(k, ·) is a monotone cubic
(PCHIP) at each k. For local vol, fit.local_vol_surface() keeps pillar expiries at least
1.5× apart: interpolating exactly through weeklies a few days apart turns tiny noise in w
into swings in ∂_T w.
Arbitrage diagnostics. Butterfly arbitrage via Gatheral's density function g(k) ≥ 0 on each slice; calendar arbitrage via w(k, T) non-decreasing in T at fixed k. The pipeline checks every model on the same z ∈ [−6, 4] standard-deviation domain.
Dupire local volatility from total variance:
σ²_loc = ∂_T w / [1 − (k/w)∂_k w + ¼(−¼ − 1/w + k²/w²)(∂_k w)² + ½ ∂²_k w]
computed by finite differences on the fitted surface, returning NaN wherever the surface admits arbitrage (negative numerator or denominator).
Validation
The synthetic chain generator prices options off a known SSVI surface, adds noise and a bid-ask spread, and rounds to the tick, so every stage can be checked against the truth:
| Check | Result (noisy synthetic chain) |
|---|---|
| SSVI ρ / η / γ (true −0.70 / 1.00 / 0.40) | −0.699 / 1.002 / 0.399 |
| SSVI RMSE | 0.02–0.12 vol points per expiry |
| Model vols inside bid-ask band | 100% |
| Static arbitrage | none (SVI slices, SSVI, eSSVI) |
On a chain whose skew flattens with maturity (true ρ₀ / ρ₁ = −0.85 / −0.45), constant-ρ SSVI can no longer fit:
| Check | SSVI | eSSVI |
|---|---|---|
| ρ₀ / ρ₁ | −0.484 (single ρ) | −0.837 / −0.447 |
| Mean RMSE | 0.54 vol points | 0.06 vol points |
| Model vols inside bid-ask band | 54% | 100% |
| Static arbitrage | none | none |
Unit tests also cover implied-vol round trips, parity recovery of forwards and discount factors, SVI and SSVI parameter recovery, detection of Axel Vogt's known butterfly-arbitrage SVI counterexample, detection of crossed slices (calendar arbitrage), and local vol equalling implied vol on a flat surface.
Real data (M3): SPX and NDX, CBOE close of 2026-10-30
| SPX | NDX | |
|---|---|---|
| Quotes → OTM implied vols | 24,550 → 10,132 (47 expiries) | 14,186 → 3,380 (36 expiries) |
| ATM vol 1m / 1y | 14.9% / 17.1% | 24.2% / 23.1% |
| SSVI ρ / η / γ | −0.55 / 1.24 / 0.50 | −0.46 / 1.26 / 0.46 |
| eSSVI ρ₀ → ρ₁ | −0.68 → −0.53 | −0.53 → −0.44 |
| Median RMSE, SVI / SSVI / eSSVI / arb-free SVI (vol pts) | 0.20 / 2.25 / 2.27 / 0.20 | 0.14 / 0.84 / 0.73 / 0.18 |
| RMSE beyond −2 sd, eSSVI → arb-free SVI | 7.43 → 0.27 | 3.95 → 6.13 (3 quotes) |
| Static arbitrage, free SVI slices | 485 calendar violations, butterfly | 1,213 calendar violations, butterfly |
| Static arbitrage, SSVI, eSSVI, arb-free SVI | none | none |
Standard-deviation bands use z = k/√w, each quote's distance from the money in its own
standard deviations; examples/real_data_study.py prints the RMSE per band for every model.
Findings:
- Skew flattens with maturity, as eSSVI was built for: SPX ρ goes from −0.68 at the short end to −0.53 at the long end. eSSVI improves NDX by 0.1 vol points, but barely moves SPX.
- SSVI's binding constraint is the SPX put wing. Within ±1 standard deviation of the money SSVI is within 0.5–0.7 vol points, but beyond −2 standard deviations it is about 7 vol points too low at every maturity. The fit sits on the no-arbitrage boundary (η(1+|ρ|) = 1.92 ≈ 2, γ = ½): SPX's put skew is steeper than a single power-law SSVI can be while staying arbitrage-free. Free SVI slices follow the wing but pay for it with calendar and butterfly arbitrage.
- Arbitrage-free SVI closes the gap (M6): 0.27 vol points beyond −2 sd on SPX, 0.16–0.42 in every other band, with no static arbitrage. The market quotes themselves have no calendar crossings at any moneyness, so the earlier gap was the model, not the data.
- NDX has only 3 quotes beyond −2 sd (half-spread ~1 vol point), so its wing number is noise.
- Tracking ρ, η and the ATM term structure over time needs daily snapshots:
run
examples/snapshot.pyeach trading day;examples/real_data_study.pythen writesdata/study.csvanddocs/study_params.png.
Local-vol Monte Carlo (M5, M6)
volsurface.montecarlo.simulate_local_vol simulates correlated paths under Dupire local vol
(daily log-Euler, forwards matched by construction) in the (n_paths, n_times, n_assets) layout
that pricing libraries take. It reprices the surface's own vanillas within 4 standard errors, and
with flat_vols it is GBM on the same forward curves and random numbers.
The worst-of autocallable study that used it has moved to
quant-stack as study S1, so volsurface no
longer depends on sppricer, not even in an example. S1 prices sppricer's README note on SPX and NDX
(ρ = 0.9) with sppricer's own LocalVolModel, an independent implementation, and reproduces this
repo's earlier table on the 2026-10-30 close within Monte Carlo error:
| 60% / 70% barrier, per 100 | Flat ATM vol | eSSVI LV | Arb-free SVI LV |
|---|---|---|---|
quant-stack S1 (sppricer LocalVolModel, 100,000 paths) |
100.44 | 96.15 | 96.44 |
earlier examples/autocallable_skew.py (simulate_local_vol, 200,000 paths) |
100.41 | 96.14 | 96.42 |
Skew takes about 4 points off the fair value, and fixing the SPX put wing (M6) moves it back by only about 0.3. NDX's long-dated quotes are wide; S1 keeps them (spread filter 0.5), because dropping them ends NDX at 1.13 years and holding its smile fixed beyond that overstates the skew effect.
Using a fitted surface elsewhere (v0.2)
Three additions let a fitted surface drive a pricer or a risk engine without refitting:
lv = fit.ssvi_surface.local_vol(K, T, floor=0.05, cap=2.0, extrapolate="flat")
fit.ssvi_surface.n_clamped, fit.ssvi_surface.n_local_vol # how often the guard rails acted
d = fit.ssvi_surface.to_dict() # JSON-safe: save a snapshot's surface
surface = SSVISurface.from_dict(d) # identical surface, no refit
stressed = fit.ssvi_surface.shifted(parallel=0.05, skew=-0.02) # +5 vol pts, steeper puts
- Safe local vol. Dupire is unreliable where there are no quotes: in the far wings the
finite-difference denominator can approach zero.
extrapolate="flat"holds local vol flat in k beyond the fitted range (surface.k_range, set byfit_surface); NaN (an arbitrage point) falls back to implied vol;floor/capclip the rest. Every evaluation the guard rails changed is counted, so a simulation can report how much of it ran on them. Without these keywordslocal_volis unchanged and still returns NaN at arbitrage. - Serialisation.
ForwardCurveandSSVISurface(SSVI or eSSVI) round-trip exactly throughto_dict/from_dict. - Scenario surfaces.
surface.shifted(parallel, skew)addsparallel + skew·kto implied vol, for stress tests. The result is checked for static arbitrage at the surface's expiries on k ∈ [−1, 1], and the method raisesValueErrorinstead of returning a surface with arbitrage.
Part of quant-stack
volsurface is one of five independent libraries linked in
quant-stack, where a fitted surface drives
sppricer's local-vol Monte Carlo (structural typing, no import between the libraries) and
shifted surfaces feed risk-lab stress tests. volsurface installs and tests on its own.
Roadmap
- M1 Pipeline: cleaning, parity forwards, implied vols, SVI, SSVI, arbitrage checks, Dupire local vol
- M2 Smooth term structure: replace piecewise-linear θ(T) with a monotone spline, removing the horizontal bands in the local vol at each expiry
- M3 Real-data study: CBOE snapshots, study script, SVI vs SSVI vs eSSVI on real spreads (above). Ongoing: the time series of ρ, η and ATM term structure fills in as daily snapshots accumulate
- M4 eSSVI: maturity-dependent ρ(θ) for better fits across the term structure
- M5 Link to the pricer: local-vol Monte Carlo in the paths layout pricers take; the autocallable study now lives in quant-stack (S1): skew lowers the worst-of note by about 4 points
- M6 Put-wing fit: arbitrage-free SVI slices; SPX wing error 7.4 → 0.3 vol points, worst-of autocallable price moves by only about +0.3 (quant-stack S1)
Limitations
Yahoo Finance quotes are delayed and sometimes stale; the snapshot is not synchronised
across strikes. Single-stock and ETF options are American, so implied vols from Black-76
carry a small early-exercise bias even on OTM quotes. A single flat discount per expiry
is used rather than a separate OIS curve. CBOE delayed quotes are end-of-day and for
personal use; snapshots stay in the git-ignored data/ folder.
Arbitrage-free SVI is free of static arbitrage on the checked domain (−6 to +4 standard
deviations at each expiry, verified on a fine grid), not analytically everywhere; between
pillar expiries butterfly freedom is not checked, and local vol falls back to implied vol at
the rare NaN points (local_vol(..., floor=, cap=) counts them).
References
- Gatheral, J. (2006). The Volatility Surface: A Practitioner's Guide. Wiley.
- Gatheral, J. & Jacquier, A. (2014). Arbitrage-free SVI volatility surfaces. Quantitative Finance 14(1).
- Hendriks, S. & Martini, C. (2019). The extended SSVI volatility surface. Journal of Computational Finance 22(5).
- Dupire, B. (1994). Pricing with a smile. Risk 7(1).
- Lee, R. (2004). The moment formula for implied volatility at extreme strikes. Mathematical Finance 14(3).
License
MIT. See CONTRIBUTING.md to contribute.
Metadata
Release files for volsurface-lab 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| volsurface_lab-0.2.1.tar.gz | 38.8 kB | With provenance | Details for volsurface_lab-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| volsurface_lab-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for volsurface_lab-0.2.1-py3-none-any.whl |
Total release size: 69.2 kB
Release files / volsurface_lab-0.2.1.tar.gz
| Download URL | volsurface_lab-0.2.1.tar.gz |
|---|---|
| Size | 38.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba3d7a830924a4da1b9daeb9aae4aa988fd06e0d8487f9183d31e2928485681e
|
|
BLAKE2b-256 checksum How to use checksums |
420ba05860ca2d25d64c8aeb46da3edd91d9c273d0e0698ebed9c57d3a592ce3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / volsurface_lab-0.2.1-py3-none-any.whl
| Download URL | volsurface_lab-0.2.1-py3-none-any.whl |
|---|---|
| Size | 30.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e361fe1f3f8cbda65407779e7388fa8f94da7289c7b5dbd49e0005a92fbcc8f
|
|
BLAKE2b-256 checksum How to use checksums |
c2488eeddf7ffd8375cef3a1ee853ed330aad00e289a8ffe67f7ed89cd6d9eb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for volsurface-lab 0.2.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for volsurface_lab-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA 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.