A practical pricing toolkit that calibrates SABR smiles per asset and couples them via a t-Copula to simulate joint terminals/paths, price basket options, range accrual, and snowball structures.
- SABR calibration with robust loss, vega weighting, curvature regularization, 3-fold CV. (see
sabr.py) - Copula fitting & model selection among Gaussian / t / Clayton / Frank / Gumbel with MLE and AIC/BIC comparison. (see
copula.py) - Pricing & Greeks using SABR-ATM marginals + t-Copula for joint terminal and GBM path simulation (basket call, range accrual, snowball). (see
pricing.py)
python -m venv .venv
# Windows PowerShell:
.venv\Scripts\Activate.ps1
pip install -r requirements.txtPrepare your option dataset under ./data. Run:
python sabr.py --input ./data/your_option_file.xlsx --outdir ./sabr_finalOutput: ./sabr_final/sabr_params.csv with columns:
symbol, T, F, alpha, beta, rho, nu (per maturity)
Highlights: robust Huber loss, vega weighting, curvature penalty, 3-fold CV, adaptive beta grid.
Fetch CN indices/ETF, compute returns, PIT transform, then MLE-fit multiple copulas with AIC/BIC comparison:
python copula.pyOutput under ./copula_out/:
copula_compare_aic.csv- If t-copula is selected, saves
t_copula_params.npz (R, nu)and tail-dependence text.
If you can't use AkShare, provide your own return CSVs and run:
python copula_local.py --files ./data/returns_510500.csv ./data/returns_000852.csv ./data/returns_000300.csv --names 510500 000852 000300 --outdir ./copula_outEach CSV should contain a single column named ret with daily returns.
Given sabr_final/sabr_params.csv and copula_out/, run:
python pricing.py ^
--sabr_csv ./sabr_final/sabr_params.csv ^
--copula_dir ./copula_out ^
--symbols 510500 000852 000300 ^
--outdir ./pricing_out ^
--allow_ko_after_ki ^
--N_terminal 120000 --N_paths 60000What it does:
- Build ATM marginal distributions via Hagan ATM approximation and interpolation.
- Load t-Copula params (
R, nu) fromcopula_outor fallback defaults. - Joint terminal sampling and path GBM simulation under t-Copula.
- Price basket call (ATM strike), compute Greeks (Delta/Gamma/Rho vs basket), price Range Accrual (monthly), and Snowball (worst-of) with daily KI / monthly KO.
Key flags:
--ko_level --ki_level --coupon_pa --ko_freq {monthly,daily} --months--range_lower --range_upper --range_coupon_pa--copula_R_default --copula_nu_defaultas safe fallback.
Outputs: CSVs & charts under ./pricing_out.
Notes
- No GPU required.
- If AkShare fails (network/proxy), use
copula_local.pywith your own CSV returns. - Directory placeholders
.keepfiles are included so Git tracks empty folders.