尚未偵測到更新。GitHub 發布版本後會顯示在這裡。
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證Exotic options under Black-Scholes, Heston, Dupire local vol and a particle-calibrated Heston SLV, fitted to SPX. Tested pricers, calibration report, browser demo.
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗Option pricing library in Python: European, American, Asian and barrier options under Black-Scholes, Heston, Dupire local volatility and a Heston stochastic-local-volatility (SLV) model whose leverage function is calibrated by the particle method. Calibrated on an SPX option snapshot and on a simulated market, with a test suite that checks every pricer against an independent reference.
Demo: luca-cs.github.io/option-pricing-lab: a pricing desk in the browser (price and Greeks, animated Monte Carlo under Black-Scholes or the SPX-calibrated Heston model, exercise boundary, value and Greeks across spot), a guide to which model suits which product, and the SPX model-risk results of the Python library.
SPX, snapshot of 27 October 2026: 9 maturities from two weeks to two years, 1,694 out-of-the-money quotes. Errors in basis points of implied vol (1 bp = 0.01 vol point); median half bid-ask 2 to 7 bp.
| 2 weeks | 1 month | 2 months | 3 months | 6 months | 9 months | 1 year | 1.6 years | 2.1 years | |
|---|---|---|---|---|---|---|---|---|---|
| SVI surface vs quotes (RMSE) | 6.4 | 4.3 | 8.8 | 4.9 | 6.5 | 10.0 | 9.0 | 9.9 | 30.8 |
| Heston vs quotes (RMSE) | 51 | 51 | 50 | 46 | 44 | 37 | 26 | 33 | 59 |
| Local vol, Monte Carlo vs surface | 7.3 | 4.3 | 2.0 | 3.7 | 5.9 | 5.1 | 1.0 | 0.5 | 5.0 |
| SLV, Monte Carlo vs surface | 9.8 | 9.4 | 3.7 | 5.4 | 2.0 | 4.8 | 1.7 | 5.1 | 6.0 |
The Monte Carlo rows are mean absolute errors over 9 strikes with 300,000 paths (standard error 3 to 4 bp). The surface is free of butterfly arbitrage and of calendar arbitrage on the checked band.
Model risk. Four models that agree on vanillas disagree on path-dependent payoffs (1 year, % of spot):
| Black-Scholes (ATM vol) | Heston | Local vol | SLV (mix 0.5) | |
|---|---|---|---|---|
| Down-and-out call, K 100 %, H 80 % | 8.63 | 8.76 | 8.79 | 8.83 |
| Up-and-out call, K 100 %, H 120 % | 1.87 | 4.69 | 3.49 | 3.97 |
| Down-and-in put, K 100 %, H 85 % | 3.65 | 4.84 | 4.72 | 4.76 |
| American put, K 100 % | 5.11 | 5.47 | 5.37 | 5.44 |
The up-and-out call doubles between Black-Scholes and the smile models, and moves by a third between local vol and Heston: in the SLV it goes from 3.48 (mix 0, local vol) to 4.13 (mix 0.75) with the vanillas held fixed.
Simulated market (quotes from a known Heston model plus 15 bp of noise): the calibration finds v0 0.0250 (true 0.0250), kappa 1.801 (1.8), theta 0.0398 (0.04), xi 0.748 (0.75), rho -0.751 (-0.75).
Full tables and charts: reports/calibration.md.
Tests: 80, covering put-call parity (closed forms, Fourier, Monte Carlo), Monte Carlo convergence (1/sqrt(N) error, closed forms within 4 standard errors), American >= European and the American call without dividend equal to the European, the geometric Asian against its closed form, barriers against Reiner-Rubinstein with the Broadie-Glasserman-Kou correction, parameter recovery for SSVI, SVI and Heston, the vanillas reproduced by Dupire local vol and by the SLV model, and the JavaScript of the demo page against the Python library (to 1e-9 on the closed forms).
| Product | Pricer | Reference it is tested against |
|---|---|---|
| European | closed form (Black-Scholes, Black), Fourier for Heston (Lewis formula, "little trap" characteristic function), Monte Carlo for every model | put-call parity, closed forms |
| American | Longstaff-Schwartz: cubic polynomial basis in S/K (plus v, v^2, S v under stochastic volatility), regression on in-the-money paths, exercise rule estimated on one set of paths and applied to an independent one (no foresight bias) | CRR binomial tree (2,000 steps, averaged over n and n + 1) |
| Asian, arithmetic | Monte Carlo with the geometric Asian as control variate (optimal coefficient) | discrete geometric Asian in closed form |
| Barrier (single, knock-in or out) | Monte Carlo with daily monitoring | Reiner-Rubinstein closed form with the Broadie-Glasserman-Kou continuity correction |
All Monte Carlo pricers use antithetic variates and report a standard error that accounts for the pairing.
Every model is simulated in the log-forward coordinate x = ln(S_t / F(t)), with deterministic
discount and forward curves (Market). The log-Euler step with the instantaneous variance taken at
the start of the step keeps exp(x) an exact martingale, so forwards are matched by construction.
The time grid is graded (step dt_min + t / 60): a steep short-dated skew makes the first weeks the main
source of discretisation error, and a uniform 1/400 grid left 10 to 20 bp of bias at three months.
The report is in reports/calibration.md.
SPX option quotes come from Yahoo Finance through yfinance. Yahoo's data are for personal use, so the
raw snapshot stays in data/raw/ (ignored by git) and is never published: the repository and the demo only
contain calibrated parameters, curves rescaled to a spot of 100, model outputs and charts.
Cleaning, maturity by maturity: SPXW contracts (PM-settled) or the monthly AM-settled SPX contracts when there is no SPXW expiry; two-sided quotes with a relative spread below 50 %; discount factor and forward from put-call parity on near-the-money strikes, with a zero-rate curve smoothed over the maturities beyond two months; out-of-the-money mid prices inverted to Black vols, within -3 to +2.5 ATM standard deviations.
The simulated market (quotes generated by a known Heston model plus noise) needs no download and checks that the calibration finds the parameters back.
python -m venv .venv
.venv/Scripts/pip install -r requirements.txt # .venv/bin/pip on Linux and macOS
python -m pytest # about ten minutes, most of it in the SLV tests
python scripts/run_calibration.py --source simulated
python scripts/download_spx.py # personal-use snapshot in data/raw/
python scripts/run_calibration.py --source spx
python scripts/make_report.py
from optlab import Market, HestonParams, HestonModel, barrier_mc
market = Market.flat(100.0, r=0.04, q=0.01)
model = HestonModel(HestonParams(v0=0.04, kappa=1.5, theta=0.04, xi=0.5, rho=-0.7))
price, stderr = barrier_mc(model, market, K=100, H=80, T=1.0, kind="down-out", cp="call")
docs/ is the demo page (GitHub Pages): dependency-free JavaScript (docs/lab.js) for the closed forms, an
American PDE (Crank-Nicolson with projected SOR on a strike-centred grid, so that the Greeks are smooth in the
spot), the tree, Lévy's Asian approximation, Heston by Fourier, Monte Carlo (Andersen's QE scheme for Heston)
and Longstaff-Schwartz, checked against the Python library by tests/test_widget_js.py (needs node), plus the
SPX results written by scripts/build_widget_data.py. Deep links open a given case, for instance
?product=barrier&K=119&model=heston. The full library, with live SLV recalibration, also has a Gradio app that
runs locally: pip install gradio, then python space/app.py.
| Path | Content |
|---|---|
optlab/market.py | discount and forward curves |
optlab/blackscholes.py | closed forms, Greeks, implied vol, geometric Asian, barriers |
optlab/tree.py | CRR binomial tree |
optlab/heston.py | characteristic function, Lewis pricing, calibration |
optlab/ssvi.py, optlab/svi.py | implied surfaces, arbitrage checks, Dupire local variance |
optlab/models.py | path simulation for the four models |
optlab/products.py | Monte Carlo pricers, Longstaff-Schwartz |
optlab/slv.py | leverage function by the particle method |
optlab/data.py | SPX chain download and cleaning |
optlab/pipeline.py, scripts/ | calibration runs, report and charts |
docs/ | demo page (GitHub Pages) |
space/ | Gradio app, run locally |
tests/ | pytest suite |