entire math behind quant trading bots

10 levels. 50 formulas. What each one means, where it makes money, and how interviews test it.

The prompt turns ChatGPT, Claude or Gemini into a tutor that teaches and quizzes you from this sheet.

find your level ↓

zoom in. start at level 1.
most traders stop at level 2.

Level 1 probability

the language of uncertainty

Tools · numpy · scipy.stats

  1. P(A | B) = P(B | A) P(A) / P(B)

    Means
    Update a belief when new evidence arrives.
    Pays
    Update the odds that the regime changed after a news print.
    Interview
    Test is 99% accurate, 1% are sick. You test positive: P(sick) = 50%.
  2. E[X + Y] = E[X] + E[Y]

    Means
    The average of a sum is the sum of averages, even if they depend on each other.
    Pays
    Expected P&L of a book = sum of each position's expected P&L.
    Interview
    Random shuffle of n cards: expected cards in their own spot = 1.
  3. Var(X) = E[X2] - (E[X])2

    Means
    How widely outcomes spread around the average.
    Pays
    Var(X + Y) = Var X + Var Y + 2 Cov(X, Y) is why diversification works.
    Interview
    Variance of one fair die roll = 35/12 = 2.92.
  4. E[X] = E[ E[X | Y] ]

    Means
    Average over scenarios, weighted by how likely each one is.
    Pays
    Price a trade by weighting its payoff in each market regime.
    Interview
    Expected rolls of a die until the first 6 = 6.
  5. Geometric E = 1/p · Poisson P(k) = λk e-λ / k! · Normal 68/95/99.7

    Means
    The shapes randomness usually takes.
    Pays
    Poisson for order arrivals. Normal for returns, but real returns have fatter tails.
    Interview
    Expected rolls to see all 6 faces = 14.7.

Level 2 statistics

is it real or is it noise?

Tools · statsmodels · scipy

  1. SE = σ / √n

    Means
    How uncertain an average is.
    Pays
    Tells you if your average trade is really above zero.
    Interview
    To halve the error you need 4x the data.
  2. t ≈ SR × √T

    Means
    Signal-to-noise of a return series (SR and T in the same period units).
    Pays
    Monthly SR 0.2 over 36 months gives t = 1.2. Not significant.
    Interview
    Annual Sharpe 1 over 4 years: t = 2. Borderline.
  3. β = (XTX)-1 XT y

    Means
    The best-fit linear weights. One variable: β = Cov(x, y) / Var(x).
    Pays
    Hedge ratios, factor exposures, signal weights.
    Interview
    Derive the one-variable β from scratch.
  4. ρ = Cov(X, Y) / (σx σy) · R2 = 1 - SSres / SStot

    Means
    How tightly two series move together, and how much variance a model explains.
    Pays
    In markets a tiny R² can still be a real, tradable edge.
    Interview
    X symmetric around 0: Corr(X, X²) = 0, yet they are not independent.
  5. P(≥1 false win) = 1 - (1 - α)N

    Means
    Test enough ideas and some pass by luck.
    Pays
    20 tests at 5% gives a 64% chance of at least one fake winner.
    Interview
    Why is your best backtest overstated?

Level 3 linear algebra

how everything moves together

Tools · numpy.linalg · scikit-learn

  1. Σij = Cov(ri, rj)

    Means
    A table of how every pair of assets moves together.
    Pays
    The input to every portfolio and risk model.
    Interview
    Why must Σ be positive semi-definite?
  2. σp2 = wT Σ w

    Means
    Total risk of a portfolio from its weights and Σ.
    Pays
    2 assets, 20% vol each, ρ = 0.5, 50/50: portfolio vol = 17.3%.
    Interview
    When does adding an asset lower risk? When ρ < 1.
  3. Σ = Q Λ QT · share = λk / Σλ

    Means
    Find the few hidden drivers behind many series.
    Pays
    First component of stocks is roughly the market. Yield curves: level, slope, curvature.
    Interview
    What does the first principal component of a stock universe mean?
  4. κ = λmax / λmin

    Means
    A large κ means Σ-1 blows up small errors.
    Pays
    Why raw optimizer weights explode on noisy data.
    Interview
    Why is your optimizer unstable with 500 assets?
  5. Σ = δ F + (1 - δ) S

    Means
    Blend the noisy sample matrix S with a simple target F (Ledoit-Wolf).
    Pays
    More stable weights and risk estimates.
    Interview
    Explain the bias-variance trade-off.

Level 4 calculus and optimization

find the best decision

