← library app

10. Quantitative Finance

The math/stats toolkit behind pricing, signals, and portfolio construction. Performance metrics (Sharpe, VaR, Kelly) live in 08-appendix.md; this file is the modeling layer above them.

Algo-wide warnings.

  1. Stationarity. Most stats assume stationary data; prices aren't (use returns). Test before modeling (ADF/KPSS).
  2. Real-world vs risk-neutral. Pricing uses the risk-neutral measure ℚ (drift = r); forecasting/backtesting uses the real-world measure ℙ (drift = μ). Never mix them.
  3. In-sample everything looks great. Every model overfits without out-of-sample / walk-forward validation. Degrees of freedom are the enemy.
  4. Fat tails & regime shifts. Markets aren't Gaussian and aren't stationary across regimes. Normal-distribution assumptions understate tail risk.

For "Signal" read interpretation / how it's used.


Stochastic Processes & Calculus

Random Walk / Brownian Motion (Wiener process)

Def. Continuous-time process with independent Gaussian increments; the base layer of price models. Formula. , , independent increments, continuous paths. Signal. The "noise" driving asset models; embodies the efficient-market "unpredictable increment" idea. Algo. Simulate , . Variance scales with time → vol scales with √time (the √t rule everywhere).

Geometric Brownian Motion (GBM)

Def. The standard equity price model — exponential of a drifting Brownian motion (prices stay positive). Formula. , solution . Signal. Underlies Black–Scholes; log returns are normal, prices lognormal. Algo. The (Itô) drift correction is the classic bug — omit it and your simulated mean is too high. Simulate in log space.

Itô's Lemma

Def. The chain rule for stochastic calculus — how a function of a stochastic process evolves. Formula. For : . Signal. The extra term — from — is why vol enters drift; derives the BS PDE. Algo. Source of the corrections throughout pricing — not optional algebra.

Ornstein–Uhlenbeck / Mean Reversion

Def. Process pulled back toward a long-run mean; the model for spreads, rates, vol. Formula. , θ = reversion speed, half-life . Signal. Basis for pairs trading & rate models (Vasicek). Half-life sets your holding period. Algo. Estimate θ via AR(1) regression: , . Don't assume mean-reversion without testing — trending series will bankrupt an OU strategy.

Jump Diffusion / Stochastic Vol

Def. Extensions adding jumps (Merton) or random volatility (Heston) to capture fat tails & smile. Formula. Merton: GBM + Poisson jumps. Heston: , correlated with price. Signal. Explain the volatility smile and crash risk that GBM/BS miss. Algo. More realistic, more parameters to (over)fit. Heston has a semi-closed-form via characteristic functions; calibrate to the option surface.


Pricing Theory

Risk-Neutral Valuation

Def. Price = discounted expected payoff under the risk-neutral measure ℚ — where all assets drift at . Formula. . Signal. The master pricing equation — works because hedging removes risk-preference from the price. Algo. Under ℚ, replace real drift μ with r in simulations. Discount at the funding/collateral rate, not a made-up "required return."

No-Arbitrage / Replication

Def. If two portfolios have identical payoffs, they have identical prices — else free money. Formula. Law of one price; a derivative = a self-financing hedging portfolio. Signal. The foundation under every pricing model (put-call parity, futures fair value, swap par rate). Algo. Sanity-check any model price against replication bounds; persistent "arbs" in a backtest usually mean a data/timing bug.

Fundamental Theorems of Asset Pricing

Def. (1) No arbitrage ⟺ a risk-neutral measure exists. (2) Market completeness ⟺ that measure is unique. Signal. Tells you when a unique price exists (complete market) vs a range (incomplete — e.g. stochastic vol). Algo. Incomplete markets → pricing depends on a chosen measure/utility; don't expect one "true" price for exotics.

Martingale

Def. A process whose expected future value equals its current value (no predictable drift). Formula. . Signal. Discounted asset prices are martingales under ℚ — the formal statement of "no free lunch." Algo. A profitable signal means returns aren't a martingale w.r.t. your info set — that's literally the edge you're testing for.

Black–Scholes PDE

Def. The PDE every (European) derivative price satisfies under BS assumptions. Formula. . Signal. Solve with payoff boundary conditions; equivalent to the risk-neutral expectation (Feynman–Kac). Algo. Finite-difference schemes (explicit/implicit/Crank–Nicolson) solve it numerically for American/exotic payoffs.


Statistics & Econometrics

Distributions & Moments

