Model Code
Every formula in the notes has an implementation, and every figure was drawn by one. They live in a small Rust crate with no dependencies.
The same code is compiled twice: natively, to draw the charts in the PDFs, and to WebAssembly, so that the figures on these pages respond when you move a slider. A chart in the PDF and the same chart in the browser are therefore the same model evaluated by the same code.
- quant/src/lib.rsPricing models behind the figures in the stochastic calculus notes.
- quant/src/numerics.rsThe two ways a derivative actually gets priced, and what each costs.
- quant/src/pathwise.rsBrownian paths, and the two things the Brownian motion and no-arbitrage chapters do with them.
- quant/src/arbitrage.rsThe geometry behind the no-arbitrage chapter's proof of the fundamental theorem.
- quant/src/black.rsBlack-Scholes, Black-76 and Bachelier, plus the inversion from price back to implied volatility.
- quant/src/smile.rsModels that produce a smile, and the map from a model to the smile it implies.
- quant/src/localvol.rsDupire's formula, applied numerically to a model's own option prices.
- quant/src/sabr.rsSABR, and Hagan's implied volatility expansion.
- quant/src/svi.rsThe stochastic volatility inspired parameterisation of one smile.
- quant/src/lsv.rsThe conditional expectation at the heart of the local-stochastic volatility chapter's leverage function.
- quant/src/heston.rsHeston, simulated, to separate two things a smile can do.
- quant/src/quasigaussian.rsThe smile a quasi-Gaussian model produces, and where it comes from.
- quant/src/curve.rsDiscount curves: bootstrapping one from par quotes, and the interpolation schemes that make the answer between the quotes ambiguous.
- quant/src/events.rsScheduled events, on the curve and on the volatility surface.
- quant/src/cms.rsPricing a CMS payoff out of the swaption smile, without a term structure model.
- quant/src/generator.rsThe generator of a diffusion, and the duality that organises the rest.
- quant/src/hullwhite.rsThe future-forward basis in the Hull-White model.
- quant/src/hjm.rsThe Heath-Jarrow-Morton drift condition, simulated.
- quant/src/marketmodels.rsThe Libor market model, and the measurement that decides it against the swap market model.
- quant/src/transform.rsPrices from a characteristic function, by Fourier inversion.
- quant/src/risk.rsRisk measures, and the arithmetic of the risk management chapter's counterexample.
- quant/src/credit.rsCredit default swaps, and the hazard curve behind them.
- quant/src/crosscurrency.rsQuanto adjustments, and the inflation convexity that turns out to be one.
- quant/src/dependence.rsDependence between defaults, and what it does to a tranche.
- quant/src/special.rsThe three special functions the dependence chapter cannot be written without.
- quant/src/measure.rsWhat a change of measure actually does to a distribution.
- quant/src/estimation.rsEstimating parameters from a history, and testing whether a model fits.
- quant/src/calibration.rsCalibration as an inverse problem, and how badly posed it is.
- quant/src/marketmaking.rsQuoting: the solvable model, and the two costs it does and does not capture.
The tests are part of the explanation and are worth reading. Several claims in the notes — that a lognormal model implies a flat smile, that a local volatility curve has twice the slope of the smile it came from, that a smile does not determine the dynamics — are stated as theorems in the text and checked numerically here.