Tools · scipy.optimize · cvxpy

  1. f(x + h) ≈ f(x) + f′(x)h + ½ f″(x)h2

    Means
    Approximate any smooth function near a point.
    Pays
    Option P&L ≈ Δ·dS + ½Γ·dS² + Θ·dt.
    Interview
    Estimate √101 in your head: about 10.05.
  2. θ ← θ - η ∇L(θ)

    Means
    Step downhill on the error, again and again.
    Pays
    How every machine-learning model is trained.
    Interview
    What happens if the learning rate η is too big? It diverges.
  3. ∇f = λ ∇g

    Means
    Optimize something under a constraint.
    Pays
    Maximum return for a fixed risk or budget.
    Interview
    Maximize xy with x + y = 10: answer 25.
  4. w* = (1/γ) Σ-1 μ

    Means
    Weights grow with expected return and shrink with risk (Markowitz).
    Pays
    The base of portfolio construction.
    Interview
    Why does it pile into estimation errors?
  5. E[f(X)] ≥ f(E[X]) for convex f

    Means
    Averages of curved functions are not the function of the average.
    Pays
    Volatility drag: growth ≈ mean - σ²/2. 10% mean, 20% vol: about 8%.
    Interview
    +50% then -50%: you are down 25%.

Level 5 time series

markets have memory, sometimes

Tools · statsmodels · arch

  1. r = ln(Pt / Pt-1) · σyr = σday √252

    Means
    Returns that add up over time.
    Pays
    1% daily vol is about 15.9% a year.
    Interview
    Why use log returns, not simple returns?
  2. ρk = Corr(rt, rt-k)

    Means
    Does today say anything about tomorrow?
    Pays
    Positive: momentum. Negative: mean reversion.
    Interview
    What does negative lag-1 autocorrelation imply?
  3. Δyt = α + γ yt-1 + … + εt

    Means
    Reject γ = 0 and the series keeps returning to its mean.
    Pays
    Only stationary spreads can be traded for reversion.
    Interview
    Are prices stationary? No. Returns roughly are.
  4. s = ln A - β ln B · half-life = -ln 2 / λ

    Means
    Two prices tied together, and how fast their gap closes.
    Pays
    Pairs trading. λ = -0.05 gives a 13.9-day half-life.
    Interview
    Correlation vs cointegration: explain the difference.
  5. σt2 = ω + α εt-12 + β σt-12

    Means
    Volatility clusters: calm follows calm, storms follow storms.
    Pays
    Forecast vol for sizing. Long-run variance = ω / (1 - α - β).
    Interview
    Why does volatility cluster?

Level 6 stochastic calculus

the math of random paths

Tools · numpy (Monte Carlo)

  1. St = S0 + Σ Xi · Var = t σ2

    Means
    Distance grows with √time, not time.
    Pays
    Why risk scales with the square root of the horizon.
    Interview
    100 fair ±1 steps: typical distance from start = 10.
  2. Wt ~ N(0, t) · (dW)2 = dt

    Means
    A continuous random walk with independent steps.
    Pays
    The building block of every continuous-time price model.
    Interview
    Why is (dW)² = dt and not 0?
  3. dS = μS dt + σS dW

    Means
    Solution: St = S0 exp((μ - σ²/2)t + σWt).
    Pays
    The standard stock model, and the engine of Monte Carlo pricing.
    Interview
    Why can a GBM price never go negative?
  4. df = (ft + μ fx + ½σ2 fxx) dt + σ fx dW

    Means
    The chain rule for random processes, with an extra ½σ² term.
    Pays
    How Black-Scholes is derived, and where volatility drag comes from.
    Interview
    Apply Itô to f = ln S.
  5. E[Xt+1 | now] = Xt · P(win) = i / N

    Means
    In a fair game no betting system has an edge.
    Pays
    Start with 30, stop at 100 or 0 on a fair coin: 30% chance to win.
    Interview
    Can doubling your bet after losses beat a fair game?

Level 7 derivatives

pricing the future

Tools · py_vollib · QuantLib

  1. C = S N(d1) - K e-rT N(d2)

    Means
    d1 = [ln(S/K) + (r + σ²/2)T] / (σ√T), d2 = d1 - σ√T.
    Pays
    S = K = 100, r = 5%, σ = 20%, T = 1: call = 10.45.
    Interview
    What are the model's assumptions, and which fail first?
  2. C - P = S - K e-rT

    Means
    Calls and puts are locked together.
    Pays
    Same example: put = 10.45 - 100 + 95.12 = 5.57.
    Interview
    Given a call price, find the put. Spot the arbitrage.
  3. Δ = ∂V/∂S · Γ = ∂²V/∂S² · Θ = ∂V/∂t · ν = ∂V/∂σ

    Means
    How the price reacts to each risk.
    Pays
    Hedge with them. In the example above, Δ = N(d1) = 0.64.
    Interview
    Why is gamma highest at the money near expiry?
  4. σ such that BS(σ) = market price

    Means
    The volatility the market is pricing in.
    Pays
    Compare implied vs realized vol to find rich or cheap options.
    Interview
    What is the volatility smile and why does it exist?
  5. P&L ≈ ½ Γ S2 (σ2realized - σ2implied) dt

    Means
    A delta-hedged option wins when realized vol beats implied.
    Pays
    The core of volatility trading.
    Interview
    You are long gamma and the market goes flat. What happens?