Def. Mean, variance, skew, kurtosis describe a return distribution's shape. Formula. Skew (asymmetry), excess kurtosis (fat tails, normal=0). Returns: negative skew + high kurtosis. Signal. Fat tails (kurtosis≫3) mean Gaussian VaR understates risk; negative skew = crash-prone. Algo. Don't assume normality. Use Student-t / empirical distributions for tail risk; test with Jarque–Bera.

OLS Regression

Def. Fit a linear relationship by minimizing squared errors. Formula. , . R² = explained variance fraction. Signal. Workhorse for factor models, beta, hedge ratios. Algo. Financial data violates OLS assumptions (heteroskedastic, autocorrelated) → use Newey–West / robust standard errors or t-stats are inflated.

Hypothesis Testing & p-values

Def. Framework for whether an effect is statistically distinguishable from noise. Formula. t-stat = estimate/std error; p-value = prob of seeing this under the null. Signal. Is a backtest's edge real or luck? Algo. Multiple-testing trap: test 100 strategies, ~5 look "significant" at p<0.05 by chance. Use Bonferroni / deflated Sharpe / hold-out sets.

Maximum Likelihood Estimation (MLE)

Def. Pick parameters that make the observed data most probable. Formula. Maximize . Signal. Standard estimator for GARCH, distribution fitting, regime models. Algo. Can overfit with many params; watch convergence and local maxima.

Stationarity & Unit Root (ADF/KPSS)

Def. Stationary = constant mean/variance over time; required for most time-series models. Formula. ADF tests for a unit root (null = non-stationary); KPSS null = stationary (use both). Signal. Prices are non-stationary (unit root); returns usually are stationary. Algo. Model returns, not prices. Regressing two non-stationary series → spurious regression (high R², meaningless). Test first.


Time Series

Autocorrelation (ACF/PACF)

Def. Correlation of a series with its own lags. Formula. . ACF/PACF plots pick AR/MA orders. Signal. Significant autocorrelation in returns = predictability (momentum/reversal); in squared returns = vol clustering. Algo. Returns have weak autocorrelation; squared/abs returns have strong (→ GARCH territory).

ARIMA

Def. Linear model of a series via autoregressive + moving-average terms on differenced data. Formula. : AR(p) + I(d) differencing + MA(q). Signal. Baseline forecasting; mostly captures short-horizon mean structure. Algo. Returns are near-unforecastable in the mean → ARIMA on returns rarely beats a constant. Better for rates/spreads with structure.

GARCH

Def. Models time-varying volatility with clustering (calm/stormy regimes). Formula. . α+β near 1 → persistent vol. Signal. The standard volatility forecaster; vol is predictable even when returns aren't. Algo. Forecast vol for position sizing / VaR / option pricing. EGARCH/GJR add the leverage effect (down moves raise vol more).

Cointegration & Pairs Trading

Def. Two non-stationary series whose linear combination is stationary — they share a long-run equilibrium. Formula. Engle–Granger (regress + ADF on residual) or Johansen test. Spread is mean-reverting. Signal. The rigorous basis for pairs/stat-arb (vs naive correlation, which says nothing about co-movement of levels). Algo. Correlation ≠ cointegration. Trade the spread's z-score; β (hedge ratio) drifts → re-estimate. Beware look-ahead in choosing pairs.

Kalman Filter

Def. Recursive estimator of a hidden state (e.g. a time-varying hedge ratio or trend) from noisy observations. Formula. Predict→update cycle with state + observation equations. Signal. Dynamic hedge ratios, adaptive betas, trend extraction without lag of moving averages. Algo. Online/incremental (no lookahead if causal) — well-suited to live trading. Tune process vs observation noise.


Portfolio Theory & Factor Models

Modern Portfolio Theory (Markowitz)

Def. Optimal portfolios maximize return for a given variance — the efficient frontier. Formula. Minimize s.t. target return; tangency portfolio maximizes Sharpe. Signal. Diversification reduces risk when assets aren't perfectly correlated. Algo. Mean-variance is extremely sensitive to estimated means (garbage in → extreme weights). Use shrinkage (Ledoit–Wolf), constraints, or risk-parity instead of raw optimization.

CAPM & Beta

Def. Expected return = risk-free + beta × market risk premium. Formula. , . Signal. Decomposes return into market (systematic) vs idiosyncratic; alpha = return beyond CAPM. Algo. Single-factor and empirically weak; the starting point, not the answer. Beta is regime-dependent — estimate rolling.