Level 8 portfolio and risk

how much to bet, how much you can lose

Tools · numpy · cvxpy

  1. E[Ri] = r(f) + βi (E[Rm] - r(f)) · β = Cov(Ri, Rm)/Var(Rm)

    Means
    Return you should expect just for taking market risk.
    Pays
    Separate real alpha from plain market exposure.
    Interview
    What is beta, and what is alpha?
  2. Ri - r(f) = α + b MKT + s SMB + h HML + ε

    Means
    Market, size and value explain much of stock returns.
    Pays
    Check if your 'alpha' is just a size or value tilt.
    Interview
    Name the factors and what each one captures.
  3. SR = (R - r(f)) / σ · SRyr = SRday × √252

    Means
    Return per unit of risk.
    Pays
    Daily SR 0.1 is about 1.59 a year.
    Interview
    Why can a high Sharpe strategy still blow up?
  4. f* = (bp - q) / b · f* = (μ - r) / σ2

    Means
    The bet size that maximizes long-run growth.
    Pays
    p = 0.55, even odds: bet 10%. Most pros bet half.
    Interview
    Why is full Kelly dangerous in practice?
  5. VaR95 = 1.645 σ V · ES95 = σ φ(1.645)/0.05 V

    Means
    Loss on a bad day, and the average loss beyond it.
    Pays
    $1M, 2% daily vol: VaR $32.9k, ES $41.3k. Max DD = largest peak-to-trough fall.
    Interview
    Why is VaR not enough on its own?

Level 9 microstructure and execution

where the edge leaks out

Tools · order book data · pandas

  1. mid = (bid + ask)/2 · spread = (ask - bid)/mid × 104 bps

    Means
    The fair price, and the cost to cross.
    Pays
    Every round trip pays the spread.
    Interview
    Who earns the spread, and what risk do they take?
  2. I = Q(bid) / (Q(bid) + Q(ask))

    Means
    Which side of the book is heavier.
    Pays
    A short-term direction signal. Weighted mid = (P(bid) Q(ask) + P(ask) Q(bid)) / total size.
    Interview
    Bid 99.98 × 10, ask 100.02 × 30: where is fair value?
  3. ΔP/P ≈ Y σ √(Q / V)

    Means
    Big orders move price, but less than in proportion.
    Pays
    σ = 2%, order = 1% of daily volume, Y = 1: about 0.2% impact.
    Interview
    Why split a large order over time?
  4. VWAP = Σ pq / Σ q

    Means
    TWAP = equal slices over time. Shortfall = paper P&L - real P&L.
    Pays
    The benchmarks every execution is judged against.
    Interview
    When would you trade at TWAP instead of VWAP?
  5. r = s - q γ σ2 (T - t)

    Means
    Spread = γσ²(T - t) + (2/γ) ln(1 + γ/k).
    Pays
    Market making that skews quotes to get rid of inventory.
    Interview
    You are long inventory. How do you move your quotes?

Level 10 research and machine learning

the art of not fooling yourself

Tools · scikit-learn · xgboost · hmmlearn

  1. signal at t → trade at t + 1

    Means
    Look-ahead, survivorship, data snooping, missing costs.
    Pays
    The four leaks behind most fake backtests.
    Interview
    Name three ways a backtest can lie.
  2. train [past] → test [next block] → roll

    Means
    Always test on data the model has never seen. Purge overlapping labels.
    Pays
    The only honest estimate of out-of-sample performance.
    Interview
    Why is shuffled k-fold wrong for time series?
  3. SR0 = σ(SR) [(1-γ)Φ-1(1 - 1/N) + γΦ-1(1 - 1/(Ne))]

    Means
    The Sharpe the luckiest of N worthless tries would show.
    Pays
    N = 50, σ(SR) = 0.5: you must beat 1.14.
    Interview
    You tested 100 strategies. Is the best one real?
  4. P = TP/(TP+FP) · R = TP/(TP+FN) · F1 = 2PR/(P+R)

    Means
    How often your 'yes' is right, and how many real winners you catch.
    Pays
    Judge meta-labeling filters that decide take or skip.
    Interview
    Accuracy is 99%. Why can the model still be useless?
  5. P(st | st-1) = transition matrix

    Means
    Hidden market states, inferred from returns.
    Pays
    Switch strategies on and off by regime.
    Interview
    How do you avoid look-ahead when labeling regimes?

your path through the map

learn it free

Take the sheet with you

All 50 formulas as a spreadsheet, the full sheet as one picture, or one prompt that makes an AI teach it to you level by level.

Download CSV Download PNG

Means
Pays
Interview