Fama–French / Multi-Factor Models

Def. Extend CAPM with size, value, profitability, investment, momentum factors. Formula. . Signal. Most "alpha" is really factor exposure; α is what's left after controlling for known factors. Algo. Run your strategy's returns through a factor regression — if α≈0, you're just selling factor beta (cheaper via ETFs). The real test of edge.

Risk Parity

Def. Allocate so each asset contributes equal risk, not equal capital. Formula. Weight ∝ 1/volatility (then account for correlations); equalize marginal risk contributions. Signal. More robust than mean-variance (no return forecasts needed); diversifies risk, not dollars. Algo. Lever up to a target vol. Sensitive to the covariance estimate; rebalancing costs matter.

PCA / Eigenportfolios

Def. Decompose the covariance matrix into orthogonal factors (principal components). Formula. Eigen-decompose Σ; PC1 ≈ market, PC2+ ≈ sectors/styles. Signal. Dimensionality reduction, risk-factor identification, cleaning noisy covariance (random-matrix theory). Algo. Denoise the covariance (clip small eigenvalues) before optimizing — raw sample covariance is unstable for large universes.


Machine Learning for Trading

Feature Engineering & Leakage

Def. Turning raw data into predictive inputs — and the ways future info sneaks in. Signal. Most ML-trading failures are data leakage, not bad models. Algo. Lag every feature to its availability time; scale using only past data (fit scaler on train); never let the target's future touch features. Purge & embargo around label windows.

Cross-Validation for Time Series

Def. Validation that respects time ordering (no shuffling). Formula. Walk-forward / expanding window; purged k-fold with embargo (López de Prado). Signal. Standard k-fold leaks future→past and massively overstates performance. Algo. Always time-ordered splits. Embargo a gap after each test fold so overlapping labels don't leak.

Labeling (Triple-Barrier)

Def. Define the prediction target by profit-take / stop-loss / time barriers, not fixed-horizon returns. Formula. Label = which barrier (upper/lower/vertical) is hit first. Signal. Matches labels to how you'd actually trade (path-aware), unlike naive next-bar return. Algo. Use meta-labeling (a second model sizes/filters the primary signal) to cut false positives.

Overfitting & Regularization

Def. Model memorizes noise; regularization (L1/L2, dropout, early stopping) penalizes complexity. Signal. Low train error + high test error = overfit. Financial signal-to-noise is tiny, so this is the default failure mode. Algo. Prefer simple models (linear, small trees). Backtest overfitting: report the Deflated Sharpe / PBO (probability of backtest overfitting).

Common Model Families

Def. What's actually used: gradient-boosted trees (tabular features), linear/regularized models, LSTMs/transformers (sequences), RL (execution/sizing). Signal. Trees dominate tabular alpha research; deep nets mostly for high-frequency/sequence or execution. Algo. Match capacity to data size — deep nets starve on the low signal-to-noise, short histories of daily finance data. Ensemble + strict validation beats a fancy single model.


Numerical Methods

Monte Carlo

Def. Estimate expectations by simulating many paths. Formula. , error . Signal. Go-to for path-dependent/high-dimensional payoffs. Algo. Halving error needs 4× paths. Use variance reduction (antithetic, control variates, quasi-MC/Sobol). Seed for reproducibility.

Finite Differences / Trees

Def. Discretize the pricing PDE (grids) or the process (lattices) and solve backward. Signal. Efficient for low-dimensional American/exotic options. Algo. Crank–Nicolson is stable + accurate; explicit schemes can blow up (CFL condition). Trees converge to BS as steps→∞.

Optimization & Root-Finding

Def. Solvers for calibration (least-squares), IV inversion (Newton/Brent), portfolio QP. Signal. Calibrating models to market prices; backing out implied vol. Algo. IV inversion: Newton is fast but needs vega>0; Brent is robust. Convex problems (mean-variance) → use QP solvers, not gradient descent.


Quick map: which tool for which job

Job Reach for
Price a vanilla option Black–Scholes / PDE
Price path-dependent/exotic Monte Carlo
Forecast volatility GARCH
Find mean-reverting pairs Cointegration (Johansen) + OU
Decompose strategy returns Fama–French factor regression
Build a robust portfolio Risk parity / shrinkage covariance
Time-varying hedge ratio Kalman filter
Tabular alpha from features Gradient-boosted trees + purged CV
Test if an edge is real Out-of-sample + deflated Sharpe + factor α