Independent study companion to Shreve

Stochastic calculus, chapter by chapter

Steven Shreve’s Stochastic Calculus for Finance is the book most quant interviews draw on. Here is every chapter in plain words, starting with an everyday picture, then the one result to remember, a live model you can change, and the interview questions it answers. Read it next to the book, not instead of it.

Desk2Quant’s own explanations and models. Not affiliated with or endorsed by the author or the publisher; chapter titles are given for reference only.

Volume IThe Binomial Asset Pricing Model · 6 chapters Volume IIContinuous-Time Models · coming next

Volume I · Chapter 1

The Binomial No-Arbitrage Pricing Model

Price an option by building a mix of stock and cash that pays exactly what the option pays. The option’s price is the cost of that mix.

Picture it

You and a friend bet on rain: if it rains, you get 10; if not, nothing. An umbrella company’s share price jumps on rainy days. Buy just the right number of its shares and you end up with exactly the bet’s payoff, rain or shine. So the bet is worth what those shares cost today. Your forecast and your friend’s forecast never come into it.

Start with one period: the stock moves up by a factor u or down by a factor d, and cash grows at rate r. For there to be no free lunch, the safe return must sit between the two stock outcomes: d < 1 + r < u.

Hold Δ shares and put the rest in cash, and choose Δ so the portfolio matches the option in both outcomes. The cost of that portfolio is the only price that avoids arbitrage. Rearranged, it is a discounted average of the two payoffs with weights p̃ and q̃: the risk-neutral probabilities. The real chance of an up move never enters.

With many periods you repeat the same step backwards through the tree, node by node. The hedge Δ changes at every node, which is dynamic hedging in its simplest form. Payoffs that depend on the whole path (lookbacks, Asians) use the same backward step with a bigger state.

Vn = p̃ Vn+1(H) + q̃ Vn+1(T)1 + r,   p̃ = 1 + r − du − d,   Δn = Vn+1(H) − Vn+1(T)Sn+1(H) − Sn+1(T)

Reading the formula: u, d: how much the stock can rise or fall in one step · r: interest earned per step · p̃, q̃: pricing weights (not a forecast) · V: option value · Δ: shares to hold to copy the option

Live modelILLUSTRATIVE INPUTS

A binomial tree with S₀ = 100 and strike 100. Change u, d, r and the number of periods; push r past u to see the arbitrage warning.

The hard parts, step by step

The ideas in this chapter that most people get stuck on, each with a picture, the derivation line by line, worked numbers and the trap to avoid.

Deriving the one-period price, line by line

Picture it

You are solving two equations for two unknowns, like working out how many coins of two kinds make two totals. The unknowns are how many shares to hold (Δ) and how much cash to start with (X0). The two equations say “match the option if the stock goes up” and “match it if the stock goes down”.

Step by step

  1. X1 = Δ0 S1 + (1 + r)(X0 − Δ0 S0)Hold Δ0 shares; whatever money is left (possibly negative, a loan) sits in cash and earns r.
  2. X1(H) = V1(H),   X1(T) = V1(T)Replication: the portfolio must pay exactly what the option pays, in both outcomes.
  3. Δ0 = V1(H) − V1(T)S1(H) − S1(T)Subtract one equation from the other: the cash part cancels, leaving only the shares.
  4. X0 = 11 + r[p̃ V1(H) + q̃ V1(T)]Put Δ0 back into either equation and tidy up.
  5. p̃ = 1 + r − du − d,   q̃ = u − 1 − ru − dThese weights simply fall out of the algebra. Nobody chose them as forecasts.

Worked numbers

S0 = 100, u = 1.2, d = 0.9, r = 5%, call with strike 100. The stock ends at 120 or 90, so the call pays 20 or 0.

  • Δ0 = (20 − 0) / (120 − 90) = 0.6667 shares
  • p̃ = (1.05 − 0.9) / 0.3 = 0.5, so the price is 0.5 × 20 / 1.05 = 9.524
  • Buy 0.6667 shares (66.67) and borrow 57.14 to pay for most of them.
  • Up: 0.6667 × 120 − 57.14 × 1.05 = 80 − 60 = 20 ✓   Down: 60 − 60 = 0 ✓

Common mistake: Plugging in the real chance of an up move. Also forgetting that the cash leg is usually a loan: for a call you borrow to buy shares.

Why the pricing weights must sit between 0 and 1

Picture it

If cash always does at least as well as the stock, nobody should hold the stock: you could short it, put the money in the bank, and never lose. The condition d < 1 + r < u is exactly “neither asset beats the other in every outcome”.

Step by step

  1. p̃ > 0  ⇔  d < 1 + rIf even the down move beats cash, borrow and buy the stock: you can only gain.
  2. p̃ < 1  ⇔  1 + r < uIf cash beats even the up move, short the stock and invest the money: you can only gain.
  3. 0 < p̃ < 1  ⇔  no arbitrageSo the weights look like probabilities exactly when the model has no free lunch.

Worked numbers

Take u = 1.04, d = 0.9, r = 5%, so cash beats even the up move.

  • Short 1 share at 100 and put 100 in the bank: it grows to 105.
  • Buying the share back costs at most 100 × 1.04 = 104.
  • Profit of at least 1 with no risk: an arbitrage. Here p̃ = (1.05 − 0.9) / 0.14 = 1.07, outside 0 to 1.

Common mistake: Calling p̃ “the probability the stock goes up”. It is a pricing weight that happens to add up like a probability.

Many periods: the wealth equation and a hedge that changes every step

Picture it

Pricing over many periods is one-period pricing done again and again, starting at the end and walking back to today. The hedge is not set once: after every move you re-solve the little two-equation problem at your new node.

Step by step

  1. Xn+1 = Δn Sn+1 + (1 + r)(Xn − Δn Sn)The wealth equation. It is self-financing: you only rebalance between stock and cash, never add or take out money.
  2. VN = payoff(SN)At expiry the value is just the payoff.
  3. Vn = p̃ Vn+1(H) + q̃ Vn+1(T)1 + rAt every earlier node, apply the one-period formula to the two values just after it.
  4. Δn = Vn+1(H) − Vn+1(T)Sn+1(H) − Sn+1(T)Each node gets its own hedge, worked out from the two branches leaving it.

Worked numbers

Two periods, same inputs, strike 100. The stock ends at 144, 108 or 81, so the call pays 44, 8 or 0.

  • After an up move: V1(H) = (0.5 × 44 + 0.5 × 8) / 1.05 = 24.762, hedge Δ1(H) = (44 − 8) / (144 − 108) = 1.000
  • After a down move: V1(T) = (0.5 × 8 + 0.5 × 0) / 1.05 = 3.810, hedge Δ1(T) = 8 / (108 − 81) = 0.296
  • Today: V0 = (0.5 × 24.762 + 0.5 × 3.810) / 1.05 = 13.605, hedge Δ0 = (24.762 − 3.810) / 30 = 0.698
  • Follow this hedge along any path and you end with exactly 44, 8, 8 or 0, the call’s payoff.

Common mistake: Keeping today’s hedge for the whole life of the option. The hedge moves with the stock: it went from 0.698 to 1.000 after an up move and to 0.296 after a down move.

Path-dependent options: why the tree stops being small

Picture it

A plain option only cares where the stock ends, so “up then down” and “down then up” land on the same node. A lookback option remembers the highest price along the way, so those two paths are different situations and can no longer share a node.

Step by step

  1. staten = (Sn, Mn),   Mn = maxk≤n SkCarry whatever the payoff needs to remember. Here that is the running maximum.
  2. Vn(s, m) = p̃ Vn+1(us, max(m, us)) + q̃ Vn+1(ds, m)1 + rSame backward step, but each value now depends on the extra state as well.
  3. plain tree: N + 1 end nodes; all paths: 2NA good state variable keeps the problem far smaller than listing every path.

Worked numbers

  • 3 periods: 4 end nodes for a plain option, 8 distinct paths.
  • 20 periods: 21 end nodes versus 1,048,576 paths.
  • A lookback needs only the pairs (price, running max) that can actually occur, which grows far more slowly than 2N.

Common mistake: Pricing a path-dependent payoff on the ordinary recombining tree as if only today’s price mattered.

Every formula in this chapter

9 formulas in the order you meet them. Each one comes with what it means, where a quant uses it on the desk, a worked example and Python you can copy or run in your browser. The expected output is in the comments, and every snippet is run against it before the page goes live.

  1. 1.1The no-arbitrage condition
  2. 1.2The hedge ratio (delta)
  3. 1.3Risk-neutral probabilities
  4. 1.4The one-period price
  5. 1.5The wealth equation
  6. 1.6Backward induction
  7. 1.7The binomial pricing formula
  8. 1.8Path-dependent payoffs: carry the state
  9. 1.9From the textbook tree to a desk tree
1.1

The no-arbitrage condition

0 < d < 1 + r < u
no arbitraged 0.901+r 1.05u 1.20arbitraged 0.90u 1.041+r 1.05
Cash must land strictly between the down and up moves. Past the up move, cash beats the stock in every outcome.
What it means
The safe return has to sit strictly between the stock’s down and up returns. If cash beat the stock in both outcomes, or the stock beat cash in both, anyone could make money with no risk.
Where a quant uses it
The first check in any tree pricer. With steps set from volatility (card 1.9), low volatility, high rates and long steps can push 1 + r outside the range from d to u. The tree then prints a price with no error message, and the price is meaningless.
Example
u = 1.04, d = 0.9, r = 5%: cash grows to 1.05, which beats even the up move of 1.04. Short a share at 100, bank the 100, and you clear at least 1 whatever happens.
Remember it
Cash sits in the sandwich: down below it, up above it.
Python · runs as isRun in browser
def no_arbitrage(u, d, r):
    # neither cash nor stock may win in every outcome
    return 0 < d < 1 + r < u

print(no_arbitrage(1.2, 0.9, 0.05))   # True
print(no_arbitrage(1.04, 0.9, 0.05))  # False
1.2

The hedge ratio (delta)

Δ0 = V1(H) − V1(T)S1(H) − S1(T)
Δ₀ = (20 − 0) / (120 − 90) = 0.6667V₁S₁payoff90K 100120rise 20run 30T (90, 0)H (120, 20)
Delta is the slope of the blue line through the two outcomes: the option rises 20 while the stock rises 30.
What it means
How many shares make your portfolio move exactly like the option: how far the option’s value moves between the two outcomes, divided by how far the stock moves.
Where a quant uses it
This is the delta a trader actually holds. Tree pricers report it the same way, from the two nodes one step after today, and it changes at every node (card 1.6).
Example
A call struck at 100 on a stock at 100 that goes to 120 or 90 pays 20 or 0, so Δ0 = (20 − 0) / (120 − 90) = 0.6667 shares.
Remember it
Delta is rise over run: the option’s spread over the stock’s spread.
Python · runs as isRun in browser
def hedge_ratio(V_up, V_down, S_up, S_down):
    # shares to hold so the portfolio moves exactly like the option
    return (V_up - V_down) / (S_up - S_down)

S0, u, d, K = 100, 1.2, 0.9, 100
delta = hedge_ratio(max(S0*u - K, 0), max(S0*d - K, 0), S0*u, S0*d)
print(round(delta, 4))  # 0.6667
1.3

Risk-neutral probabilities

p̃ = 1 + r − du − d,   q̃ = u − 1 − ru − d
1+r−d 0.15u−1−r 0.15d 0.901+r 1.05u 1.20p̃ = 0.15 / 0.30 = 0.5q̃ = 0.50 < p̃ < 11+r−d 0.15d 0.90u 1.041+r 1.05p̃ = 0.15 / 0.14 = 1.0714q̃ = −0.0714p̃ > 1: arbitrage
p̃ is the green share of the bar, how far cash sits above d. When cash passes u, that share tops 1.
What it means
Two weights that add up to 1 and fall out of the replication algebra. They are not anyone’s forecast. They lie strictly between 0 and 1 exactly when card 1.1 holds.
Where a quant uses it
Every pricing engine (tree, Monte Carlo or PDE) prices with these weights, not with real-world odds. When a quant calibrates a model to market prices, they are fitting these weights, not predicting the market.
Example
u = 1.2, d = 0.9, r = 5% gives p̃ = 0.15 / 0.30 = 0.5. With u = 1.04 the same formula gives 1.07, which cannot be a probability: the model has an arbitrage.
Remember it
p̃ places cash on the d-to-u ruler: 0 at d, 1 at u.
Python · runs as isRun in browser
def risk_neutral(u, d, r):
    p = (1 + r - d) / (u - d)
    return p, 1 - p

p, q = risk_neutral(1.2, 0.9, 0.05)
print(round(p, 4), round(q, 4))  # 0.5 0.5
p, q = risk_neutral(1.04, 0.9, 0.05)
print(round(p, 4), round(q, 4))  # 1.0714 -0.0714
1.4

The one-period price

V0 = X0 = 11 + r[p̃ V1(H) + q̃ V1(T)]
V₀ 9.5240.6667 shloan 57.14p̃ 0.5q̃ 0.5V₁(H) 200.6667×120 − 60 = 20V₁(T) 00.6667×90 − 60 = 0V₀ = (0.5×20 + 0.5×0) / 1.05 = 9.524
Weigh the payoffs with p̃, discount once: 9.524. The copy (0.6667 shares, a 57.14 loan owing 60) pays 20 or 0 too.
What it means
The option is worth what it costs to build the stock-and-cash portfolio that copies it. Worked out, that cost is the two payoffs averaged with the card 1.3 weights, then discounted for one period.
Where a quant uses it
This is the pattern behind every price: discounted expected payoff under the pricing weights. A Monte Carlo pricer is the same formula, averaged over thousands of simulated outcomes instead of two.
Example
The call pays 20 or 0 and p̃ = 0.5, so V0 = 0.5 × 20 / 1.05 = 9.524. The copy is 0.6667 shares (66.67) paid for partly with a loan of 57.14.
Remember it
Weigh, then discount: the p̃-average payoff over 1 + r is what the copy costs.
Python · runs as isRun in browser
S0, u, d, r, K = 100, 1.2, 0.9, 0.05, 100
V_up, V_dn = max(S0*u - K, 0), max(S0*d - K, 0)
p = (1 + r - d) / (u - d)
V0 = (p*V_up + (1 - p)*V_dn) / (1 + r)

delta = (V_up - V_dn) / (S0*u - S0*d)
cash = V0 - delta*S0                 # negative: a loan
print(round(V0, 3), round(cash, 2))  # 9.524 -57.14
print(round(delta*S0*u + cash*(1 + r), 6), round(delta*S0*d + cash*(1 + r), 6))  # 20.0 0.0
1.5

The wealth equation

Xn+1 = Δn Sn+1 + (1 + r)(Xn − Δn Sn)
X₀X₁X₂payoff13.605Δ 0.698424.762Δ 13.810Δ 0.2963HH44=44HT8=8TH8=8TT0=0X₁(H) = 0.6984×120 + 1.05×(13.605 − 69.84) = 24.762
Nothing is added or taken out after the start, yet wealth lands exactly on each payoff: 44, 8, 8 and 0.
What it means
Wealth after a step is shares times the new price plus cash that has earned interest. Money only moves between stock and cash; you never add any or take any out. That is what “self-financing” means.
Where a quant uses it
This is the basis of hedge P&L explain. A delta-hedged book’s daily P&L is the option’s change, minus delta times the stock’s change, minus financing. Whatever is left over is hedging error, and risk teams look into it.
Example
Start with 13.605 (the two-period price from card 1.6) and rebalance after every move. You finish with exactly 44, 8, 8 or 0, the call’s payoff on each of the four paths.
Remember it
Shares ride the stock, the rest earns r in cash: nothing added, nothing taken.
Python · runs as isRun in browser
from itertools import product

S0, u, d, r, K, N = 100, 1.2, 0.9, 0.05, 100, 2
p = (1 + r - d) / (u - d)

def value(n, S):
    # option value at step n when the stock is at S (backward induction)
    if n == N:
        return max(S - K, 0)
    return (p*value(n + 1, S*u) + (1 - p)*value(n + 1, S*d)) / (1 + r)

for path in product("HT", repeat=N):
    X, S = value(0, S0), S0          # start with exactly the option price
    for n, move in enumerate(path):
        delta = (value(n + 1, S*u) - value(n + 1, S*d)) / (S*u - S*d)
        S_next = S*u if move == "H" else S*d
        X = delta*S_next + (1 + r)*(X - delta*S)   # the wealth equation
        S = S_next
    print("".join(path), round(X, 4), round(max(S - K, 0.0), 4))

# Output: wealth equals the payoff on every path
# HH 44.0 44.0
# HT 8.0 8.0
# TH 8.0 8.0
# TT 0.0 0.0
1.6

Backward induction

VN = payoff(SN),   Vn = p̃ Vn+1(H) + q̃ Vn+1(T)1 + r
todayn = 1expiry13.60510024.7621203.81090441448108081(0.5×44 + 0.5×8) / 1.05 = 24.762
Blue values start as payoffs at expiry and are averaged and discounted node by node, right to left, down to 13.605 today.
What it means
At expiry the value is just the payoff. Step back one period at a time, applying the card 1.4 formula at every node, until you reach today.
Where a quant uses it
Lattice pricers for American and Bermudan options, convertibles and callable bonds run this exact loop. Chapter 4 adds a single line that compares each value with exercising now.
Example
Two periods, strike 100: the payoffs 44, 8 and 0 become 24.762 and 3.810 one step earlier, then 13.605 today.
Remember it
Start at the leaves and fold back: each node is its two children, averaged and discounted.
Python · runs as isRun in browser
def binomial_price(S0, u, d, r, N, payoff):
    p = (1 + r - d) / (u - d)
    V = [payoff(S0 * u**k * d**(N - k)) for k in range(N + 1)]  # k = number of ups
    for n in range(N, 0, -1):
        V = [(p*V[k + 1] + (1 - p)*V[k]) / (1 + r) for k in range(n)]
    return V[0]

call = lambda S: max(S - 100, 0)
print(round(binomial_price(100, 1.2, 0.9, 0.05, 1, call), 3))  # 9.524
print(round(binomial_price(100, 1.2, 0.9, 0.05, 2, call), 3))  # 13.605
1.7

The binomial pricing formula

Follows from the chapter
V0 = 1(1 + r)N ∑k=0N N!k!(N − k)! p̃k q̃N−k (S0ukdN−k − K)+
0.251 pathk = 0S 81, pays 00.25 × 0 = 00.52 pathsk = 1S 108, pays 80.5 × 8 = 40.251 pathk = 2S 144, pays 440.25 × 44 = 11(0 + 4 + 11) / 1.05² = 15 / 1.1025 = 13.605
Each bar is paths × 0.25, since every two-step path has p̃-weight 0.5 × 0.5. Times payoffs, summed and discounted: 13.605.
What it means
If the payoff depends only on the final price, backward induction collapses into a single sum: the weight of each possible number of up moves, times the payoff there, discounted.
Where a quant uses it
A fast cross-check on any lattice for European payoffs. It is also the bridge to Black–Scholes: as N grows, the sum turns into the normal-distribution formula (card 1.9).
Example
N = 2: (0.25 × 44 + 0.5 × 8 + 0.25 × 0) / 1.052 = 15 / 1.1025 = 13.605, the same as backward induction.
Remember it
Count the paths to each end node, weight them by p̃ and q̃, pay, discount.
Python · runs as isRun in browser
from math import comb

def binomial_formula(S0, u, d, r, N, K):
    p = (1 + r - d) / (u - d)
    total = sum(comb(N, k) * p**k * (1 - p)**(N - k) * max(S0 * u**k * d**(N - k) - K, 0)
                for k in range(N + 1))
    return total / (1 + r)**N

print(round(binomial_formula(100, 1.2, 0.9, 0.05, 2, 100), 3))   # 13.605
print(round(binomial_formula(100, 1.2, 0.9, 0.05, 3, 100), 3))   # 17.45
1.8

Path-dependent payoffs: carry the state

Vn(s, m) = p̃ Vn+1(us, max(m, us)) + q̃ Vn+1(ds, m)1 + r
max 144129.6100HHT: max 144 − final 129.6 = 14.4THH: max 129.6 − final 129.6 = 020 steps: 2,761 states vs 1,048,576 paths
Two paths end at the same price yet pay 14.4 and 0, so each node must also carry the running maximum.
What it means
If the payoff remembers something about the path (here, the highest price so far), each node has to carry that memory too. Add the smallest extra state the payoff needs, and the same backward step still works.
Where a quant uses it
Exotics desks price lookbacks, Asians and barriers by adding a state to a lattice or PDE, or with Monte Carlo. Choosing a small state is what keeps them fast enough to use.
Example
A three-period lookback paying (highest price − final price), same inputs: 8.4116. Over 20 small steps, 2,761 states do the job of 1,048,576 paths.
Remember it
If the payoff remembers, the node must too: carry (price, running max).
Python · runs as isRun in browser
from functools import lru_cache

def lookback(S0, u, d, r, N):
    # pays (highest price on the path) - (final price)
    # state = (step, number of up moves, running max)
    p = (1 + r - d) / (u - d)
    S = lambda n, k: S0 * u**k * d**(n - k)

    @lru_cache(maxsize=None)
    def V(n, k, M):
        if n == N:
            return M - S(n, k)
        up = S(n + 1, k + 1)
        return (p*V(n + 1, k + 1, max(M, up)) + (1 - p)*V(n + 1, k, M)) / (1 + r)

    return V(0, 0, S0), V.cache_info().currsize

price, states = lookback(100, 1.2, 0.9, 0.05, 3)
print(round(price, 4))  # 8.4116
price, states = lookback(100, 1.02, 0.98, 0.001, 20)
print(states, "states vs", 2**20, "paths")  # 2761 states vs 1048576 paths
1.9

From the textbook tree to a desk tree

Beyond the chapter
u = eσ√Δt,   d = 1u,   p̃ = erΔt − du − d
10 steps1001,000Black–Scholes10.4506odd Neven N10.253410.430610.4486
More steps, closer to the dashed Black–Scholes line: 10.2534 at 10 steps, 10.4486 at 1,000, with odd and even step counts on either side.
What it means
Set the up and down moves from volatility so that the tree matches the market. As the number of steps grows, the price closes in on Black–Scholes. Here r is a yearly rate with continuous compounding.
Where a quant uses it
This is the standard Cox–Ross–Rubinstein (CRR) setup for equity trees. Model validation checks that prices converge as the steps increase, and how much they wiggle up and down along the way.
Example
S = K = 100, one year, r = 5%, σ = 20%: 10.2534 with 10 steps, 10.4306 with 100, 10.4486 with 1,000. Black–Scholes gives 10.4506.
Remember it
In log price each step is ±σ√Δt, and p̃ makes the stock grow at r.
Python · runs as isRun in browser
import numpy as np
from math import erf, exp, log, sqrt

def crr_call(S0, K, T, r, sigma, N):
    dt = T / N
    u = exp(sigma * sqrt(dt)); d = 1 / u
    p = (exp(r * dt) - d) / (u - d)
    k = np.arange(N + 1)
    V = np.maximum(S0 * u**k * d**(N - k) - K, 0.0)
    for _ in range(N):
        V = exp(-r * dt) * (p * V[1:] + (1 - p) * V[:-1])
    return V[0]

def bs_call(S0, K, T, r, sigma):
    Phi = lambda x: 0.5 * (1 + erf(x / sqrt(2)))
    d1 = (log(S0 / K) + (r + sigma**2 / 2) * T) / (sigma * sqrt(T))
    return S0 * Phi(d1) - K * exp(-r * T) * Phi(d1 - sigma * sqrt(T))

for N in (10, 100, 1000):
    print(N, round(crr_call(100, 100, 1, 0.05, 0.2, N), 4))
print("Black-Scholes", round(bs_call(100, 100, 1, 0.05, 0.2), 4))

# Output: the tree closes in on Black-Scholes
# 10 10.2534
# 100 10.4306
# 1000 10.4486
# Black-Scholes 10.4506

Where these ideas come from

Interview questions

Why does the real-world chance of an up move not affect the option price?

Because the option can be copied with stock and cash in every state. The cost of the copy depends only on the two possible outcomes, not on how likely they are, and any other price lets someone lock in a riskless profit.

One period, S₀ = 100, u = 1.1, d = 0.9, r = 0. What is the risk-neutral probability, and what is an at-the-money call worth?

p̃ = (1 − 0.9)/(1.1 − 0.9) = 0.5. The call pays 10 or 0, so it is worth 0.5 × 10 = 5.

Stochastic Calculus for Quants: Interview Playbook →

Volume I · Chapter 2

Probability Theory on Coin Toss Space

Make “expected value” and “what we know so far” precise on coin tosses, and meet the martingale: a process whose best forecast of tomorrow is today.

Picture it

A martingale is a fair game. If you toss a fair coin for 1 rupee a time, your expected money after the next toss is exactly what you have now, whatever you did before. Risk-neutral pricing turns every traded asset, once interest is stripped out, into such a fair game. Conditional expectation is simply your best guess given the tosses you have already seen, updated as each new toss comes in.

Everything lives on the set of possible coin-toss sequences. On that one set we can put two probability measures, the real-world one and the risk-neutral one, and compute expectations under each. A random variable is any number the tosses decide, such as the stock price after three tosses. Its expectation weights each outcome by its probability, and its variance, E[(X − E[X])2], measures how widely it spreads around that average.

Conditional expectation is the best estimate of a quantity given the first n tosses. Two rules carry most of the weight: the tower property (your forecast of a later forecast is today’s forecast) and taking out what is already known.

A martingale is a process whose conditional expectation of tomorrow equals today. Under the risk-neutral measure the discounted stock price is a martingale, and so is the discounted value of any self-financing portfolio. That gives the risk-neutral pricing formula. When the future depends on the past only through today’s state (the Markov property), prices become functions of the current stock price, which keeps the algorithms small.

Sn(1 + r)n = Ẽn[Sn+1(1 + r)n+1],   Vn = Ẽn[VN(1 + r)N−n]

Reading the formula: Sn: stock price after n tosses · (1 + r)n: what 1 in cash grows to · Ẽn[…]: best guess under the pricing weights, given the first n tosses · VN: the payoff at the end

Live modelILLUSTRATIVE INPUTS

The distribution of the discounted stock price after N tosses under the real-world p and the risk-neutral p̃. Move p: the risk-neutral mean stays at S₀ = 100.

The hard parts, step by step

The ideas in this chapter that most people get stuck on, each with a picture, the derivation line by line, worked numbers and the trap to avoid.

Conditional expectation: your best guess, given what you have seen

Picture it

Halfway through a cricket match, your forecast of the final score depends on the overs already bowled. Conditional expectation is exactly that: an average over the tosses you have not seen yet, holding fixed the ones you have. Because it depends on what you have seen, it is itself random, one number per possible history.

Step by step

  1. En[X] = average of X over the tosses after n, with the first n held fixedThe definition. “What we know at time n” (a filtration) is just the first n tosses.
  2. En[aX + bY] = a En[X] + b En[Y]Linearity: averages add up.
  3. En[YX] = Y En[X]   if Y is known at time nTaking out what is known: anything already decided acts like a constant.
  4. En[Em[X]] = En[X],   n ≤ mTower property: your forecast today of a later forecast is today’s forecast.
  5. En[X] = E[X]   if X depends only on tosses after nIndependence: what you have seen tells you nothing about it.

Worked numbers

Throughout: S0 = 100, u = 1.2, d = 0.9, r = 5% per period, so p̃ = q̃ = 0.5. Where a real-world probability is needed we use p = 0.6 (illustrative).

  • After a head (S1 = 120): E1[S2] = 0.6 × 144 + 0.4 × 108 = 129.6
  • After a tail (S1 = 90): E1[S2] = 0.6 × 108 + 0.4 × 81 = 97.2
  • Tower check: E0[E1[S2]] = 0.6 × 129.6 + 0.4 × 97.2 = 116.64 = 100 × 1.082 ✓

Common mistake: Treating En[X] as a single number. Before the first toss it is a random variable: 129.6 or 97.2 depending on the first toss.

Why the discounted stock price is a martingale under p̃

Picture it

A martingale is a fair game: tomorrow’s expected value equals today’s. Under the pricing weights, the stock is expected to grow exactly like cash, so once you divide by cash growth, nothing is left over: the game is fair.

Step by step

  1. Ẽn[Sn+1] = p̃ u Sn + q̃ d SnTomorrow the stock is u Sn or d Sn.
  2. p̃ u + q̃ d = 1 + rPlug in p̃ = (1 + r − d)/(u − d): the pricing weights are built to make this true.
  3. Ẽn[Sn+1(1 + r)n+1] = (1 + r) Sn(1 + r)n+1 = Sn(1 + r)nDivide by the next period’s cash growth and the extra (1 + r) cancels.

Worked numbers

Throughout: S0 = 100, u = 1.2, d = 0.9, r = 5% per period, so p̃ = q̃ = 0.5. Where a real-world probability is needed we use p = 0.6 (illustrative).

  • p̃ u + q̃ d = 0.5 × 1.2 + 0.5 × 0.9 = 1.05 = 1 + r ✓
  • From S1 = 120: (0.5 × 144 + 0.5 × 108) / 1.05 = 120, so the discounted price does not drift.

Common mistake: Saying the stock itself is a martingale. It is the discounted stock, under p̃, that is fair. Under the real p = 0.6 it drifts upward.

Why every hedged portfolio is a martingale, and the pricing formula that follows

Picture it

If the stock is a fair game, then any strategy of buying and selling it, financed only by cash, is also a fair game: you cannot turn fair bets into an expected profit by changing your stake. And if the portfolio copies the option, the option’s price must be the fair-game value of its payoff.

Step by step

  1. Xn+1(1 + r)n+1 = Xn(1 + r)n + Δn(Sn+1(1 + r)n+1 − Sn(1 + r)n)Rewrite the wealth equation in discounted terms: new wealth = old wealth + shares × change in discounted price.
  2. Ẽn[bracket] = 0The bracket is the change in a martingale, so its expectation is zero; Δn is known at n and comes out.
  3. discounted Xn is a martingaleSo expected discounted wealth never changes.
  4. Vn = Ẽn[VN(1 + r)N−n]If XN = VN, the martingale property gives the risk-neutral pricing formula.

Worked numbers

Throughout: S0 = 100, u = 1.2, d = 0.9, r = 5% per period, so p̃ = q̃ = 0.5. Where a real-world probability is needed we use p = 0.6 (illustrative).

  • Two-period call, strike 100: paths HH, HT, TH, TT pay 44, 8, 8, 0, each with weight 0.25.
  • V0 = (0.25 × 44 + 0.5 × 8 + 0.25 × 0) / 1.052 = 15 / 1.1025 = 13.605
  • The same answer as working backwards through the tree in Chapter 1 ✓

Common mistake: Thinking risk-neutral pricing is an assumption about investors. It is a consequence: hedged portfolios are fair games under p̃.

Jensen’s inequality: why an option is worth more than its payoff at the average

Picture it

Average a curve that bends upwards and you land above the curve evaluated at the average. A call payoff bends upwards (flat, then rising), so the average payoff beats the payoff at the average price. That gap is the value of optionality.

Step by step

  1. φ convex  ⇒  E[φ(X)] ≥ φ(E[X])Jensen’s inequality. Convex means the chord between two points lies above the curve.
  2. φ(s) = (s − K)+ is convexThe call payoff.
  3. Ẽ[(SN − K)+] ≥ (Ẽ[SN] − K)+So the expected payoff is at least the payoff at the forward price.

Worked numbers

Throughout: S0 = 100, u = 1.2, d = 0.9, r = 5% per period, so p̃ = q̃ = 0.5. Where a real-world probability is needed we use p = 0.6 (illustrative).

  • Ẽ[S2] = 100 × 1.052 = 110.25, so the payoff at the average is 110.25 − 100 = 10.25
  • The average payoff is 0.25 × 44 + 0.5 × 8 = 15, which is larger ✓

Common mistake: Writing E[max(S − K, 0)] = max(E[S] − K, 0). That throws away exactly the time value of the option.

Markov processes: why prices become functions of today’s price

Picture it

If the future depends on the past only through where the stock is now, then two different histories that end at the same price must have the same option value. So instead of tracking every path, you only need a table of values by price.

Step by step

  1. Vn = vn(Sn)For a payoff that depends only on SN, the value at time n is a function of today’s price alone.
  2. vn(s) = p̃ vn+1(us) + q̃ vn+1(ds)1 + rThe backward step, written as a function of price instead of path.
  3. extra state when needed: (Sn, Mn), (Sn, running sum), …Path-dependent payoffs stay Markov once you add what they remember.

Worked numbers

Throughout: S0 = 100, u = 1.2, d = 0.9, r = 5% per period, so p̃ = q̃ = 0.5. Where a real-world probability is needed we use p = 0.6 (illustrative).

  • HT and TH both reach S2 = 108, so both carry the value v2(108) = 8.
  • v1(120) = 24.762 and v1(90) = 3.810, two numbers instead of a value for every path.

Common mistake: Assuming every process is Markov. The running maximum on its own is not; you need the pair (price, maximum).

Every formula in this chapter

10 formulas in the order you meet them. Each one comes with what it means, where a quant uses it on the desk, a worked example and Python you can copy or run in your browser. The expected output is in the comments, and every snippet is run against it before the page goes live.

  1. 2.1Probability on coin toss space
  2. 2.2Expectation and variance
  3. 2.3Conditional expectation
  4. 2.4Taking out what is known, and the tower property
  5. 2.5Martingales, and the discounted stock
  6. 2.6Hedged portfolios are martingales too
  7. 2.7The risk-neutral pricing formula
  8. 2.8Jensen’s inequality
  9. 2.9The Markov property
  10. 2.10Put–call parity
2.1

Probability on coin toss space

P(ω) = p#H(ω)q#T(ω),   P(A) = ∑ω∈A P(ω)
A: at least two headsnot AP 0.648P̃ 0.5HHH0.216HHT0.144HTH0.144THH0.144HTT0.096THT0.096TTH0.096TTT0.064P̃ 0.125 each
Under p = 0.6, more heads means more weight; under p̃ every sequence weighs 0.125. The event A just adds up its four sequences.
What it means
Ω is the set of every possible toss sequence, such as HHT. Each sequence gets a probability from its number of heads and tails, and an event (a set of sequences) gets the sum of its sequences’ probabilities. Put p̃ and q̃ in place of p and q and you get the risk-neutral measure P̃ on the same set.
Where a quant uses it
Every scenario engine is a finite probability space: a list of scenarios with weights that add up to 1. Risk models such as VaR weight their scenarios with real-world probabilities; pricing and CVA engines weight their paths with risk-neutral ones. Checking that the weights are positive and sum to 1 is the first test of any such engine.
Example
Three tosses give 8 sequences. With p = 0.6 (illustrative), P(HHT) = 0.6 × 0.6 × 0.4 = 0.144; with p̃ = 0.5 every sequence has 0.125. “At least two heads” has probability 0.648 under P and 0.5 under P̃.
Remember it
One sequence: a p per head, a q per tail. An event: add its sequences.
Python · runs as isRun in browser
from fractions import Fraction
from itertools import product

def prob(omega, p):
    # P(omega) = p^(number of heads) * q^(number of tails)
    return p**omega.count("H") * (1 - p)**omega.count("T")

Omega = ["".join(w) for w in product("HT", repeat=3)]   # all 8 sequences
p, p_tilde = Fraction(6, 10), Fraction(1, 2)            # real-world and pricing weights
A = [w for w in Omega if w.count("H") >= 2]             # the event "at least two heads"

print(len(Omega), sum(prob(w, p) for w in Omega), sum(prob(w, p_tilde) for w in Omega))  # 8 1 1
print(float(prob("HHT", p)), float(prob("HHT", p_tilde)))  # 0.144 0.125
print(float(sum(prob(w, p) for w in A)), float(sum(prob(w, p_tilde) for w in A)))  # 0.648 0.5
2.2

Expectation and variance

E[X] = ∑ω∈Ω X(ω) P(ω),   Var(X) = E[(X − E[X])2]
±1 sd = 22.55, Var 508.550.361440.481080.1681E[S₂] = 116.64
The mean, 116.64, is where the weighted outcomes balance; the bracket reaches one standard deviation, 22.55, either side of it.
What it means
The expectation weights every outcome by its probability and adds them up. The variance does the same for the squared distance from that average, so it measures how widely X spreads; its square root is the standard deviation. The same sums under P̃ give the averages used for pricing, written Ẽ.
Where a quant uses it
Pricing engines compute expectations and risk engines measure spread. The variance also sets the error bar on every Monte Carlo price: the standard error is the standard deviation of the simulated payoffs divided by √(number of paths), so four times the paths only halves the error.
Example
Two tosses with p = 0.6: S2 is 144, 108 or 81 with probabilities 0.36, 0.48 and 0.16. E[S2] = 116.64 and Var(S2) = 508.55, a standard deviation of 22.55. Under p̃ the mean is 110.25 = 100 × 1.052.
Remember it
Mean: weight each outcome. Variance: weight each squared miss from that mean.
Python · runs as isRun in browser
from itertools import product

S0, u, d, N = 100, 1.2, 0.9, 2

def S_N(w):
    return S0 * u**w.count("H") * d**w.count("T")

def E(X, p):
    # E[X] = sum over every toss sequence of X(omega) * P(omega)
    paths = map("".join, product("HT", repeat=N))
    return sum(X(w) * p**w.count("H") * (1 - p)**w.count("T") for w in paths)

mean = E(S_N, 0.6)
var = E(lambda w: (S_N(w) - mean)**2, 0.6)
print(round(mean, 2), round(var, 4), round(var**0.5, 2))  # 116.64 508.5504 22.55
print(round(E(S_N, 0.5), 2))  # 110.25
2.3

Conditional expectation

En[X](ω1…ωn) = ∑ p#Hq#T X(ω1…ωnωn+1…ωN)
after H1441080.60.40.6×144 + 0.4×108E₁[S₂] = 129.6after T108810.60.40.6×108 + 0.4×81E₁[S₂] = 97.2nothing seen yet: E₀[S₂] = 116.64
Each history gets its own forecast: 129.6 after a head, 97.2 after a tail. With nothing seen yet it is 116.64.
What it means
Hold the first n tosses fixed and average X over the tosses still to come: the sum runs over ωn+1…ωN, and #H and #T count the heads and tails among them. The answer depends on the tosses already seen, so En[X] is itself a random variable, one number per history.
Where a quant uses it
Exposure engines for CVA and potential future exposure compute exactly this on every simulated path at every future date: a trade’s value given the market up to that date. When there is no formula, they estimate it by regressing later cash flows on today’s state, the least-squares Monte Carlo method also used for American options.
Example
p = 0.6, two tosses. After a head, E1[S2] = 0.6 × 144 + 0.4 × 108 = 129.6; after a tail, 0.6 × 108 + 0.4 × 81 = 97.2. With n = 0 nothing is known yet, and E0[S2] = E[S2] = 116.64.
Remember it
Freeze the tosses you have seen, average the ones to come: one forecast per history.
Python · runs as isRun in browser
from itertools import product

S0, u, d, p, N = 100, 1.2, 0.9, 0.6, 2

def S2(w):
    return S0 * u**w.count("H") * d**w.count("T")

def cond_exp(X, seen):
    # average X over the tosses not yet seen, holding the first n fixed
    total = 0.0
    for rest in map("".join, product("HT", repeat=N - len(seen))):
        total += p**rest.count("H") * (1 - p)**rest.count("T") * X(seen + rest)
    return total

print(round(cond_exp(S2, "H"), 4), round(cond_exp(S2, "T"), 4))  # 129.6 97.2
print(round(cond_exp(S2, ""), 4))  # 116.64
2.4

Taking out what is known, and the tower property

En[YX] = Y En[X]  (Y known at n),   En[Em[X]] = En[X]  (n ≤ m)
in two stages144 108 81129.6 97.2S₂E₁[S₂]144 108 81at once: 0.36 0.48 0.16E₀[S₂]116.64taking out what is known, after H:E₁[S₁S₂] = 120 × 129.6 = 15,552
Averaging in two stages, through 129.6 and 97.2, lands on the same 116.64 as averaging once. Known numbers just multiply.
What it means
Anything the first n tosses already decide acts like a constant and comes outside the average. And your forecast today of a later forecast is just today’s forecast: averaging in two stages gives the same answer as averaging once. Shreve calls the second rule iterated conditioning.
Where a quant uses it
Taking out what is known is how today’s delta comes outside an expected hedge P&L (card 2.6). The tower property is why rolling a tree back one step at a time gives the same price as one big expectation, and why a price can be built in stages: value at an intermediate date, then discount that value back.
Example
After a head, S1 = 120 is known, so E1[S1S2] = 120 × 129.6 = 15,552. Tower: 0.6 × 129.6 + 0.4 × 97.2 = 116.64 = E[S2].
Remember it
Known now? Take it outside. A forecast of a later forecast is today’s forecast.
Python · runs as isRun in browser
from itertools import product

S0, u, d, p, N = 100, 1.2, 0.9, 0.6, 2

def S(w, n):
    # stock price after the first n tosses of the sequence w
    return S0 * u**w[:n].count("H") * d**w[:n].count("T")

def E_n(X, seen):
    total = 0.0
    for rest in map("".join, product("HT", repeat=N - len(seen))):
        total += p**rest.count("H") * (1 - p)**rest.count("T") * X(seen + rest)
    return total

# taking out what is known: after a head, S_1 = 120 acts as a constant
lhs = E_n(lambda w: S(w, 1) * S(w, 2), "H")
print(round(lhs, 4), round(120 * E_n(lambda w: S(w, 2), "H"), 4))  # 15552.0 15552.0

# tower property: E_0[ E_1[S_2] ] = E_0[S_2]
E1 = lambda w: E_n(lambda v: S(v, 2), w[:1])
print(round(E_n(E1, ""), 4), round(E_n(lambda w: S(w, 2), ""), 4))  # 116.64 116.64
2.5

Martingales, and the discounted stock

Mn = En[Mn+1],   Sn(1 + r)n = Ẽn[Sn+1(1 + r)n+1]
120today144108average, ÷ 1.05p 0.6: 123.43p̃ 0.5: 120
Under p̃ the next price, averaged and discounted, comes back to exactly 120; under p = 0.6 it drifts up to 123.43.
What it means
A martingale is a fair game: given everything seen so far, the best forecast of the next value is the current value. Under the pricing weights the stock, measured in units of cash, is one, because p̃u + q̃d = 1 + r makes it grow on average exactly like cash. Under the real-world p it is not.
Where a quant uses it
The martingale test. Model validation checks every Monte Carlo engine by averaging the discounted simulated price of each traded asset: it must come back to today’s price within the simulation’s standard error. If it does not, the drift, the discounting or the random numbers are wrong.
Example
From S1 = 120: (0.5 × 144 + 0.5 × 108) / 1.05 = 120, no drift. With p = 0.6 the same step gives 129.6 / 1.05 = 123.43. Over 100,000 simulated ten-step paths, the average discounted price comes back as 99.88, within two standard errors (0.15 each) of 100.
Remember it
Under p̃, the stock in cash units has no drift: tomorrow’s average is today.
Python · runs as isRun in browser
import random

S0, u, d, r = 100, 1.2, 0.9, 0.05
pt = (1 + r - d) / (u - d)                    # 0.5

def next_step(S, p):
    # E_n[S_(n+1)] / (1 + r): tomorrow's expected price in today's money
    return (p*u*S + (1 - p)*d*S) / (1 + r)

print(round(next_step(120, pt), 4), round(next_step(120, 0.6), 4))  # 120.0 123.4286

# martingale test of a simulator: the average discounted S_N must return to S_0
random.seed(1)
N, M = 10, 100_000
vals = []
for _ in range(M):
    heads = sum(random.random() < pt for _ in range(N))
    vals.append(S0 * u**heads * d**(N - heads) / (1 + r)**N)
mean = sum(vals) / M
se = (sum((x - mean)**2 for x in vals) / (M - 1) / M)**0.5   # standard error
print(round(mean, 2), round(se, 2), abs(mean - S0) < 2*se)  # 99.88 0.15 True
2.6

Hedged portfolios are martingales too

Xn(1 + r)n = Ẽn[Xn+1(1 + r)n+1]  for any Δn known at n
any deltasΔ 0.3Δ 1Δ −0.5mean of X₂/1.05²13.605start13.605p̃15.932p 0.6
Whatever deltas you pick, the expected discounted wealth under p̃ stays at the starting 13.605. Only real-world drift moves it.
What it means
Choose any number of shares Δn at each step, using only what you know at time n, and finance it with cash (the wealth equation, card 1.5). In discounted terms each step adds Δn times the change in the discounted stock, and under p̃ that change averages to zero. You cannot trade a fair game into an expected profit.
Where a quant uses it
A sanity check on hedging backtests and strategy simulators. Under the pricing weights, any self-financing strategy must show zero expected discounted P&L, whatever its deltas. A strategy that makes money in a risk-neutral simulation is peeking at future prices, or the simulator has the wrong drift.
Example
Start with 13.605 and hold 0.3 shares, then 1 share after a head or −0.5 after a tail. Under p̃ the expected discounted wealth after two steps is still 13.605. Under p = 0.6 it is 15.932, because the discounted stock now drifts up.
Remember it
Any deltas, chosen without peeking, keep a fair game fair: no expected discounted profit.
Python · runs as isRun in browser
from itertools import product

S0, u, d, r = 100, 1.2, 0.9, 0.05
pt = (1 + r - d) / (u - d)
X0 = 15 / 1.05**2                          # start with the two-period call price
delta = {"": 0.3, "H": 1.0, "T": -0.5}     # any shares, chosen from what is known so far

def mean_disc_wealth(p):
    total = 0.0
    for path in map("".join, product("HT", repeat=2)):
        X, S = X0, S0
        for n, move in enumerate(path):
            D = delta[path[:n]]
            S_next = S*u if move == "H" else S*d
            X, S = D*S_next + (1 + r)*(X - D*S), S_next   # the wealth equation
        total += p**path.count("H") * (1 - p)**path.count("T") * X
    return total / (1 + r)**2

print(round(X0, 4), round(mean_disc_wealth(pt), 4))  # 13.6054 13.6054
print(round(mean_disc_wealth(0.6), 4))  # 15.932
2.7

The risk-neutral pricing formula

Vn = Ẽn[VN(1 + r)N−n]
p̃ = 0.5 on every branch, ÷ 1.05 per step13.60524.7623.81044S 1448S 1080S 81V₀V₁payoff V₂
Each value is the p̃-average of the payoffs it can still reach, discounted over the periods left: 13.605 today.
What it means
If a self-financing portfolio ends at the payoff VN on every path, card 2.6 says its discounted value is a fair game under p̃. So its value at time n, which is the option’s price, is the expected payoff given the first n tosses, discounted over the periods left. Real-world probabilities never enter.
Where a quant uses it
Every Monte Carlo pricer is this formula: simulate paths with the pricing weights, discount each payoff, average. For payoffs that depend on the whole path, such as Asian options and autocallables, it is often the only practical method.
Example
Two-period call, strike 100: V0 = (0.25 × 44 + 0.5 × 8 + 0.25 × 0) / 1.052 = 13.605. Given a head, V1 = (0.5 × 44 + 0.5 × 8) / 1.05 = 24.762; given a tail, 3.810. Both match backward induction (card 1.6).
Remember it
Given the path so far, average the payoff with p̃, then discount the periods left.
Python · runs as isRun in browser
from itertools import product

S0, u, d, r, K, N = 100, 1.2, 0.9, 0.05, 100, 2
pt = (1 + r - d) / (u - d)

def price(payoff, seen=""):
    # V_n: expected discounted payoff under the pricing weights, given the tosses seen
    n, total = len(seen), 0.0
    for rest in map("".join, product("HT", repeat=N - n)):
        path = seen + rest
        S_N = S0 * u**path.count("H") * d**path.count("T")
        total += pt**rest.count("H") * (1 - pt)**rest.count("T") * payoff(S_N)
    return total / (1 + r)**(N - n)

call = lambda S: max(S - K, 0)
print(round(price(call), 3))  # 13.605
print(round(price(call, "H"), 3), round(price(call, "T"), 3))  # 24.762 3.81
2.8

Jensen’s inequality

φ convex  ⇒  E[φ(X)] ≥ φ(E[X]),   En[φ(X)] ≥ φ(En[X])
(s − K)⁺average payoff 15payoff at average 10.25K 10081144mean 110.25
The average payoff, 15, sits above the payoff at the average price, 10.25, because the call payoff bends upwards at the strike.
What it means
Average a function that bends upwards and you land above the function of the average. The call payoff (s − K)+ bends upwards, so the expected payoff beats the payoff at the expected price. The gap is the option’s time value. The same holds for conditional expectations.
Where a quant uses it
Convexity is what option buyers pay for and what traders call gamma. Jensen is also why rates desks make convexity adjustments: a futures rate is not the forward rate, and a CMS rate or a rate paid in arrears needs a correction, because the expectation of a convex function is not the function of the expectation.
Example
Ẽ[S2] = 110.25, so the call’s payoff at the average price is 10.25. The average payoff is 15, which is larger. With φ(s) = s2 the gap is exactly the variance, 501.19.
Remember it
Convex: the average of the payoffs beats the payoff of the average.
Python · runs as isRun in browser
S0, u, d, r, K = 100, 1.2, 0.9, 0.05, 100
pt = (1 + r - d) / (u - d)
dist = {S0*u*u: pt**2, S0*u*d: 2*pt*(1 - pt), S0*d*d: (1 - pt)**2}   # S_2 and its weight

E = lambda f: sum(w * f(s) for s, w in dist.items())
call = lambda s: max(s - K, 0)

mean = E(lambda s: s)
print(round(mean, 2), round(call(mean), 2), round(E(call), 2))  # 110.25 10.25 15.0

# s^2 is convex too: the Jensen gap is exactly the variance
print(round(E(lambda s: s**2) - mean**2, 4))  # 501.1875
2.9

The Markov property

Ẽn[f(Sn+1)] = g(Sn),   vn(s) = p̃ vn+1(us) + q̃ vn+1(ds)1 + r
100120v₁ 24.76290v₁ 3.81014481108HTcall at 1088 either waylookback at 108HT 10.857TH 5.143
HT and TH meet at 108, so the call has one value there: 8. A lookback still remembers the path.
What it means
The future depends on the past only through today’s state. Any forecast about tomorrow’s price is a function of today’s price alone, here g(s) = p̃ f(us) + q̃ f(ds). So an option paying on SN is worth Vn = vn(Sn): two paths that end at the same price have the same value.
Where a quant uses it
This is why a PDE or lattice pricer stores one value per price level, not one per path, and why least-squares Monte Carlo can regress continuation values on today’s state. A path-dependent payoff gets an extra state variable (the running maximum, the running average, a knocked-out flag) to make the problem Markov again.
Example
HT and TH both reach 108, so both carry v2(108) = 8, and v1(120) = 24.762, v1(90) = 3.810. A three-period lookback is different: at 108 it is worth 10.857 after HT (maximum 120) but 5.143 after TH (maximum 108), so the price alone is not enough.
Remember it
Same price, same value: only where you are matters, not how you got there.
Python · runs as isRun in browser
S0, u, d, r = 100, 1.2, 0.9, 0.05
pt = (1 + r - d) / (u - d)

def v(n, s, N=2, K=100):
    # a call's value is a function of today's price s alone
    if n == N:
        return max(s - K, 0)
    return (pt*v(n + 1, s*u) + (1 - pt)*v(n + 1, s*d)) / (1 + r)

def lookback(n, s, m, N=3):
    # pays (running max - final price): needs the max m as well as s
    if n == N:
        return m - s
    up, down = lookback(n + 1, s*u, max(m, s*u)), lookback(n + 1, s*d, m)
    return (pt*up + (1 - pt)*down) / (1 + r)

print(round(v(1, 120), 3), round(v(1, 90), 3))  # 24.762 3.81
print(round(v(2, S0*u*d), 3), round(v(2, S0*d*u), 3))  # 8.0 8.0
print(round(lookback(2, 108, 120), 3), round(lookback(2, 108, 108), 3))  # 10.857 5.143
2.10

Put–call parity

Follows from the chapter
Cn − Pn = Sn − K(1 + r)N−n
19−19putcallcall − put = S − KK 100today: 13.605 − 4.308 = 9.297= 100 − 100 / 1.05²
Call minus put pays S − K in every outcome, a straight line, so today it is worth S0 minus the discounted strike.
What it means
A call minus a put with the same strike and expiry pays (SN − K)+ − (K − SN)+ = SN − K whatever happens. Linearity of Ẽn and the martingale property of the discounted stock (card 2.5) turn that into today’s prices, with no view on volatility needed.
Where a quant uses it
Equity option desks read the market’s forward, and from it the implied dividends or borrow cost, from pairs of listed calls and puts at the same strike. A pair that breaks parity by more than the bid–ask spread flags a stale quote or a mispricing.
Example
Two periods, strike 100: the call C0 is worth 13.605. The put pays 19 only after TT, so P0 = 0.25 × 19 / 1.052 = 4.308. C0 − P0 = 9.297 = 100 − 100 / 1.052.
Remember it
Long call, short put is a forward: stock minus the strike’s present value.
Python · runs as isRun in browser
from math import comb

S0, u, d, r, K, N = 100, 1.2, 0.9, 0.05, 100, 2
pt = (1 + r - d) / (u - d)

def price(payoff):
    # risk-neutral pricing formula for a payoff on S_N (card 2.7)
    total = sum(comb(N, k) * pt**k * (1 - pt)**(N - k) * payoff(S0 * u**k * d**(N - k))
                for k in range(N + 1))
    return total / (1 + r)**N

C = price(lambda S: max(S - K, 0))
P = price(lambda S: max(K - S, 0))
print(round(C, 3), round(P, 3))  # 13.605 4.308
print(round(C - P, 4), round(S0 - K / (1 + r)**N, 4))  # 9.2971 9.2971

Where these ideas come from

Interview questions

Is the stock price a martingale under the real-world measure?

Usually not. It grows on average at its real expected return. Only the discounted price, under the risk-neutral measure, is a martingale.

State the tower property in one line.

For n ≤ m, En[Em[X]] = En[X]: your forecast today of a later forecast is just today’s forecast.

Stochastic Calculus for Quants: Interview Playbook →

Volume I · Chapter 3

State Prices

Every possible future state has a price today. An option’s price is its payoff in each state times that state’s price, added up.

Picture it

Imagine a shop that sells one ticket for each possible future: “pays 1 if the market crashes”, “pays 1 if it booms”, and so on. The ticket prices are the state prices. Any investment is just a basket of these tickets, so its price is the sum of its tickets. Crash tickets cost the most for how likely they are, because everyone wants money when times are bad. It is the same reason insurance costs more than the expected claim.

The Radon–Nikodym derivative Z is the ratio of risk-neutral to real-world probability, state by state. It converts one expectation into the other: Ẽ[X] = E[Z X].

Divide Z by the growth of cash and you get the state price density ζ. Now prices are real-world expectations of payoff times ζ. When the stock is expected to beat cash, ζ is highest in the states where the stock has done badly: insurance against bad states is expensive.

The same object solves the investor’s problem: choose the best terminal wealth in terms of ζ, subject to its price being today’s wealth, then replicate it. That is the martingale (or dual) approach to portfolio choice.

Z = P̃(ω)P(ω),   ζ = Z(1 + r)N,   V0 = E[ζ VN] = ∑ω ζ(ω) VN(ω) P(ω)

Reading the formula: ω: one possible future (one sequence of tosses) · P, P̃: real-world and pricing probabilities of it · Z: their ratio · ζ: the ticket price of that future per unit of real probability · VN: the payoff

Live modelILLUSTRATIVE INPUTS

Bars show how likely each number of heads is; the line is the state-price density. The prices of all states add up to the discount factor.

The hard parts, step by step

The ideas in this chapter that most people get stuck on, each with a picture, the derivation line by line, worked numbers and the trap to avoid.

The Radon–Nikodym derivative Z: switching between two sets of probabilities

Picture it

Think of Z as an exchange rate between two currencies of probability. For each future path it tells you how much more (or less) weight the pricing measure gives that path than the real world does. Multiply by Z and a real-world average becomes a pricing average.

Step by step

  1. Z(ω) = P̃(ω)P(ω)One number per path: pricing probability over real probability.
  2. Z > 0,   E[Z] = 1Both measures agree on what is possible, and Z re-weights without creating or losing total probability.
  3. Ẽ[X] = E[Z X]Change of measure: any pricing expectation is a real-world expectation re-weighted by Z.

Worked numbers

Two tosses with real-world p = 0.6 (illustrative) and pricing weight p̃ = 0.5, same stock as before.

  • Z(HH) = 0.25 / 0.36 = 0.694   Z(HT) = Z(TH) = 0.25 / 0.24 = 1.042   Z(TT) = 0.25 / 0.16 = 1.563
  • E[Z] = 0.36 × 0.694 + 0.48 × 1.042 + 0.16 × 1.563 = 1 ✓
  • Bad paths get more weight: the pricing measure is pessimistic compared with the real world.

Common mistake: Forgetting that Z must be strictly positive. If one measure says a path is impossible and the other does not, there is no Z and pricing breaks.

Z over time and the change of measure inside a conditional expectation

Picture it

Before the game ends you do not know the final Z, so you track your best guess of it, Zn. When you change measure halfway through, you must divide by what you already know about Z, a bit like re-normalising after you learn the first toss.

Step by step

  1. Zn = En[Z]The Radon–Nikodym process: a martingale under the real-world measure.
  2. Ẽn[Y] = En[Z Y]ZnBayes’ rule for conditional expectations. Dividing by Zn corrects for the information already revealed.

Worked numbers

Two tosses with real-world p = 0.6 (illustrative) and pricing weight p̃ = 0.5, same stock as before.

  • Z1(H) = 0.6 × 0.694 + 0.4 × 1.042 = 0.833 = 0.5 / 0.6   Z1(T) = 1.25 = 0.5 / 0.4
  • After a head: (0.6 × 0.694 × 144 + 0.4 × 1.042 × 108) / 0.833 = (60 + 45) / 0.833 = 126
  • Direct check: 0.5 × 144 + 0.5 × 108 = 126 ✓

Common mistake: Using En[Z Y] without dividing by Zn. That gives 105 instead of 126 here.

State prices: pricing with real-world probabilities

Picture it

Each future path has a ticket price today. Divide that ticket price by how likely the path really is and you get ζ, the price per unit of probability. Prices are then ordinary real-world averages of payoff times ζ.

Step by step

  1. ζ(ω) = Z(ω)(1 + r)NThe state price density: Z and discounting rolled into one.
  2. price of a path’s ticket = ζ(ω) P(ω)The cost today of receiving 1 if and only if that path happens.
  3. V0 = E[ζ VN] = ∑ω ζ(ω) P(ω) VN(ω)Any payoff is a basket of tickets.

Worked numbers

Two tosses with real-world p = 0.6 (illustrative) and pricing weight p̃ = 0.5, same stock as before.

  • ζ(HH) = 0.694 / 1.1025 = 0.630   ζ(HT) = ζ(TH) = 0.945   ζ(TT) = 1.417
  • Call price: 0.36 × 0.630 × 44 + 0.48 × 0.945 × 8 = 9.977 + 3.628 = 13.605 ✓

Common mistake: Thinking ζ is the same in every state. It is highest in bad states, which is why insurance against bad states is expensive.

Optimal investment with state prices (log utility)

Picture it

Instead of picking trades period by period, pick the final wealth you want in each possible future, subject to its price matching your money today. Then build the trades that deliver it. The state prices turn a hard multi-period problem into one shopping problem.

Step by step

  1. maximise E[log XN]   subject to   E[ζ XN] = X0Best expected utility you can afford.
  2. 1XN(ω) = λ ζ(ω)Lagrange multiplier: set the derivative of utility equal to λ times the price, path by path.
  3. XN = X0ζPut this into the budget: E[ζ · 1/(λζ)] = 1/λ = X0.
  4. then replicate XNAny payoff can be replicated in this model, so the wealth you chose is achievable.

Worked numbers

Two tosses with real-world p = 0.6 (illustrative) and pricing weight p̃ = 0.5, same stock as before.

  • X0 = 100: XN(HH) = 100 / 0.630 = 158.76, XN(HT) = XN(TH) = 105.84, XN(TT) = 70.56
  • Budget check: 0.36 × 0.630 × 158.76 + 0.48 × 0.945 × 105.84 + 0.16 × 1.417 × 70.56 = 100 ✓
  • You take less wealth in the expensive bad states and more in the cheap good ones.

Common mistake: Pricing the budget with real-world probabilities. The budget must use ζ; otherwise the plan is not affordable.

Every formula in this chapter

9 formulas in the order you meet them. Each one comes with what it means, where a quant uses it on the desk, a worked example and Python you can copy or run in your browser. The expected output is in the comments, and every snippet is run against it before the page goes live.

  1. 3.1The Radon–Nikodym derivative
  2. 3.2Changing measure in an expectation
  3. 3.3The Radon–Nikodym process
  4. 3.4Bayes’ rule for a change of measure
  5. 3.5The state price density
  6. 3.6Pricing with state prices
  7. 3.7Optimal investment: log utility
  8. 3.8Optimal investment: any utility
  9. 3.9State prices from call prices
3.1

The Radon–Nikodym derivative

Z(ω) = P̃(ω)P(ω),   Z > 0,   E[Z] = 1
P real (p = 0.6)P̃ pricing: 0.25 each0.36HH0.6940.24HT1.0420.24TH1.0420.16TT1.5625Z = P̃/PE[Z] = 0.36×0.694 + 0.48×1.042 + 0.16×1.5625 = 1
Z is the blue bar over the grey one: below 1 on HH, which the real world favours, and 1.5625 on the crash path TT.
What it means
For each path of coin tosses, Z says how much more (or less) weight the pricing measure gives that path than the real world does. It is strictly positive because both measures agree on which paths can happen, and its real-world average is 1 because both sets of probabilities add up to 1.
Where a quant uses it
Comparing what option prices imply with what history says. The chance of a large index fall read off put prices, divided by its real-world estimate, is a Z. For crash scenarios it sits well above 1, and that gap is what sellers of downside protection are paid for.
Example
Two tosses, real-world p = 0.6 (illustrative), p̃ = 0.5: Z(HH) = 0.25 / 0.36 = 0.694, Z(HT) = Z(TH) = 0.25 / 0.24 = 1.042, Z(TT) = 0.25 / 0.16 = 1.5625. Check: 0.36 × 0.694 + 0.48 × 1.042 + 0.16 × 1.5625 = 1.
Remember it
Z is new odds over old odds; averaged with the old odds, it gives 1.
Python · runs as isRun in browser
from fractions import Fraction as F
from itertools import product

p, pt = F(3, 5), F(1, 2)       # real-world p (illustrative) and pricing p~
P  = lambda w: p**w.count("H") * (1 - p)**w.count("T")
Pt = lambda w: pt**w.count("H") * (1 - pt)**w.count("T")
paths = ["".join(t) for t in product("HT", repeat=2)]

Z = {w: Pt(w) / P(w) for w in paths}   # one number per path
for w in paths:
    print(w, Z[w], f"{float(Z[w]):.4f}")
print("E[Z] =", sum(P(w) * Z[w] for w in paths))

# Output
# HH 25/36 0.6944
# HT 25/24 1.0417
# TH 25/24 1.0417
# TT 25/16 1.5625
# E[Z] = 1
3.2

Changing measure in an expectation

Ẽ[X] = E[Z X],   E[X] = Ẽ[XZ]
S₂ =81108144Preal0.160.480.36E[S₂] = 116.64Z×P= P̃0.250.50.25E[Z S₂] = 110.25 = 100 × 1.05²
Same three end prices. Weighting each by Z moves the balance point from 116.64 down to 110.25: growth at the safe 5% a step.
What it means
Any average under the pricing measure is a real-world average with each path re-weighted by Z, and dividing by Z takes you back. You never need a second model to move between the two.
Where a quant uses it
Change of numeraire. Rates desks price caplets and swaptions under the forward or annuity measure, and FX desks price quanto payoffs under the foreign measure, because each payoff is simplest there. Every such switch is this formula, with Z built from the ratio of the two numeraires.
Example
Same stock: S0 = 100, u = 1.2, d = 0.9. In the real world E[S2] = 0.36 × 144 + 0.48 × 108 + 0.16 × 81 = 116.64, growth of 8% a step. Re-weighted by Z: E[Z S2] = 0.25 × 144 + 0.5 × 108 + 0.25 × 81 = 110.25 = 100 × 1.052, growth at the safe rate, exactly as Ẽ[S2] should be.
Remember it
Into pricing, multiply by Z; back to the real world, divide by Z.
Python · runs as isRun in browser
from fractions import Fraction as F
from itertools import product

S0, u, d = 100, F(6, 5), F(9, 10)
p, pt = F(3, 5), F(1, 2)       # real-world (illustrative) and pricing
paths = ["".join(t) for t in product("HT", repeat=2)]
P  = {w: p**w.count("H") * (1 - p)**w.count("T") for w in paths}
Pt = {w: pt**w.count("H") * (1 - pt)**w.count("T") for w in paths}
Z  = {w: Pt[w] / P[w] for w in paths}
S2 = {w: S0 * u**w.count("H") * d**w.count("T") for w in paths}

print("E[S2] =", float(sum(P[w] * S2[w] for w in paths)))          # E[S2] = 116.64
print("E[Z S2] =", float(sum(P[w] * Z[w] * S2[w] for w in paths))) # E[Z S2] = 110.25
print("E~[S2] =", float(sum(Pt[w] * S2[w] for w in paths)))        # E~[S2] = 110.25
3.3

The Radon–Nikodym process

Zn = En[Z] = (p̃p)#H(q̃q)#T
Z₀ = 15/65/4H ×5/6T ×5/425/36 = 0.69425/24 = 1.04225/16 = 1.5625from H: 0.6×25/36 + 0.4×25/24 = 5/6
Each head multiplies Z by 5/6, each tail by 5/4. From any node, the real-world average of the next value is today’s.
What it means
Your best real-world estimate of Z after n tosses. In the binomial model it is a running product: multiply by p̃/p after each head and by q̃/q after each tail (q = 1 − p), where #H and #T count the heads and tails so far. It starts at Z0 = 1 and is a martingale under the real-world measure: its expected next value is always today’s value.
Where a quant uses it
Importance sampling in Monte Carlo. To price a deep out-of-the-money option, simulate under a measure that reaches the payoff more often and carry a weight along each path, multiplied at every step by the ratio of the two probabilities. That weight is a Zn, and checking that its sample average stays near 1 at every date is the standard test of the code.
Example
Z1(H) = 0.5 / 0.6 = 5/6 and Z1(T) = 0.5 / 0.4 = 5/4, so E[Z1] = 0.6 × 5/6 + 0.4 × 5/4 = 0.5 + 0.5 = 1. After a head, Z2 is (5/6)2 = 25/36 = 0.694 or 5/6 × 5/4 = 25/24 = 1.042, and 0.6 × 25/36 + 0.4 × 25/24 = 5/12 + 5/12 = 5/6 again.
Remember it
A running tally from 1: times p̃/p per head, times q̃/q per tail.
Python · runs as isRun in browser
from fractions import Fraction as F

p, pt = F(3, 5), F(1, 2)       # real-world (illustrative) and pricing

def Z_n(tosses):
    # one factor per toss seen so far
    z = F(1)
    for t in tosses:
        z *= pt / p if t == "H" else (1 - pt) / (1 - p)
    return z

print(Z_n("H"), Z_n("T"))                               # 5/6 5/4
print(Z_n("HH"), Z_n("HT"), Z_n("TT"))                  # 25/36 25/24 25/16
print(p * Z_n("H") + (1 - p) * Z_n("T"))                # 1
print(p * Z_n("HH") + (1 - p) * Z_n("HT") == Z_n("H"))  # True
3.4

Bayes’ rule for a change of measure

Ẽn[Y] = En[Z Y]Zn
after a head: S₁ = 120, Z₁ = 5/6S₂ = 144S₂ = 1080.6×25/36=5/120.4×25/24=5/12real×Z₂adds to 5/6: E₁[Z S₂] = 60 + 45 = 1055/12 ÷ 5/6 = 1/25/12 ÷ 5/6 = 1/2÷ Z₁adds to 1: 105 ÷ 5/6 = 126 = 1.05 × 120
The re-weighted chances of the two open paths add to only 5/6. Dividing by Z1 = 5/6 restores 1 and gives 126.
What it means
To get a pricing forecast after n tosses from real-world averages, re-weight by Z and then divide by Zn, the part of Z already revealed. Without the division, the re-weighted chances of the paths still open do not add up to 1.
Where a quant uses it
Mid-life valuation in exposure simulation. A counterparty-risk engine runs real-world scenarios to a future date and then needs each trade’s pricing value in every scenario. That value is a conditional pricing expectation: dividing by Zn makes it depend only on what can happen next, not on how likely the scenario was to arise.
Example
After a head (S1 = 120): E1[Z S2] = 0.6 × 25/36 × 144 + 0.4 × 25/24 × 108 = 60 + 45 = 105. Divide by Z1(H) = 5/6 to get 126 = 1.05 × 120. After a tail: (67.5 + 50.625) / (5/4) = 118.125 / 1.25 = 94.5 = 1.05 × 90. Forgetting the division gives 105 instead of 126.
Remember it
Bayes as always: re-weight the open paths by Z, then divide by their total, Zn.
Python · runs as isRun in browser
from fractions import Fraction as F

S0, u, d = 100, F(6, 5), F(9, 10)
p, pt = F(3, 5), F(1, 2)       # real-world (illustrative) and pricing
Z = lambda w: (pt / p)**w.count("H") * ((1 - pt) / (1 - p))**w.count("T")
S = lambda w: S0 * u**w.count("H") * d**w.count("T")
prob = lambda t: p if t == "H" else 1 - p     # real-world odds of the next toss

for first in "HT":
    EZS = sum(prob(t) * Z(first + t) * S(first + t) for t in "HT")   # E_1[Z S_2]
    direct = pt * S(first + "H") + (1 - pt) * S(first + "T")         # E~_1[S_2]
    print(first, float(EZS), float(EZS / Z(first)), float(direct))

# Output: dividing by Z_1 gives the pricing expectation
# H 105.0 126.0 126.0
# T 118.125 94.5 94.5
3.5

The state price density

ζ(ω) = Z(ω)(1 + r)N,   ∑ω ζ(ω) P(ω) = 1(1 + r)N
ζ(ω)per unit ofreal prob.0.630HH1440.22680.945HT1080.22680.945TH1080.22681.417TT810.2268stock S₂ticket ζPsum of tickets = 0.9070 = 1/1.05²
ζ is highest where the stock fell, yet every path’s ticket costs the same 0.2268, and the four add up to the discount factor.
What it means
ζ(ω)P(ω) is the price today of a ticket that pays 1 if and only if path ω happens, and ζ is that price per unit of real probability. Holding every ticket pays 1 for sure, so the ticket prices add up to the discount factor. When the stock is expected to beat cash, ζ is highest on the paths where the stock did badly.
Where a quant uses it
Insurers’ economic scenario generators. They simulate real-world scenarios and attach a “deflator” to each one, which is ζ. Market-consistent values are then plain averages of deflated cash flows, and the standard test is that deflated bond and equity prices average back to today’s market prices.
Example
ζ(HH) = 0.6944 / 1.1025 = 0.630, ζ(HT) = ζ(TH) = 0.945, ζ(TT) = 1.417. Every path’s ticket costs 0.25 / 1.1025 = 0.2268 (its p̃-probability, discounted), and the four add up to 1 / 1.1025 = 0.9070, the two-period discount factor. Per unit of real probability, the TT ticket costs 2.25 times the HH ticket.
Remember it
ζ is Z, discounted; all the tickets together are a zero-coupon bond.
Python · runs as isRun in browser
from fractions import Fraction as F
from itertools import product

p, pt, r, N = F(3, 5), F(1, 2), F(1, 20), 2
paths = ["".join(t) for t in product("HT", repeat=N)]
P = {w: p**w.count("H") * (1 - p)**w.count("T") for w in paths}
Z = {w: (pt / p)**w.count("H") * ((1 - pt) / (1 - p))**w.count("T") for w in paths}
zeta = {w: Z[w] / (1 + r)**N for w in paths}

for w in paths:   # path, zeta, ticket price zeta * P
    print(w, f"{float(zeta[w]):.3f}", f"{float(zeta[w] * P[w]):.4f}")
print(f"{float(sum(zeta[w] * P[w] for w in paths)):.4f}", f"{1 / 1.05**2:.4f}")

# Output: the tickets add up to the discount factor
# HH 0.630 0.2268
# HT 0.945 0.2268
# TH 0.945 0.2268
# TT 1.417 0.2268
# 0.9070 0.9070
3.6

Pricing with state prices

V0 = E[ζ VN] = ∑ω ζ(ω) VN(ω) P(ω)
call, K = 100: payoff on each path44HH8HT8TH0TT× ticket ζP0.2268 each, sum:V₀ = 13.605put, K = 100: pays 19 on TT onlyprice4.308real avg2.757
The call is its payoffs times the ticket prices: 13.605. The put pays only on TT, where ζ is highest: 4.308, not the naive 2.757.
What it means
Any payoff is a basket of tickets, so its price is its payoff on each path times that path’s ticket price, added up. It is the same number as the risk-neutral price Ẽ[VN] / (1 + r)N, written with real-world probabilities.
Where a quant uses it
Short-rate trees (Hull–White, Black–Derman–Toy) are calibrated with Arrow–Debreu prices, the ticket price of each node. They are built forward one step at a time so that each step’s prices add up to that date’s discount factor, and every bond, cap or swaption on the tree is then its payoffs times these prices.
Example
Every path’s ticket ζP costs 0.25 / 1.1025. The call struck at 100 pays 44, 8, 8 or 0, so V0 = (44 + 8 + 8) × 0.25 / 1.1025 = 15 / 1.1025 = 13.605, as in chapter 1. The put struck at 100 pays 19 only on TT: 0.16 × 1.417 × 19 = 4.308, well above its discounted real-world average payoff, 0.16 × 19 / 1.1025 = 2.757. Insurance costs more than the expected claim.
Remember it
A payoff is a basket of tickets: payoff on each path times its ticket, summed.
Python · runs as isRun in browser
from fractions import Fraction as F
from itertools import product

S0, u, d, r, N, K = 100, F(6, 5), F(9, 10), F(1, 20), 2, 100
p, pt = F(3, 5), F(1, 2)       # real-world (illustrative) and pricing
paths = ["".join(t) for t in product("HT", repeat=N)]
P = {w: p**w.count("H") * (1 - p)**w.count("T") for w in paths}
zeta = {w: (pt / p)**w.count("H") * ((1 - pt) / (1 - p))**w.count("T") / (1 + r)**N for w in paths}
S2 = {w: S0 * u**w.count("H") * d**w.count("T") for w in paths}

price = lambda V: float(sum(zeta[w] * V(S2[w]) * P[w] for w in paths))   # E[zeta V_N]
print(f"{price(lambda S: max(S - K, 0)):.3f}")   # 13.605
print(f"{price(lambda S: max(K - S, 0)):.3f}")   # 4.308
naive = sum(P[w] * max(K - S2[w], 0) for w in paths) / (1 + r)**N
print(f"{float(naive):.3f}")                     # 2.757
3.7

Optimal investment: log utility

max E[log XN]  subject to  E[ζ XN] = X0  ⇒  XN = X0ζ
0ζwealthHH 158.760.630HT, TH 105.840.945TT 70.561.417wealth = 100/ζζ × wealth = 100on every path
Wealth falls as ζ rises: the cheapest path gets the most. Every point has ζ × XN = 100, so the plan costs exactly X0.
What it means
Choose the wealth you want on each path, not the trades. The budget prices that wealth with ζ. Setting the derivative of utility equal to λ times the price on every path gives 1/XN = λζ, and the budget then fixes λ = 1/X0. Finally replicate XN with stock and cash, which is always possible in this model.
Where a quant uses it
Log utility is the Kelly criterion. Its answer is a fixed fraction of wealth in the risky asset, rebalanced every period. Systematic traders size positions with a fraction of it (half-Kelly is common), because the full bet is very sensitive to errors in the estimated edge, here the real-world p.
Example
X0 = 100: XN = 100 / ζ is 158.76, 105.84, 105.84 or 70.56. The budget holds because ζ XN = 100 on every path, so E[ζ XN] = 100. The trades: keep 140% of wealth in the stock, borrowing the other 40%, so 100 becomes 126 or 84 after one step, then 158.76, 105.84 or 70.56.
Remember it
Log utility: wealth is budget ÷ ζ, so the cheapest path ends richest.
Python · runs as isRun in browser
from fractions import Fraction as F
from itertools import product

u, d, r, N, X0 = F(6, 5), F(9, 10), F(1, 20), 2, 100
p, pt = F(3, 5), F(1, 2)       # real-world (illustrative) and pricing
paths = ["".join(t) for t in product("HT", repeat=N)]
P = {w: p**w.count("H") * (1 - p)**w.count("T") for w in paths}
zeta = {w: (pt / p)**w.count("H") * ((1 - pt) / (1 - p))**w.count("T") / (1 + r)**N for w in paths}

X_N = {w: X0 / zeta[w] for w in paths}         # log-optimal terminal wealth
for w in paths:
    print(w, f"{float(X_N[w]):.2f}")
print("cost:", sum(zeta[w] * X_N[w] * P[w] for w in paths))

growth_up = (1 + r) * p / pt                    # X_1(H) / X_0
print("in stock:", float((growth_up - 1 - r) / (u - 1 - r)))

# Output
# HH 158.76
# HT 105.84
# TH 105.84
# TT 70.56
# cost: 100
# in stock: 1.4
3.8

Optimal investment: any utility

Follows from the chapter
U′(XN) = λζ  ⇒  XN = I(λζ),   E[ζ I(λζ)] = X0
U = log x: 140% in stock70.56105.84158.76U = −1/x (R = 2): 71% in stock89.10109.12133.65HHHT, THTTfinal wealth
Same rule, more risk aversion: the plan narrows from 70.56–158.76 to 89.10–133.65, and the stock holding falls from 140% to 71%.
What it means
The same recipe works for any increasing, strictly concave utility U. I is the inverse of the marginal utility U′, and λ is set so that the plan costs exactly today’s wealth. Cheap paths (low ζ) get more wealth and expensive ones less; the more risk-averse the investor, the smaller the gap.
Where a quant uses it
Asset allocation. The continuous-time version is Merton’s rule: hold (μ − r) / (Rσ2) of wealth in the risky asset, where R is relative risk aversion. Multi-asset and robo-advice models apply it with R set from the client’s risk profile.
Example
U(x) = −1/x (power utility xγ/γ with γ = −1, so R = 2) and X0 = 100: XN is 133.65, 109.12, 109.12 or 89.10, a much narrower range than log utility’s 70.56 to 158.76. The trades keep about 71% of wealth in the stock, close to half of log utility’s 140%, as Merton’s rule suggests.
Remember it
Marginal utility tracks price: U′(XN) = λζ, so dearer paths get less wealth.
Python · runs as isRun in browser
from itertools import product

u, d, r, N, X0, p, pt = 1.2, 0.9, 0.05, 2, 100, 0.6, 0.5   # p is illustrative
paths = ["".join(t) for t in product("HT", repeat=N)]
P = {w: p**w.count("H") * (1 - p)**w.count("T") for w in paths}
zeta = {w: (pt / p)**w.count("H") * ((1 - pt) / (1 - p))**w.count("T") / (1 + r)**N for w in paths}

def optimal_wealth(I):
    # X_N = I(lam * zeta); bisect on lam until the plan costs exactly X0
    lo, hi = 1e-9, 1e3
    for _ in range(200):
        lam = (lo * hi) ** 0.5
        cost = sum(zeta[w] * I(lam * zeta[w]) * P[w] for w in paths)
        lo, hi = (lam, hi) if cost > X0 else (lo, lam)
    return {w: I(lam * zeta[w]) for w in paths}

log = optimal_wealth(lambda y: 1 / y)            # U = log x (card 3.7)
power = optimal_wealth(lambda y: y ** -0.5)      # U = -1/x: gamma = -1, risk aversion 2
for w in paths:
    print(w, f"{log[w]:.2f}", f"{power[w]:.2f}")
X1 = (pt * power["HH"] + (1 - pt) * power["HT"]) / (1 + r)
print("in stock:", f"{(X1 / X0 - 1 - r) / (u - 1 - r):.4f}")

# Output: log utility, then risk aversion 2
# HH 158.76 133.65
# HT 105.84 109.12
# TH 105.84 109.12
# TT 70.56 89.10
# in stock: 0.7071
3.9

State prices from call prices

Beyond the chapter
π(K) = C(K − h) − 2C(K) + C(K + h)h,   ∂2C∂K2 = e−rT f̃(K)
long C(99), short 2 C(108), long C(117)pays 9 = h9911781108144S₂(14.2857 − 2×8.1633 + 6.1224) / 9 = 0.4535= 0.5 / 1.1025, the ticket for ending at 108
The butterfly pays a tent of height 9 that covers only the end price 108, so its price divided by 9 is that state’s ticket.
What it means
A butterfly spread (long one call at K − h, short two at K, long one at K + h) pays a tent of height h peaking at K, so divided by h it is the ticket π(K) that pays 1 if the stock ends at K. In the tree this is exact as long as no other end price lies strictly between K − h and K + h. With a continuum of strikes, the second derivative of the call price in the strike is the discounted pricing density f̃ of the stock at expiry (Breeden–Litzenberger).
Where a quant uses it
Vol desks read the market’s pricing distribution off listed option chains this way, then price digitals and other payoffs on the final price against it. The same second difference is the standard arbitrage check on a vol surface: a negative butterfly means a negative probability, and the surface must be fixed before anything is priced on it.
Example
On the two-period tree, calls struck at 99, 108 and 117 cost 14.2857, 8.1633 and 6.1224. With h = 9 the butterfly gives (14.2857 − 2 × 8.1633 + 6.1224) / 9 = 0.4535: the price of 1 paid if the stock ends at 108, which is 0.5 / 1.1025 (two paths, each with p̃-probability 0.25).
Remember it
Buy one call, sell two, buy one, divide by h: the ticket for ending at K.
Python · runs as isRun in browser
from math import comb

S0, u, d, r, N = 100, 1.2, 0.9, 0.05, 2
pt = (1 + r - d) / (u - d)
# the market's call prices (here made by the tree; on a desk, read off the screen)
ends = [(S0 * u**k * d**(N - k), comb(N, k) * pt**k * (1 - pt)**(N - k) / (1 + r)**N)
        for k in range(N + 1)]
call = lambda K: sum(pi * max(S - K, 0) for S, pi in ends)

h = 9
print(f"{call(99):.4f} {call(108):.4f} {call(117):.4f}")   # 14.2857 8.1633 6.1224
for S, pi in ends:   # butterfly around each end price vs the true state price
    fly = (call(S - h) - 2 * call(S) + call(S + h)) / h
    print(f"{S:.0f} {fly:.4f} {pi:.4f}")

# Output
# 14.2857 8.1633 6.1224
# 81 0.2268 0.2268
# 108 0.4535 0.4535
# 144 0.2268 0.2268

Where these ideas come from

Interview questions

Why are state prices higher in bad states?

Money is worth more to investors when they are poor. When the stock’s expected return beats the safe rate, the risk-neutral measure moves probability toward the down states, so their prices per unit of real probability go up.

What is the price of a security that pays 1 in every state at time N?

1/(1 + r)N, the discount factor. The state prices must add up to it.

Stochastic Calculus for Quants: Interview Playbook →

Volume I · Chapter 4

American Derivative Securities

When the holder can exercise at any time, the price comes from the best stopping rule: at every node, compare “exercise now” with “keep the option”.

Picture it

Think of a discount coupon you can use on any day before it expires. Each day you ask: is using it now worth more than keeping the chance to use it later? Usually waiting wins, because the future might be better. But for a put that is already deep in the money, cashing in now lets you start earning interest on the strike, and that beats waiting.

The backward step changes by one word: at each node the value is the larger of the payoff from exercising now and the discounted risk-neutral expectation of tomorrow’s value.

A stopping time is a rule for when to stop that uses only the information so far. The American price is the best expected discounted payoff over all such rules. Its discounted price is a supermartingale, falling on average, and a martingale up to the optimal exercise time.

For a call on a stock that pays no dividends, with positive rates, early exercise never helps, so the American call is worth the same as the European one. A put is different: deep in the money, receiving the strike now and earning interest on it beats waiting.

Vn = max{g(Sn), p̃ Vn+1(H) + q̃ Vn+1(T)1 + r},   V0 = maxτ Ẽ[g(Sτ)(1 + r)τ]

Reading the formula: g(Sn): what you get if you exercise now · the fraction: what keeping the option is worth · τ: a rule for when to stop, using only what you know so far · max over τ: the best such rule

Live modelILLUSTRATIVE INPUTS

A one-year American put, S₀ = 100, strike 100. Red nodes are where exercising now beats waiting. Raise the rate and watch the region and the premium grow.

The hard parts, step by step

The ideas in this chapter that most people get stuck on, each with a picture, the derivation line by line, worked numbers and the trap to avoid.

Stopping times: rules that never peek into the future

Picture it

A stopping time is a rule like “sell the first day the price drops below 90”. You can always tell, on the day, whether the rule says stop. “Sell on the day of the highest price” is not a stopping time, because you only know it was the highest afterwards.

Step by step

  1. τ is a stopping time  ⇔  whether {τ = n} happened is known from the first n tossesThe formal test.
  2. first time Sn ≤ 90   ✓Decided using only prices seen so far.
  3. time of the maximum of Sn   ✗Needs the whole future path.

Worked numbers

  • Path H then T: prices 100, 120, 108. “First time price ≤ 100” is never triggered: you know at every step.
  • “Time of the maximum” on that path is 1, but at time 1 you cannot know 120 will be the top until you see 108.

Common mistake: Choosing exercise using information you would not have yet, for example exercising “at the bottom”. Such strategies are not allowed, and pricing with them gives the wrong number.

The American algorithm, node by node

Picture it

At every node you compare two things: the cash you get by exercising now, and the value of keeping the option one more step. You keep the larger, and you work back from expiry.

Step by step

  1. VN = g(SN)At expiry it is just the payoff, here g(s) = (100 − s)+.
  2. Vn = max{g(Sn), p̃ Vn+1(H) + q̃ Vn+1(T)1 + r}Exercise now versus continue.
  3. V0 = maxτ Ẽ[g(Sτ)(1 + r)τ]Equivalently, the best stopping rule’s discounted expected payoff.

Worked numbers

American put with strike 100 on the two-period tree (S0 = 100, u = 1.2, d = 0.9, r = 5%, p̃ = 0.5).

  • At expiry the stock is 144, 108 or 81, so the put pays 0, 0 or 19.
  • Node S1 = 90: continue = 0.5 × 19 / 1.05 = 9.048, exercise = 10 → exercise, V = 10.
  • Node S1 = 120: both are 0.
  • Today: continue = 0.5 × 10 / 1.05 = 4.762, exercise = 0 → American put 4.762.
  • European put (no early exercise): 4.308, so the early-exercise premium is 0.454.

Common mistake: Forgetting the max at intermediate nodes, which gives the European price instead.

Supermartingales and the best time to exercise

Picture it

An American option is a fair game while you should still hold it, and turns into a losing game once you have passed the best exercise point. So its discounted value drifts down on average (a supermartingale), and stays level exactly until the optimal time to stop.

Step by step

  1. discounted Vn is a supermartingale under p̃Its expected value tomorrow is at most today’s.
  2. τ* = min{n : Vn = g(Sn)}Optimal rule: exercise the first time the option is worth only its payoff.
  3. discounted Vn ∧ τ* is a martingaleUp to τ*, nothing is lost by waiting.

Worked numbers

American put with strike 100 on the two-period tree (S0 = 100, u = 1.2, d = 0.9, r = 5%, p̃ = 0.5).

  • From today: Ẽ[V1] / 1.05 = (0.5 × 0 + 0.5 × 10) / 1.05 = 4.762 = V0: fair up to time 1.
  • At S1 = 90: Ẽ1[V2] / 1.05 = 9.048 < V1 = 10: waiting now loses value, so τ* = 1 on that path.

Common mistake: Holding past τ*. Once value equals payoff and continuing is worth less, every extra step loses money on average.

General American derivatives: when the payoff depends on the path

Picture it

A voucher that pays the gap between the highest price you have seen and today’s price. Two holders can stand at the same price today and still hold vouchers of different value, because one of them saw a higher peak on the way. The option has to remember the path, not just where the price is now.

Step by step

  1. Gn = maxk≤n Sk − SnThe exercise value depends on the whole path so far, so paths that meet at the same price cannot be merged.
  2. VN = GN,   Vn = max(Gn, p̃ Vn+1(H) + q̃ Vn+1(T)1 + r)The same backward rule as before, applied on every path: exercise now, or keep the fair value of waiting.
  3. Vn ≥ Gn, and discounted Vn is a supermartingale under p̃The price never falls below what exercising gives, and on average it never grows faster than cash.
  4. V is the smallest process with both propertiesAnything that dominates the payoff and is a discounted supermartingale costs at least as much. The price is the cheapest such process (the Snell envelope).
  5. τ* = min{n : Vn = Gn}Exercise the first time the option is worth no more than its exercise value.

Worked numbers

Two periods, S0 = 4, u = 2, d = 1/2, r = 25%, so p̃ = (1.25 − 0.5)/(2 − 0.5) = 0.5.

  • Paths HT and TH both end at S2 = 4, but pay 4 (the peak was 8) and 0 (the peak was 4). TT pays 3, HH pays 0.
  • At S1 = 8: V1 = max(0, (0.5 × 0 + 0.5 × 4)/1.25) = 1.6: hold.
  • At S1 = 2: exercising pays 4 − 2 = 2, waiting is worth (0.5 × 0 + 0.5 × 3)/1.25 = 1.2, so V1 = 2 and τ* = 1 on that path.
  • Today: V0 = (0.5 × 1.6 + 0.5 × 2)/1.25 = 1.44.

Common mistake: Pricing it on the price-only tree. Merging HT and TH at S = 4 averages a payoff of 4 with a payoff of 0, and the value comes out wrong.

Why an American call on a non-dividend stock is never exercised early

Picture it

Exercising a call early means paying the strike now instead of later, losing the interest on it, and giving up the protection the option gives if the stock falls. With no dividends, there is nothing to gain in return.

Step by step

  1. g(s) = (s − K)+ is convex with g(0) = 0The call payoff.
  2. g(λs) ≤ λ g(s),   0 ≤ λ ≤ 1A consequence of convexity and g(0) = 0.
  3. discounted g(Sn) is a submartingale under p̃Using Jensen with the discounted stock martingale: the discounted payoff drifts up on average.
  4. waiting to N is optimal, so American call = European callA submartingale is best stopped as late as possible (optional sampling).

Worked numbers

  • Same tree, call with strike 100: American = European = 13.605.
  • At S1 = 120: exercising gives 20 but holding is worth 24.762.

Common mistake: Applying this to puts, or to calls on dividend-paying stocks. Both can be worth exercising early.

Every formula in this chapter

10 formulas in the order you meet them. Each one comes with what it means, where a quant uses it on the desk, a worked example and Python you can copy or run in your browser. The expected output is in the comments, and every snippet is run against it before the page goes live.

  1. 4.1Intrinsic value
  2. 4.2The American pricing algorithm
  3. 4.3Hedging: delta and consumption
  4. 4.4Stopping times
  5. 4.5The price as the best stopping rule
  6. 4.6Supermartingale and optimal exercise
  7. 4.7Path-dependent American payoffs
  8. 4.8The American call without dividends
  9. 4.9The early-exercise boundary
  10. 4.10Exercise by regression (Longstaff–Schwartz)
4.1

Intrinsic value

Gn = g(Sn),   put: g(s) = K − s,   call: g(s) = s − K,   Vn ≥ max{Gn, 0}
K 100stock sput: G = K − sfloor max{G, 0}S 90: G = 10S 120: G = −20kept, not used
The option never sits below the blue floor: worth at least 10 at S = 90 and at least 0, not −20, at S = 120.
What it means
What you would get by exercising right now. It can be negative, for a put with the stock above the strike; the holder simply does not exercise then. So an American option is never worth less than the larger of Gn and 0.
Where a quant uses it
Cleaning listed option quotes before fitting a volatility surface. Listed single-stock options in the US are American, so an offer below max{Gn, 0} is stale or wrong: anyone could buy the option there and exercise it at once for a free profit. Such quotes are dropped before calibration.
Example
A put struck at 100 has G = 10 with the stock at 90, and −20 at 120, where the holder just keeps it. An offer of 9.50 at S = 90 is free money: pay 9.50 for the put and 90 for the stock, exercise, and receive 100, a profit of 0.50.
Remember it
Floor rule: an American option is never worth less than cashing it in now, or zero.
Python · runs as isRun in browser
def intrinsic(kind, S, K):
    # G_n = g(S_n): what exercising right now pays; it can be negative
    return K - S if kind == "put" else S - K

def below_floor(kind, quote, S, K):
    # an American offer under max(G_n, 0) is free money: buy it and exercise at once
    return quote < max(intrinsic(kind, S, K), 0)

print(intrinsic("put", 90, 100), intrinsic("put", 120, 100))  # 10 -20
print(intrinsic("call", 120, 100))         # 20
print(below_floor("put", 9.5, 90, 100))    # True
print(below_floor("put", 10.5, 90, 100))   # False
4.2

The American pricing algorithm

VN = max{GN, 0},   Vn = max{Gn, p̃ Vn+1(H) + q̃ Vn+1(T)1 + r}
S 1004.7619S 1200S 9010S 1440S 1080S 8119exercise 10 > wait 9.0476European 4.3084 · premium 0.4535
Before expiry, exercise wins only at S = 90 (10 against 9.0476), and that one max lifts the price from 4.3084 to 4.7619.
What it means
Chapter 1’s backward step with one change: at every node, keep the larger of exercising now and the discounted risk-neutral value of waiting. At expiry you exercise only if it pays.
Where a quant uses it
Lattice pricers for listed American equity options, and short-rate trees for Bermudan swaptions, run exactly this loop, with the max applied only on the allowed exercise dates. The gap to the European price, the early-exercise premium, is what desks take off American quotes to get European-equivalent prices before fitting a volatility surface.
Example
Put struck at 100 on the two-period tree (S0 = 100, u = 1.2, d = 0.9, r = 5%): 4.7619 against 4.3084 for the European, a premium of 0.4535. With r = 0 the premium is 0; at r = 10% it is 1.2856. On the S0 = 4, u = 2, d = 1/2, r = 1/4 tree used throughout the book, a two-period put struck at 5 is worth 1.36.
Remember it
Every node asks: exercise now, or wait? Keep the bigger, then step back.
Python · runs as isRun in browser
def price(S0, u, d, r, N, g, american=True):
    p = (1 + r - d) / (u - d)
    V = [max(g(S0 * u**k * d**(N - k)), 0) for k in range(N + 1)]   # V_N = max(G_N, 0)
    for n in range(N - 1, -1, -1):
        cont = [(p*V[k + 1] + (1 - p)*V[k]) / (1 + r) for k in range(n + 1)]
        # American: the larger of exercising now and continuing; European: always continue
        V = [max(g(S0 * u**k * d**(n - k)), c) if american else c for k, c in enumerate(cont)]
    return V[0]

put = lambda s: 100 - s
for r in (0.0, 0.05, 0.10):
    am = price(100, 1.2, 0.9, r, 2, put)
    eu = price(100, 1.2, 0.9, r, 2, put, american=False)
    print(r, round(am, 4), round(eu, 4), round(am - eu, 4))
print(round(price(4, 2, 0.5, 0.25, 2, lambda s: 5 - s), 4))

# Output: rate, American, European, early-exercise premium; then the S0 = 4 tree
# 0.0 8.4444 8.4444 0.0
# 0.05 4.7619 4.3084 0.4535
# 0.1 3.0303 1.7447 1.2856
# 1.36
4.3

Hedging: delta and consumption

Δn = Vn+1(H) − Vn+1(T)Sn+1(H) − Sn+1(T),   Cn = Vn − p̃ Vn+1(H) + q̃ Vn+1(T)1 + r,   Xn+1 = Δn Sn+1 + (1 + r)(Xn − Cn − ΔnSn)
S 100X 4.7619S 90X 10S 108X 0S 81X 19Δ −0.3333not exercisedΔ −0.7037take out C = 0.9524put pays 0put pays 19
The holder skips exercise at 90, so the seller withdraws 0.9524 and the rest still covers the payoff exactly: 0 or 19.
What it means
The seller starts with V0 and hedges with the usual delta. Where the holder should exercise but does not, the portfolio holds more than it needs, and the seller can take out Cn and still cover the option, whatever the holder does later. Cn is never negative, and it is 0 wherever waiting is optimal.
Where a quant uses it
This is the delta a desk holds against a short American put. Holders do not always exercise at the best time, and when they miss it the hedged book shows the Cn surplus. P&L explain reports it as exercise P&L, apart from hedging error.
Example
Two-period put: start with 4.7619 and hold Δ0 = −0.3333 shares. After a fall to 90 the put should be exercised for 10. If it is not, the seller takes out C1 = 0.9524, holds −0.7037 shares, and still ends with exactly 0 or 19, the put’s payoff.
Remember it
C is the holder’s missed exercise, cashed by the seller; zero wherever waiting is right.
Python · runs as isRun in browser
S0, u, d, r, K = 100, 1.2, 0.9, 0.05, 100
p = (1 + r - d) / (u - d)

def V(n, S):
    # American put on the two-period tree
    if n == 2:
        return max(K - S, 0.0)
    return max(K - S, (p*V(n + 1, S*u) + (1 - p)*V(n + 1, S*d)) / (1 + r))

def hedge(n, S):
    cont = (p*V(n + 1, S*u) + (1 - p)*V(n + 1, S*d)) / (1 + r)
    delta = (V(n + 1, S*u) - V(n + 1, S*d)) / (S*u - S*d)
    return delta, V(n, S) - cont            # C_n: cash the seller can take out

print([round(x, 4) for x in hedge(0, 100)], [round(x, 4) for x in hedge(1, 90)])
for path in ("HH", "HT", "TH", "TT"):          # the holder never exercises
    X, S = V(0, S0), S0
    for n, move in enumerate(path):
        delta, C = hedge(n, S)
        S_next = S*u if move == "H" else S*d
        X = delta*S_next + (1 + r)*(X - C - delta*S)   # wealth equation with consumption
        S = S_next
    print(path, V(2, S), abs(X - V(2, S)) < 1e-9)

# Output: delta and C at S = 100 and S = 90, then payoff and "wealth covers it" per path
# [-0.3333, 0.0] [-0.7037, 0.9524]
# HH 0.0 True
# HT 0.0 True
# TH 0.0 True
# TT 19.0 True
4.4

Stopping times

τ(ω1…ωnωn+1…ωN) = n  ⇒  τ(ω1…ωnω′n+1…ω′N) = n,   τ ∈ {0, 1, …, N, ∞}
step 2: HHT = HHH so farfirst time ≤ 90HHH 172.8HHT 129.6top of HHT?stop at 90: known nown = 0n = 1n = 2n = 3
The green stop is decided by what you have seen. The red one needs step 3, when HHT and HHH finally part.
What it means
A rule for when to stop that uses only the tosses seen so far. If it says “stop now” on one path, it must say so on every path that matches it up to now, whatever comes later. τ = ∞ means never stopping.
Where a quant uses it
Every exercise rule in a pricer has to be one. In Monte Carlo it is easy to break by accident, for example by picking each path’s exercise date after seeing the whole path, which overprices the option (card 4.5). Model validation tests exercise code for this kind of look-ahead.
Example
“Exercise the first time the price is at or below 90” is a stopping time. “Exercise on the day of the highest price” is not: on HHT the top, 144, comes at step 2, but at step 2 you cannot yet tell HHT from HHH, which peaks at step 3.
Remember it
No peeking: whether to stop at step n is settled by the first n tosses.
Python · runs as isRun in browser
from itertools import product

S0, u, d, N = 100, 1.2, 0.9, 3
paths = list(product("HT", repeat=N))

def prices(path):
    S = [S0]
    for move in path:
        S.append(S[-1] * (u if move == "H" else d))
    return S

first_at_or_below_90 = lambda w: next((n for n, s in enumerate(prices(w)) if s <= 90), None)  # None = never
time_of_max = lambda w: max(range(N + 1), key=lambda n: prices(w)[n])

def is_stopping_time(rule):
    # whether {tau = n} happened must be settled by the first n tosses:
    # two paths that agree up to n must agree on it
    return all((rule(a) == n) == (rule(b) == n)
               for a in paths for b in paths for n in range(N + 1) if a[:n] == b[:n])

print(is_stopping_time(first_at_or_below_90))  # True
print(is_stopping_time(time_of_max))           # False
4.5

The price as the best stopping rule

V0 = maxτ Ẽ[1{τ ≤ N} Gτ(1 + r)τ]
−10−505best rule 4.7619hindsight6.6893expiry only 4.308426 stopping rules, one dot eachvalue
Every rule you can follow lands at or left of 4.7619. Only hindsight, which peeks at the future, gets past it.
What it means
Among all stopping rules, take the one with the largest discounted expected payoff under the pricing weights. The algorithm of card 4.2 finds that maximum without listing the rules. The indicator sets the payoff to 0 on paths where you never stop.
Where a quant uses it
Every Monte Carlo method for American and Bermudan options starts here. Any rule you can follow gives a value at or below the price, so its average discounted payoff is a lower bound (card 4.10). Upper bounds come from the dual form of the same problem, and the gap between the two shows how good the rule is.
Example
The two-period tree has 26 stopping rules. The best is worth 4.7619, the put’s price. Exercising only at expiry, where it pays, gives the European 4.3084. Picking each path’s best moment with hindsight would give 6.6893, but that rule is not a stopping time.
Remember it
Best rule you can actually follow, not best with hindsight: that is the price.
Python · runs as isRun in browser
from itertools import product

S0, u, d, r, K, N = 100, 1.2, 0.9, 0.05, 100, 2
p = (1 + r - d) / (u - d)
G = lambda node: K - S0 * u**node.count("H") * d**node.count("T")   # intrinsic value at a node

def rules(node=""):
    # every stopping rule from this node on, as the set of nodes where you exercise
    yield {node}                                         # exercise here
    if len(node) == N:
        yield set()                                      # never exercise
        return
    for a, b in product(list(rules(node + "H")), list(rules(node + "T"))):
        yield a | b                                      # wait, then decide again after H and after T

def value(rule, node=""):
    # E~[ 1{tau <= N} G_tau / (1 + r)^tau ], worked backwards from this node
    if node in rule or len(node) == N:
        return G(node) if node in rule else 0.0
    return (p*value(rule, node + "H") + (1 - p)*value(rule, node + "T")) / (1 + r)

every = list(rules())
print(len(every), round(max(value(rule) for rule in every), 4))  # 26 4.7619
print(round(value({"TT"}), 4))  # 4.3084
# hindsight (not a stopping time): each path exercised at its best moment, known only afterwards
best = lambda w: max(0, *(G(w[:n]) / (1 + r)**n for n in range(N + 1)))
print(round(sum(p**w.count("H") * (1 - p)**w.count("T") * best(w) for w in map("".join, product("HT", repeat=N))), 4))  # 6.6893
4.6

Supermartingale and optimal exercise

Vn(1 + r)n ≥ Ẽn[Vn+1(1 + r)n+1],   τ* = min{n : Vn = Gn}
price Vvalue of waiting4.76194.7619today, S 100hold00after H, S 120hold109.0476after T, S 90stop: τ* = 1
Equal bars mean waiting costs nothing. At S = 90 the price beats waiting for the first time: that is τ*.
What it means
On average the discounted price never rises: waiting can only keep value or lose it. It stays level (a martingale) up to τ*, the first time the option is worth only what exercising pays, and stopping there earns exactly V0. Of all processes that stay at or above max{Gn, 0} and whose discounted value never rises on average, V is the smallest: the Snell envelope.
Where a quant uses it
Two checks when validating a lattice pricer: at every node the value is at least the exercise value and at least the discounted value of waiting. A node that fails either one points to a bug in the discounting or the exercise step. The nodes where waiting is strictly worse form the exercise region the desk watches (card 4.9).
Example
Two-period put: from today the discounted value of waiting is 4.7619 = V0, so holding loses nothing. At S1 = 90 it is 9.0476 < V1 = 10, so τ* = 1 there. After an up move V never equals G (G is negative), so τ* = ∞. Stopping at τ* is worth 4.7619.
Remember it
Never rises on average, stays level until value equals payoff: stop at that first moment.
Python · runs as isRun in browser
S0, u, d, r, K, N = 100, 1.2, 0.9, 0.05, 100, 2
p = (1 + r - d) / (u - d)
S = lambda n, k: S0 * u**k * d**(n - k)               # k = number of up moves
G = lambda n, k: K - S(n, k)

V = {(N, k): max(G(N, k), 0.0) for k in range(N + 1)}
for n in range(N - 1, -1, -1):
    for k in range(n + 1):
        cont = (p*V[n + 1, k + 1] + (1 - p)*V[n + 1, k]) / (1 + r)   # E~_n[V_{n+1}] / (1 + r)
        V[n, k] = max(G(n, k), cont)
        # supermartingale: V_n >= cont; it is strict only where tau* says stop (V_n = G_n)
        print(n, round(S(n, k)), round(V[n, k], 4), round(cont, 4), "stop" if V[n, k] == G(n, k) else "hold")

def stopped(n=0, k=0):
    # E~[ G_tau* / (1 + r)^tau* ] with tau* = min{n : V_n = G_n}, never if that never happens
    if V[n, k] == G(n, k):
        return G(n, k)
    if n == N:
        return 0.0
    return (p*stopped(n + 1, k + 1) + (1 - p)*stopped(n + 1, k)) / (1 + r)

print(round(stopped(), 4), round(V[0, 0], 4))

# Output: step, stock, V_n, discounted E~_n[V_{n+1}], decision; then tau*'s value = V_0
# 1 90 10.0 9.0476 stop
# 1 120 0.0 0.0 hold
# 0 100 4.7619 4.7619 hold
# 4.7619 4.7619
4.7

Path-dependent American payoffs

Gn = maxk≤n Sk − Sn,   Vn(ω1…ωn) = max{Gn, p̃ Vn+1(ω1…ωnH) + q̃ Vn+1(ω1…ωnT)1 + r}
V 1.44S 4S 8V 1.6 holdS 2V 2 exercise(wait 1.2)HH S 16, peak 16: 0HT S 4, peak 8: 4TH S 4, peak 4: 0TT S 1, peak 4: 3same S, different pay
HT and TH end at the same price, 4, yet pay 4 and 0: the nodes cannot merge, so every path keeps its own branch.
What it means
When the exercise value depends on the path, so does the option’s value, and paths that meet at the same price cannot share a node. Run the same backward step on the tree of paths, or carry just the state the payoff needs.
Where a quant uses it
American-style Asian options let the holder exercise early against the running average price, so a lattice has to carry the average as an extra state, as card 1.8 does for the maximum. When that state grows too large, desks switch to Monte Carlo with a regression exercise rule (card 4.10).
Example
S0 = 4, u = 2, d = 1/2, r = 1/4, paying the highest price so far minus today’s. Paths HT and TH both end at 4 but pay 4 and 0. Working back gives 1.6 after H, 2 after T (exercise there: 2 beats 1.2 for waiting) and V0 = 1.44.
Remember it
Same price, different past, different value: when the payoff remembers, the tree cannot merge.
Python · runs as isRun in browser
S0, u, d, r, N = 4, 2, 0.5, 0.25, 2
p = (1 + r - d) / (u - d)

def V(path=""):
    # value after the tosses in `path`: the payoff needs the whole path, not just today's price
    S = [S0]
    for move in path:
        S.append(S[-1] * (u if move == "H" else d))
    G = max(S) - S[-1]                      # G_n = max_{k<=n} S_k - S_n
    if len(path) == N:
        return max(G, 0)
    return max(G, (p*V(path + "H") + (1 - p)*V(path + "T")) / (1 + r))

print(round(V(), 4))                   # 1.44
print(round(V("H"), 4), round(V("T"), 4))  # 1.6 2.0
print(V("HT"), V("TH"))                # 4.0 0.0
4.8

The American call without dividends

VnEu ≥ (Sn − K(1 + r)N−n)+ ≥ (Sn − K)+  (r ≥ 0)  ⇒  V0Am = V0Eu
KK/1.05S 120hold 24.7619exercise 20call: American = European = 13.6054a year of daily steps: nodes where exercise winscall0 of 31,375put14,314 of 31,375
Holding is worth at least the blue line, stock minus discounted strike, which never dips below the payoff: the call is never exercised early.
What it means
Before expiry, a European call on a stock that pays no dividends is already worth at least the stock minus the discounted strike, which is at least what exercising pays (more, when r > 0). Exercising early gives up interest on the strike and the protection if the stock falls, and gets nothing back. So the max in card 4.2 never picks exercise. Shreve proves it with Jensen’s inequality: the discounted call payoff is a submartingale.
Where a quant uses it
Pricers for listed single-stock calls only check early exercise just before each ex-dividend date, the only time it can pay. A call on a stock with no dividend left before expiry is priced as a European, and an early exercise of it is a gift to the seller.
Example
Two-period tree, strike 100: American = European = 13.6054, with no node where exercising wins. At S1 = 120 exercise pays 20, while holding is worth 24.7619 = 120 − 100/1.05 (both branches end in the money there). On a year of daily steps (250 steps, u = 1.01, d = 1/u, r = 0.02% a step) the call, worth 8.8546, still has no such node; the put, worth 4.5000, has 14,314 of the 31,375 nodes before expiry.
Remember it
No dividends, no early call: paying the strike sooner and dropping the insurance never pays.
Python · runs as isRun in browser
def american(S0, u, d, r, N, g):
    p = (1 + r - d) / (u - d)
    V = [max(g(S0 * u**k * d**(N - k)), 0) for k in range(N + 1)]
    early = 0                                          # nodes where exercising beats waiting
    for n in range(N - 1, -1, -1):
        cont = [(p*V[k + 1] + (1 - p)*V[k]) / (1 + r) for k in range(n + 1)]
        G = [g(S0 * u**k * d**(n - k)) for k in range(n + 1)]
        early += sum(x > c for x, c in zip(G, cont))
        V = [max(x, c) for x, c in zip(G, cont)]
    return round(V[0], 4), early

call, put = (lambda s: s - 100), (lambda s: 100 - s)
print(american(100, 1.2, 0.9, 0.05, 2, call))  # (13.6054, 0)
# at S_1 = 120 exercising pays 20; holding is worth at least S_1 - K / (1 + r)
print(round(120 - 100 / 1.05, 4))  # 24.7619
# a year of daily steps: the call never, the put often
print(american(100, 1.01, 1 / 1.01, 0.0002, 250, call))  # (8.8546, 0)
print(american(100, 1.01, 1 / 1.01, 0.0002, 250, put))   # (4.5, 14314)
4.9

The early-exercise boundary

Follows from the chapter
Sn* = max{s : vn(s) = K − s},   τ* = min{n : Sn ≤ Sn*}
strike 10081.484.387.190.31y6m3m0.1y0time left to expiryexerciseholdAmerican put 6.0864 · European 5.5735
The red region is where exercising at once is optimal. Its edge climbs towards the strike as expiry nears.
What it means
For a put, the nodes where exercise is optimal (red in the live model above) sit below a critical price at each step. Exercise the first time the stock falls to it. The critical price rises towards the strike as expiry nears, and with the interest rate.
Where a quant uses it
Below the boundary a short American put should expect to be assigned, and the put’s delta there is −1. Risk systems flag short puts near the boundary so an assignment is no surprise, and desks recheck the boundary when rates move.
Example
One-year put, S = K = 100, r = 5%, σ = 20%, on the CRR tree of card 1.9 with 200 steps: 6.0864, against 5.5735 for the European (Black–Scholes). Exercise at once if the stock is at or below about 81.4 with a year left, 84.3 with six months, 87.1 with three months and 90.3 with 0.1 years. An 800-step tree moves each of them down by less than 0.3.
Remember it
At or below the line, exercise; the line climbs towards the strike as expiry nears.
Python · runs as isRun in browser
from math import exp, sqrt

def am_put(S0, K, T, r, sigma, N=200):
    dt = T / N; u = exp(sigma * sqrt(dt)); d = 1 / u
    p, disc = (exp(r * dt) - d) / (u - d), exp(-r * dt)
    V = [max(K - S0 * u**k * d**(N - k), 0.0) for k in range(N + 1)]
    for n in range(N - 1, -1, -1):
        V = [max(K - S0 * u**k * d**(n - k), disc * (p*V[k + 1] + (1 - p)*V[k])) for k in range(n + 1)]
    return V[0]

def boundary(K, T, r, sigma):
    # the highest stock price at which exercising at once is optimal, by bisection
    lo, hi = 0.5 * K, K
    for _ in range(30):
        mid = (lo + hi) / 2
        lo, hi = (mid, hi) if am_put(mid, K, T, r, sigma) <= K - mid + 1e-9 else (lo, mid)
    return lo

print(round(am_put(100, 100, 1, 0.05, 0.2), 4))
for T in (1, 0.5, 0.25, 0.1):                # years left to expiry
    print(T, round(boundary(100, T, 0.05, 0.2), 1))

# Output: the American put, then the critical stock price for each time left
# 6.0864
# 1 81.4
# 0.5 84.3
# 0.25 87.1
# 0.1 90.3
4.10

Exercise by regression (Longstaff–Schwartz)

Beyond the chapter
(b0, b1, b2) = argminβ ∑i (Yi − β0 − β1xi − β2xi2)2,   exercise if Gn > b0 + b1x + b2x2
exercisewaitpayoff K − Sfitted wait valueone path: cash from waitingLSM 6.07 ± 0.05tree 6.07370.750.80.91.0x = S/K
Left of the dot the payoff beats the fitted value of waiting, so those paths exercise; right of it they wait.
What it means
When the state is too big for a tree, simulate paths and work back through the exercise dates. At each date, regress the discounted cash flow Yi from waiting on simple functions of today’s price xi = Sn/K, using in-the-money paths only. The fitted curve estimates the value of waiting; exercise where the payoff beats it. The result carries Monte Carlo error, and the fitted rule is only close to τ*.
Where a quant uses it
The standard Monte Carlo method for early exercise on several factors or path-dependent payoffs: Bermudan and callable rate products under multi-factor models, and the exercise decisions inside xVA exposure simulations.
Example
The card 4.9 put with 50 exercise dates, 20,000 paths and a quadratic in S/K: 6.07 with a standard error of 0.05. A 50-step tree, with the same exercise dates, gives 6.0737. This sketch fits and prices on the same paths, which can bias it slightly up; pricing on fresh paths gives a value that is low on average, a lower bound.
Remember it
Fit what waiting pays, in-the-money paths only; exercise where cash now beats the fit.
Python · runs as isRun in browser
import random, statistics
from itertools import accumulate
from math import exp, sqrt

def lsm_put(S0, K, T, r, sigma, steps=50, paths=20000, seed=1):
    random.seed(seed)
    dt = T / steps; disc = exp(-r * dt); a, b = (r - sigma**2 / 2) * dt, sigma * sqrt(dt)
    S = [list(accumulate((exp(a + b * random.gauss(0, 1)) for _ in range(steps)), lambda x, y: x * y, initial=S0))
         for _ in range(paths)]                                    # risk-neutral stock paths
    cash = [max(K - s[-1], 0.0) for s in S]                        # payoff if held to expiry
    for n in range(steps - 1, 0, -1):
        cash = [c * disc for c in cash]                            # what waiting paid, valued at step n
        itm = [i for i in range(paths) if S[i][n] < K]
        X = [(1.0, S[i][n] / K, (S[i][n] / K)**2) for i in itm]    # basis 1, x, x^2 with x = S/K
        A = [[sum(x[j] * x[k] for x in X) for k in range(3)] + [sum(x[j] * cash[i] for x, i in zip(X, itm))]
             for j in range(3)]                                    # least squares: the normal equations
        for j, k in [(j, k) for j in range(3) for k in range(3) if k != j]:
            A[k] = [y - A[k][j] / A[j][j] * z for y, z in zip(A[k], A[j])]
        for x, i in zip(X, itm):                                   # exercise where it beats the fitted value
            if K - S[i][n] > sum(A[j][3] / A[j][j] * x[j] for j in range(3)):
                cash[i] = K - S[i][n]
    v = [c * disc for c in cash]
    return round(statistics.fmean(v), 2), round(statistics.stdev(v) / sqrt(paths), 2)

print(lsm_put(100, 100, 1, 0.05, 0.2))  # (6.07, 0.05)

Where these ideas come from

Interview questions

Why is an American call on a non-dividend stock never exercised early?

Before expiry it is worth at least S − K discounted to today, which is more than S − K when rates are positive. Exercising throws away that interest and the option’s protection against a fall.

What happens to the early-exercise premium of a put when interest rates rise?

It rises. Getting the strike early earns more interest, so exercising early becomes worth more.

Equity Derivatives Quant Notes & Code →

Volume I · Chapter 5

Random Walk

The symmetric random walk is the discrete twin of Brownian motion. How long it takes to hit a level is the key to barrier options and perpetual American options.

Picture it

Someone takes one random step left or right each second. They will almost surely reach a lamppost one step to their right, but on average it takes forever, because a few walks wander very far left before coming back. To count how often the walk reaches a level, mirror each path after it first touches the level: every path that touched it and ended below has a twin that ends above.

Toss a fair coin and step up or down by one. The first time the walk reaches level m is a random time τm. It is finite with probability one, yet its expected value is infinite.

A well-chosen exponential martingale, together with the rule that a martingale stopped at a sensible time keeps its expectation, gives the distribution of τm through its generating function.

The reflection principle counts paths: every path that touches m and ends below it pairs with one that ends the same distance above. That gives the maximum’s distribution in closed form. The same tools price a perpetual American put: exercise the first time the stock falls to a threshold.

P(maxk≤n Mk ≥ m) = P(Mn = m) + 2 P(Mn > m),   E[ατm] = (1 − √(1 − α2)α)m

Reading the formula: Mn: position after n steps · max Mk: the highest point reached so far · τm: the first time the walk reaches level m · α: a number between 0 and 1 that tracks how long that takes

Live modelSIMULATED

Simulated symmetric random walks. Walks that reach the level are green; the share that reach it is checked against the reflection-principle formula.

The hard parts, step by step

The ideas in this chapter that most people get stuck on, each with a picture, the derivation line by line, worked numbers and the trap to avoid.

Sure to hit +1, yet the average time is infinite

Picture it

The walker always gets to the lamppost eventually, but now and then they wander off a very long way first. Those rare, enormous detours are long enough to make the average time infinite, even though almost every walk arrives fairly soon.

Step by step

  1. P(τ1 ≤ n) → 1   as n → ∞Hitting is certain in the long run.
  2. E[ατ1] = 1 − √(1 − α2)αThe generating function (derived in the next topic).
  3. let α ↑ 1:   the value → 1So P(τ1 < ∞) = 1.
  4. the slope at α = 1 is infinite  ⇒  E[τ1] = ∞Differentiating gives the mean, and the square root makes the slope blow up.

Worked numbers

  • Chance of reaching +1 within 1 step: 50%; within 9: 75.4%; within 99: 92.0%; within 999: 97.5%.
  • It keeps creeping towards 100%, but so slowly that the average time never settles.

Common mistake: Thinking “certain to happen” means “happens in finite expected time”. Here it does not.

Deriving the hitting-time formula with a martingale

Picture it

Find a quantity that stays fair as the walk moves. Stop it when the walk first reaches m. Because the game is fair, its expected value at that moment equals its value at the start, and that one equation gives the whole distribution of the hitting time.

Step by step

  1. Sn = eσMn (2eσ + e−σ)nFor any σ > 0 this is a martingale: one step multiplies eσM by eσ or e−σ on average (eσ + e−σ)/2, and the second factor cancels it.
  2. E[Sτm] = S0 = 1Optional sampling, justified because M stays at most m before τm.
  3. eσm E[ατm] = 1,   α = 2/(eσ + e−σ)At τm the walk sits exactly at m.
  4. E[ατm] = (e−σ)m = (1 − √(1 − α2)α)mSolve α = 2/(eσ + e−σ) for e−σ.

Worked numbers

  • α = 0.9, m = 1: (1 − √0.19) / 0.9 = 0.6268
  • Check by adding up the exact first-passage probabilities, αn × P(τ1 = n), over all n: 0.6268 ✓

Common mistake: Using optional sampling without checking it applies. It needs the stopped process to stay bounded (or a similar condition).

The reflection principle, by counting paths

Picture it

Take any path that touches level m and later ends below it. Flip everything after the first touch upside down: it now ends the same distance above m. Every path that ends above m pairs with one that touched m and ends below, so the paths that touch m are easy to count.

Step by step

  1. paths that touch m and end at b < m  ↔  paths ending at 2m − bThe reflection pairing, one for one.
  2. P(maxk≤n Mk ≥ m) = P(Mn = m) + 2 P(Mn > m)Paths ending above m count twice (themselves and their twins); paths ending exactly at m once.

Worked numbers

  • 4 steps, level 2: P(M4 = 2) = 4/16 and P(M4 > 2) = P(M4 = 4) = 1/16.
  • Formula: 4/16 + 2 × 1/16 = 6/16 = 0.375
  • Listing all 16 paths by hand: exactly 6 touch level 2 ✓

Common mistake: Doubling the paths that end exactly at m. They are their own reflection and count only once.

The perpetual American put: when to exercise if the option never expires

Picture it

With no expiry, the only question is how low to let the stock fall before cashing in. Fix a trigger level, work out what the put is worth if you exercise the first time the stock hits it, then choose the trigger that gives the most.

Step by step

  1. trigger L = S0 dj: exercise the first time the stock falls j stepsEvery exercise rule of this shape is a stopping time.
  2. value(j) = (K − L) · Ẽ[(1 + r)−τ]Payoff at the trigger, discounted by how long it takes to get there.
  3. Ẽ[(1 + r)−τ] = fj,   f = 1 − √(1 − 4p̃q̃α2)2p̃α,   α = 1/(1 + r)Each one-step fall takes an independent random time; f solves f = α(q̃ + p̃ f2).
  4. choose j to maximise value(j)Too high a trigger gives up the chance of a bigger payoff; too low means waiting too long.

Worked numbers

K = 100, S0 = 100, u = 1.2, d = 1/1.2, r = 5% (so p̃ = 0.591, f = 0.5769).

  • j = 1 (L = 83.33): value = 9.615
  • j = 2 (L = 69.44): value = 10.170 ← best
  • j = 3 (L = 57.87): value = 8.090
  • Check by brute force (repeated backward induction on a long price ladder): 10.170, exercising at 69.44 ✓

Common mistake: Exercising as soon as the put is in the money. Here the best trigger is well below the strike.

Every formula in this chapter

10 formulas in the order you meet them. Each one comes with what it means, where a quant uses it on the desk, a worked example and Python you can copy or run in your browser. The expected output is in the comments, and every snippet is run against it before the page goes live.

  1. 5.1The symmetric random walk
  2. 5.2The first passage time
  3. 5.3The exponential martingale
  4. 5.4Stopping the martingale at τ1
  5. 5.5The hitting-time generating function
  6. 5.6Sure to hit, yet the average time is infinite
  7. 5.7The reflection principle
  8. 5.8The perpetual American put
  9. 5.9A one-touch priced by reflection
  10. 5.10From the walk to Brownian motion
5.1

The symmetric random walk

M0 = 0,   Mn = X1 + X2 + … + Xn,   Xj = ±1, each with probability 12
0123416 equally likely pathsP(M₄ = m)−41/16−24/1606/16+24/16+41/16mean 0 · variance 4
Four fair steps spread the walk 1:4:6:4:1 around 0, with mean 0 and variance 4, the number of steps.
What it means
Toss a fair coin; step up 1 for heads and down 1 for tails. Mn is where you stand after n tosses. On average you stay at 0, but the spread grows: the variance after n steps is n, so the typical distance from 0 is √n. Mn is a martingale: the best forecast of where it will be later is where it is now.
Where a quant uses it
Every CRR tree (card 1.9) is a random walk in disguise: with d = 1/u the price after n steps is S0uMn, where Mn is ups minus downs. Variance growing like n is also behind the square-root-of-time rule that scales a 1-day VaR to 10 days by √10, an approximation that leans on independent daily steps.
Example
After 4 steps the walk ends at −4, −2, 0, 2 or 4 with probabilities 1/16, 4/16, 6/16, 4/16 and 1/16. The mean is 0 and the variance is 4, the number of steps.
Remember it
The average stays at 0; the variance counts the steps, so the spread grows like √n.
Python · runs as isRun in browser
from fractions import Fraction
from itertools import product

n = 4
dist = {}
for steps in product((1, -1), repeat=n):      # all 2**n equally likely paths
    M = sum(steps)
    dist[M] = dist.get(M, 0) + Fraction(1, 2**n)

for M, prob in sorted(dist.items()):
    print(M, prob)
mean = sum(M*prob for M, prob in dist.items())
var = sum(M*M*prob for M, prob in dist.items()) - mean**2
print("mean", mean, "variance", var)

# Output: the four-step walk
# -4 1/16
# -2 1/4
# 0 3/8
# 2 1/4
# 4 1/16
# mean 0 variance 4
5.2

The first passage time

τm = min{n ≥ 0 : Mn = m},   τm = ∞ if the walk never reaches m
0m = 1τ₁P(τ₁ ≤ n)n = 150%n = 975.4%n = 9992.0%n = 99997.5%100%
The walk can wander below 0 for long before its first visit to +1, so the chance of arriving only creeps towards 100%.
What it means
The first step at which the walk stands at level m. Whether τm ≤ n is settled by the first n tosses alone, with no peeking ahead, so τm is a stopping time. That is what lets the martingale tools of cards 5.4–5.5 work with it.
Where a quant uses it
Trigger times are first passage times: the step a barrier option knocks out, the date an autocallable is called, the day a stop-loss or margin call fires. In first-passage credit models a firm defaults the first time its asset value falls to a barrier.
Example
Chance of reaching +1 within 1 step: 50%; within 9: 75.4%; within 99: 92.0%; within 999: 97.5%. It keeps creeping towards 100% (card 5.6).
Remember it
τm is the first tick on level m, known the moment it happens.
Python · runs as isRun in browser
def hit_by(m, n):
    # P(tau_m <= n): push the probability forward, absorb it at level m
    alive, hit = {0: 1.0}, 0.0
    for _ in range(n):
        nxt = {}
        for x, p in alive.items():
            for y in (x - 1, x + 1):
                nxt[y] = nxt.get(y, 0.0) + p / 2
        hit += nxt.pop(m, 0.0)
        alive = nxt
    return hit

for n in (1, 9, 99, 999):
    print(n, round(hit_by(1, n), 4))

# Output: P(tau_1 <= n) creeps towards 1
# 1 0.5
# 9 0.7539
# 99 0.9204
# 999 0.9748
5.3

The exponential martingale

Sn = eσMn(2eσ + e−σ)n,   σ > 0
11.76160.2384avg 11e1/eavg 1.5431times 0.6481 per stepwithout the factormean stays 110 steps: 76.54
With the factor, the two outcomes sit evenly around 1; without it, the average climbs to 1.5431 after one step and 76.54 after ten.
What it means
Each step multiplies eσM by eσ or e−σ, so on average by (eσ + e−σ)/2, which is more than 1. The second factor divides that growth back out, so Sn is a martingale with S0 = 1 for every σ. Here σ is a free dial, not a volatility.
Where a quant uses it
Exponential tilting. Weighting each path by this martingale tilts the coin towards up moves, which is how Monte Carlo engines make rare barrier hits common and then correct the average (importance sampling). Its continuous-time twin, eσW(t) − σ2t/2, is the density behind Girsanov’s theorem in Volume II, which every change of drift in a pricing model relies on.
Example
σ = 1: (e + e−1)/2 = 1.5431, so the factor is 0.6481 per step. After one step S1 is 1.7616 or 0.2384, which average to exactly 1. Without the factor, E[eM10] = 1.543110 = 76.54.
Remember it
Each step multiplies the mean by cosh σ; divide that out and the mean stays 1.
Python · runs as isRun in browser
from itertools import product
from math import exp

sigma = 1.0                                   # any sigma > 0; not a volatility
alpha = 2 / (exp(sigma) + exp(-sigma))        # 1 / cosh(sigma)

def mean_over_paths(f, n):
    paths = list(product((1, -1), repeat=n))
    return sum(f(sum(p), n) for p in paths) / len(paths)

S = lambda M, n: exp(sigma*M) * alpha**n      # the exponential martingale
print(round(alpha, 4), round(exp(sigma)*alpha, 4), round(exp(-sigma)*alpha, 4))  # 0.6481 1.7616 0.2384
print([round(mean_over_paths(S, n), 10) for n in (1, 5, 10)])  # [1.0, 1.0, 1.0]
print(round(mean_over_paths(lambda M, n: exp(sigma*M), 10), 2))  # 76.54
5.4

Stopping the martingale at τ1

E[Sn∧τ1] = 1,   n → ∞:   E[1{τ1 < ∞} eσ(2eσ + e−σ)τ1] = 1
stopped at level 1still runningn = 10.8808+ 0.1192n = 50.9927+ 0.0073n = 100.9993+ 0.0007total 1
The total stays exactly 1 at every n, while the share from paths still running shrinks towards 0.
What it means
Freeze S the moment the walk first reaches 1; n ∧ τ1 is the earlier of n and τ1. A stopped martingale is still a martingale, so its expectation stays 1 at every n. Up to τ1 the walk is never above 1, so S stays between 0 and eσ, and that bound makes it safe to let n → ∞. On paths that never reach 1 the second factor shrinks S to 0, so only paths that hit count.
Where a quant uses it
Martingale tests in model validation. In a Monte Carlo engine the discounted price, stopped at a barrier hit or at maturity (whichever comes first), must average to today’s price; if it does not, the engine has the wrong drift or the wrong discounting. The bound matters: “double the bet until you win” is a fair game stopped at a finite time that always ends 1 up, because the losses before the win have no bound.
Example
σ = 1. After 1 step, paths already stopped at level 1 contribute 0.8808 and paths still running 0.1192: total 1. After 5 steps, 0.9927 + 0.0073; after 10, 0.9993 + 0.0007. The total stays 1 while the running part dies out.
Remember it
Stopped at the first hit, still fair; bounded by eσ, so the limit keeps the 1.
Python · runs as isRun in browser
from itertools import product
from math import exp

sigma = 1.0
alpha = 2 / (exp(sigma) + exp(-sigma))

def stopped_mean(n):
    # average of S at min(n, tau_1) over all 2**n paths: stopped at level 1, or still running
    stopped = running = 0.0
    for steps in product((1, -1), repeat=n):
        M = 0
        for k, x in enumerate(steps, 1):
            M += x
            if M == 1:
                stopped += exp(sigma) * alpha**k
                break
        else:
            running += exp(sigma*M) * alpha**n
    return stopped / 2**n, running / 2**n

for n in (1, 5, 10):
    s, run = stopped_mean(n)
    print(n, round(s + run, 10), round(s, 4), round(run, 4))

# Output: total, stopped part, running part
# 1 1.0 0.8808 0.1192
# 5 1.0 0.9927 0.0073
# 10 1.0 0.9993 0.0007
5.5

The hitting-time generating function

E[ατm] = (1 − √(1 − α2)α)m,   0 < α < 1
0level 1level 2α = 0.9× 0.6268× 0.6268m = 2: 0.6268 × 0.6268 = 0.3929
Reaching level 2 is two separate one-level climbs, each worth 0.6268 at α = 0.9, so the value is 0.62682 = 0.3929.
What it means
Write α = 2/(eσ + e−σ) in card 5.4. Since ατ1 is 0 when τ1 = ∞, it says E[ατ1] = e−σ, and solving αe−2σ − 2e−σ + α = 0 gives the fraction. Reaching m takes m separate climbs of one level, each like the first, so the answer for m is the m-th power. Expand it in powers of α and the coefficient of αn is P(τm = n).
Where a quant uses it
With α = 1/(1 + r), E[ατm] is today’s value of 1 paid the first time the level is reached, when the walk is symmetric under the pricing weights: the rebate paid at the hit on a knock-out barrier, and the building block of the perpetual American put (card 5.8).
Example
α = 0.9, m = 1: (1 − √0.19)/0.9 = 0.6268; m = 2: 0.62682 = 0.3929. Adding up αn × P(τm = n) over the exact first-passage probabilities (1/2, 0, 1/8, 0, 1/16, 0, 5/128, … for m = 1) gives the same. With α = 1/1.05: 0.7298.
Remember it
Each level is a fresh one-level climb, so m levels give the m-th power.
Python · runs as isRun in browser
from math import sqrt

def first_passage(m, N):
    # P(tau_m = n) for n = 1..N: push the probability forward, absorb it at level m
    alive, law = {0: 1.0}, []
    for _ in range(N):
        nxt = {}
        for x, p in alive.items():
            for y in (x - 1, x + 1):
                nxt[y] = nxt.get(y, 0.0) + p / 2
        law.append(nxt.pop(m, 0.0))
        alive = nxt
    return law

phi = lambda a: (1 - sqrt(1 - a*a)) / a       # E[a^tau_1]
print(first_passage(1, 7))
for m in (1, 2):
    law = first_passage(m, 400)
    print(m, round(phi(0.9)**m, 4), round(sum(0.9**(n + 1) * p for n, p in enumerate(law)), 4))
print(round(phi(1 / 1.05), 4))

# Output: exact law of tau_1, then formula vs. sum over the law
# [0.5, 0.0, 0.125, 0.0, 0.0625, 0.0, 0.0390625]
# 1 0.6268 0.6268
# 2 0.3929 0.3929
# 0.7298
5.6

Sure to hit, yet the average time is infinite

P(τ1 < ∞) = limα↑1 E[ατ1] = 1,   E[τ1] = limα↑1 1 − √(1 − α2)α2√(1 − α2) = ∞
E[α^τ₁] as α ↑ 1: settles at 1α = 0.90.6268α = 0.990.8676α = 0.99990.98601mean of min(τ₁, n): grows like √nn = 10015.0n = 10⁴158.6n = 10⁶1,594.8
The top bars settle at 1, so the hit is certain; the bottom bars grow about tenfold per hundredfold n, never settling.
What it means
Let α rise to 1 in card 5.5: ατ1 rises to 1 on every path that hits, so the limit is the chance of hitting, and the formula gives 1. Differentiating card 5.5 gives E[τ1ατ1−1], the fraction above. Its denominator goes to 0 at α = 1, so the mean time is infinite: rare, enormous detours below 0 drag the average up without bound.
Where a quant uses it
Simulated hitting times (time to a barrier, to a stop-loss, to default in a first-passage model) always need a cap. An uncapped average of simulated τ never settles, and the mean you report grows with the cap you chose. It is also why “hold the losing position until it comes back” is not a plan: it comes back for sure, but the expected wait is infinite.
Example
E[ατ1] is 0.6268, 0.8676 and 0.9860 at α = 0.9, 0.99 and 0.9999, creeping to 1, while the slope is 1.6, 6.21 and 69.73. The mean of min(τ1, n) is 15.0 for n = 100, 158.6 for 10,000 and 1,594.8 for 1,000,000: it grows like √n.
Remember it
Sure to hit, but the average wait is infinite: certain is not quick.
Python · runs as isRun in browser
from math import sqrt

phi = lambda a: (1 - sqrt(1 - a*a)) / a                      # E[a^tau_1]
slope = lambda a: (1 - sqrt(1 - a*a)) / (a*a*sqrt(1 - a*a))  # E[tau_1 a^(tau_1 - 1)]
for a in (0.9, 0.99, 0.9999):
    print(a, round(phi(a), 4), round(slope(a), 2))

# capped mean E[min(tau_1, n)] = sum of P(tau_1 > k) over k < n
total, tail = 0.0, 1.0                 # tail = P(tau_1 > k), from k = 0
for k in range(1, 10**6 + 1):
    total += tail
    if k in (100, 10**4, 10**6):
        print(k, round(total, 1))
    if k % 2 == 1:
        tail *= k / (k + 1)

# Output: E[a^tau_1] and its slope, then the capped mean
# 0.9 0.6268 1.6
# 0.99 0.8676 6.21
# 0.9999 0.986 69.73
# 100 15.0
# 10000 158.6
# 1000000 1594.8
5.7

The reflection principle

P(τm ≤ n) = P(maxk≤n Mk ≥ m) = P(Mn = m) + 2 P(Mn > m)
m = 2first touchends 4ends 0end at 24/16, onceend above 21/16, twicetouch 2 by step 46/16 = 0.375
Mirror the path after its first touch of 2 and an end at 0 becomes an end at 4, so ends above 2 count twice.
What it means
Reflect each path after its first visit to m. A path that touched m and ends at b < m pairs one for one with a path ending at 2m − b > m, and every path that ends above m has touched m. So paths ending above m count twice and paths ending exactly at m count once: the distribution of the running maximum comes from the end point alone.
Where a quant uses it
The chance that a barrier is touched before expiry, read off the terminal distribution. Its Brownian version (card 5.10) is the starting point of closed-form knock-in, knock-out and lookback prices, and the discrete form gives exact answers to test lattice and Monte Carlo barrier engines against.
Example
4 steps, level 2: P(M4 = 2) = 4/16 and P(M4 > 2) = 1/16, so 4/16 + 2/16 = 6/16 = 0.375. Listing all 16 paths finds exactly 6 that touch 2. With 10 steps and level 3: 11/32; with 15 steps and level 4: 309/1024.
Remember it
Reflect after the first touch: ends above m count twice, ends at m once.
Python · runs as isRun in browser
from fractions import Fraction
from itertools import accumulate, product
from math import comb

def brute(n, m):
    # share of all 2**n paths whose running maximum reaches m
    hits = sum(max(accumulate(s)) >= m for s in product((1, -1), repeat=n))
    return Fraction(hits, 2**n)

def P_end(n, b):
    # P(M_n = b): (n + b)/2 of the n steps must be up
    return Fraction(comb(n, (n + b)//2), 2**n) if (n + b) % 2 == 0 else Fraction(0)

def reflection(n, m):
    return P_end(n, m) + 2*sum(P_end(n, b) for b in range(m + 1, n + 1))

for n, m in ((4, 2), (10, 3), (15, 4)):
    print(n, m, brute(n, m), reflection(n, m))

# Output: n, m, counting every path, the formula
# 4 2 3/8 3/8
# 10 3 11/32 11/32
# 15 4 309/1024 309/1024
5.8

The perpetual American put

v(S0) = maxj (K − S0dj) fj,   f = 1 − √(1 − 4p̃q̃α2)2p̃α,   α = 11 + r,   d = 1u
payoff K − Lvalue (K − L) × f^jS₀ = K = 100f = 0.5769 per step down83.339.61569.4410.170 best57.878.090
Lower triggers pay more (grey) but are reached later and discounted by f per step (blue); the best value, 10.170, comes at 69.44.
What it means
A put that never expires is exercised the first time the stock falls to a trigger L = S0dj. Its value is the payoff there, K − L, times the expected discount until the stock gets there. That discount is fj, because the stock must fall j separate one-step levels and f solves f = α(q̃ + p̃f2). Choose the j that gives the most. With p̃ = q̃ = 1/2, f is card 5.5’s formula.
Where a quant uses it
The continuous-time perpetual put has a closed form, so it is a standard benchmark for American-option engines: a very long-dated American put from a tree, a PDE solver or a Longstaff–Schwartz Monte Carlo must converge to it. The same trade-off, a higher payoff against a longer wait, sets the early-exercise boundary of long-dated American options.
Example
K = S0 = 100, u = 1.2, d = 1/1.2, r = 5%: p̃ = 0.591 and f = 0.5769. A trigger of 83.33 gives 9.615, 69.44 gives 10.170 (best) and 57.87 gives 8.090. Backward induction on a long price ladder also gives 10.170, exercising at 69.44, well below the strike.
Remember it
Each step lower pays more but costs a factor f; exercise where the product peaks.
Python · runs as isRun in browser
from math import sqrt

K, S0, u, r = 100, 100, 1.2, 0.05
d = 1 / u
p = (1 + r - d) / (u - d); q = 1 - p; a = 1 / (1 + r)
f = (1 - sqrt(1 - 4*p*q*a*a)) / (2*p*a)     # E[a^tau] for one step down
print(round(p, 3), round(f, 4))
for j in (1, 2, 3):                        # exercise the first time S falls j steps
    print(j, round(S0 * d**j, 2), f"{(K - S0 * d**j) * f**j:.3f}")

# brute force: v(s) = max(K - s, a(p v(us) + q v(ds))) on a long price ladder S0 u^i
lo, hi = -60, 60
v = {i: max(K - S0 * u**i, 0) for i in range(lo, hi + 1)}
for _ in range(2000):
    v = {i: max(K - S0 * u**i, a*(p*v[min(i + 1, hi)] + q*v[max(i - 1, lo)])) for i in v}
trigger = max(i for i in v if v[i] == K - S0 * u**i)
print(f"{v[0]:.3f}", round(S0 * u**trigger, 2))

# Output: p, f, the three triggers, then brute force
# 0.591 0.5769
# 1 83.33 9.615
# 2 69.44 10.170
# 3 57.87 8.090
# 10.170 69.44
5.9

A one-touch priced by reflection

Follows from the chapter
V0 = 1(1 + r)n[P̃(Mn = m) + 2 P̃(Mn > m)],   d = 1u,   1 + r = u + d2
100barrier 12101234p̃ = 0.5touch 0.375÷ 1.004545⁴price 0.3683
Any path reaching the shaded zone by step 4 pays 1: reflection gives the chance, 6/16 = 0.375, and four steps of discounting give 0.3683.
What it means
A one-touch pays 1 at step n if the stock has touched the barrier S0um at any step. With d = 1/u the stock is S0uMn, so touching the barrier means the walk reaches m. When 1 + r = (u + d)/2 the pricing weights are p̃ = q̃ = 1/2, the walk is symmetric, and the price is card 5.7 discounted. At any other rate p̃ ≠ 1/2 and reflected paths no longer have equal weight, so carry a “touched yet” flag through backward induction instead (card 1.8).
Where a quant uses it
FX options desks trade one-touch and no-touch options every day. Their prices come from the Brownian version (card 5.10) with drift added, and exact lattice numbers like these are how a tree or Monte Carlo barrier engine is tested before it is trusted.
Example
S0 = 100, u = 1.1, d = 1/1.1, so 1 + r = 1.004545 per step and p̃ = 0.5. Barrier 121 (m = 2), 4 steps: touch probability 6/16 = 0.375 (card 5.7), price 0.375/1.0045454 = 0.3683. Backward induction with a “touched” flag gives 0.3683 too.
Remember it
With p̃ = 1/2, price = the reflection touch probability, discounted n steps.
Python · runs as isRun in browser
from functools import lru_cache
from math import comb

S0, u, n, m = 100, 1.1, 4, 2            # barrier S0 u^m = 121, four steps
d = 1 / u
r = (u + d) / 2 - 1                     # the per-step rate that makes p = 1/2
p = (1 + r - d) / (u - d)
P_end = lambda b: comb(n, (n + b)//2) / 2**n if (n + b) % 2 == 0 else 0.0
touch = P_end(m) + 2*sum(P_end(b) for b in range(m + 1, n + 1))
print(round(p, 10), round(r, 6), touch)  # 0.5 0.004545 0.375
print(round(touch / (1 + r)**n, 4))      # 0.3683

@lru_cache(maxsize=None)
def V(k, M, touched):                   # check: backward induction with a "touched" flag
    touched = touched or M >= m
    if k == n:
        return 1.0 if touched else 0.0
    return (p*V(k + 1, M + 1, touched) + (1 - p)*V(k + 1, M - 1, touched)) / (1 + r)

print(round(V(0, 0, False), 4))         # 0.3683
5.10

From the walk to Brownian motion

Beyond the chapter
P(max0≤t≤T W(t) ≥ b) = 2 P(W(T) ≥ b) = 2N(−b√T)
0b = 1T = 1P(max ≥ 1 by T = 1)walk, 1000.3197walk, 10⁴0.31732N(−1)0.3173
Mirror the path after it first touches b = 1; as the steps shrink, the touch chance closes in on 2N(−1) = 0.3173.
What it means
Take n steps of size 1/√n per unit of time and the walk approaches Brownian motion W (Volume II builds it this way). The reflection count carries over, but ending exactly at the level now has probability zero, so the P(Mn = m) term drops out and the factor 2 remains.
Where a quant uses it
Closed-form barrier prices start here: add drift with Girsanov and you get the continuous knock-out and one-touch formulas (Merton 1973; Shreve Volume II, Chapter 7). Real barriers are often checked once a day, and the Broadie–Glasserman–Kou correction shifts the barrier away from the spot by a factor e0.5826σ√Δt so that the continuous formula prices the daily-checked contract.
Example
T = 1, b = 1: 2N(−1) = 0.3173. The walk with 100 steps of size 0.1 gives 0.3197; with 10,000 steps of size 0.01 it gives 0.3173.
Remember it
Twice the tail: touching b is twice as likely as ending above b.
Python · runs as isRun in browser
from math import comb, erf, sqrt

N = lambda x: 0.5 * (1 + erf(x / sqrt(2)))

def walk_max_prob(n, m):
    # card 5.7 with exact path counts: P(M_n = m) + 2 P(M_n > m), for n + m even
    k = (n + m) // 2                    # up steps needed to end at m
    c = comb(n, k)
    at_m, above = c, 0
    while k < n:                        # ends at m + 2, m + 4, ..., n
        c = c * (n - k) // (k + 1)
        k += 1
        above += c
    return (at_m + 2*above) / 2**n

for n in (100, 10**4):                  # n steps of size 1/sqrt(n): level 1 is m = sqrt(n)
    print(n, round(walk_max_prob(n, round(sqrt(n))), 4))
print("Brownian", round(2 * (1 - N(1)), 4))

# Output: the walk closes in on Brownian motion
# 100 0.3197
# 10000 0.3173
# Brownian 0.3173

Where these ideas come from

Interview questions

A symmetric random walk starts at 0. Will it hit +1, and how long does it take on average?

It hits +1 with probability one, but the expected time is infinite: rare, very long excursions below zero drag the mean up without bound.

What does the reflection principle say?

Take any path that reaches m and ends at b < m, and reflect it after its first visit to m. It now ends at 2m − b. This pairs paths one for one and gives the distribution of the running maximum.

The Stochastic Calculus Visual Lab →

Volume I · Chapter 6

Interest-Rate-Dependent Assets

Let the interest rate itself be random on the tree. Bonds, forwards, futures, caps and floors are then priced by discounting along each path.

Picture it

Picture a savings account whose interest rate is reset every year at random. What is a promise of 1 in ten years worth today? It depends on every rate along the way, so you average over all the possible rate paths, discounting year by year along each one. That average is the zero-coupon bond price, and the bond prices together give the yield curve.

The discount factor is now a product of one-period discounts along the path, each at that node’s rate. A zero-coupon bond’s price is the risk-neutral expectation of that product. Roll 1 back from maturity, discounting at each node.

With random rates, forward and futures prices separate. The forward price weighs payoffs by discounting; the futures price, marked to market every period, is a plain risk-neutral expectation. They agree only when rates are not random.

Caps, floors and swaps follow from the same backward step, and the tree’s parameters are fixed by matching the bond prices seen in the market.

B0,m = Ẽ[∏k=0m−1 11 + Rk],   Futn,m = Ẽn[Sm],   Forn,m = Ẽn[Dm Sm]Dn Bn,m

Reading the formula: Rk: the interest rate in period k · ∏: multiply the one-period discounts together · B0,m: price today of 1 paid at period m · D: the discount factor up to a date · Fut, For: futures and forward prices

Live modelILLUSTRATIVE INPUTS

A recombining short-rate tree: each period the rate is multiplied by the up or down factor with risk-neutral chance one half. Bars are zero-coupon bond prices; the line is the yield curve they imply.

The hard parts, step by step

The ideas in this chapter that most people get stuck on, each with a picture, the derivation line by line, worked numbers and the trap to avoid.

A zero-coupon bond from a rate tree, step by step

Picture it

A promise of 1 in two years is worth less today the higher rates turn out to be. So you start with 1 at maturity, walk back one year at a time, and at each node discount by that node’s own rate.

Step by step

  1. Dn = ∏k<n 11 + RkThe discount factor along a path: one-period discounts multiplied together.
  2. Bn,m = Ẽn[DmDn]Price at n of 1 paid at m.
  3. roll back: B = average of the two next values1 + rate at this nodeIn practice: start with 1 at maturity and work backwards.

Worked numbers

Rate tree: r0 = 4%, next period 5% (up) or 3.4% (down), each with pricing weight 0.5.

  • One-period bond: B0,1 = 1 / 1.04 = 0.96154
  • At time 1 the remaining one-period bond is 1/1.05 = 0.95238 (up) or 1/1.034 = 0.96712 (down).
  • B0,2 = 0.5 × (0.95238 + 0.96712) / 1.04 = 0.92284, a two-period yield of 4.097%

Common mistake: Discounting the whole way with today’s rate. When rates are random, each period uses its own rate along the path.

Forward price versus futures price when rates are random

Picture it

A futures contract settles gains and losses every period. If the asset tends to be worth more exactly when rates are high, your futures gains get reinvested at high rates and your losses are funded at low rates. That makes the futures position slightly more attractive, so its price sits a little above the forward.

Step by step

  1. For0,m = Ẽ[Dm Sm]B0,mThe forward price: the fixed price agreed today that makes the contract worth zero.
  2. Fut0,m = Ẽ[Sm]The futures price: a plain pricing-weight average, no discounting.
  3. equal when rates are not randomThen Dm is a constant and cancels.

Worked numbers

Rate tree: r0 = 4%, next period 5% (up) or 3.4% (down), each with pricing weight 0.5.

Asset worth 100 × (1 + r1) at time 2, so it rises with rates.

  • Forward: (100 / 1.04) / 0.92284 = 104.194
  • Futures: 100 × (1 + 0.5 × (5% + 3.4%)) = 104.200
  • The futures price is higher by 0.006, as the picture says.

Common mistake: Treating forward and futures prices as identical in a model where rates move.

The swap rate: the fixed rate that makes a swap worth zero

Picture it

In a swap you pay a fixed rate and receive whatever the floating rate turns out to be. The floating side is worth exactly what it costs to deposit 1 now and take back 1 at the end, so pricing it needs no model at all. The swap rate just balances the fixed side against that.

Step by step

  1. floating leg value = 1 − B0,mReceiving each period’s rate on 1 is the same as holding 1 now and owing 1 at maturity.
  2. fixed leg value = K ∑k=1m B0,kA fixed payment K each period, discounted with today’s bond prices.
  3. swap rate = 1 − B0,mB0,1 + … + B0,mSet the two legs equal and solve for K.

Worked numbers

Rate tree: r0 = 4%, next period 5% (up) or 3.4% (down), each with pricing weight 0.5.

  • Two-period swap rate = (1 − 0.92284) / (0.96154 + 0.92284) = 4.095%
  • Check: receiving r1 at time 2 is worth 0.5 × (0.05/(1.04 × 1.05) + 0.034/(1.04 × 1.034)) = 0.03870 = B0,1 − B0,2 ✓

Common mistake: Building a rate model to value the floating leg. Its value comes straight from today’s bond prices.

Caps and floors, and the parity that links them

Picture it

A caplet pays you if the rate ends above a level K, like insurance against rates rising. A floorlet pays if it ends below K. Holding a caplet and selling a floorlet gives you exactly the rate minus K, whatever happens, so their prices must line up with a simple swap payment.

Step by step

  1. caplet = Ẽ[Dm (R − K)+],   floorlet = Ẽ[Dm (K − R)+]Price each with the pricing weights, discounting along each path.
  2. caplet − floorlet = Ẽ[Dm (R − K)]Because (x)+ − (−x)+ = x: the cap–floor parity.

Worked numbers

Rate tree: r0 = 4%, next period 5% (up) or 3.4% (down), each with pricing weight 0.5.

Strike K = 4% on the time-1 rate, paid at time 2.

  • Caplet: 0.5 × (5% − 4%) / (1.04 × 1.05) = 0.004579
  • Floorlet: 0.5 × (4% − 3.4%) / (1.04 × 1.034) = 0.002790
  • Difference 0.001789 = value of receiving (r1 − 4%) at time 2 ✓

Common mistake: Discounting the caplet with the up-state rate in every state. Each state uses the rates along its own path.

Forward measures: pricing in bond units

Picture it

Count money in zero-coupon bonds that mature on the payment date, instead of in bank-account cash. In those units the awkward random discounting disappears: today’s price is just the bond price times an average of the payoff, with the weights tilted towards the low-rate states, where that bond is worth more.

Step by step

  1. Dm = 1(1 + R0)···(1 + Rm−1),   B0,m = Ẽ[Dm]The zero-coupon bond price is the average discount factor.
  2. P̃m(ω) = P̃(ω) · Dm(ω)B0,mA change of measure with Z = Dm/B0,m, which averages to 1, exactly as in Chapter 3.
  3. V0 = Ẽ[Dm Vm] = B0,m Ẽm[Vm]Price = bond price × forward-measure average. At a later time n: Vn = Bn,m Ẽmn[Vm].
  4. Forn,m = Sn / Bn,m is a martingale under P̃mSo the forward price today is the forward-measure average of the asset price at m: For0,m = Ẽm[Sm].

Worked numbers

R0 = 10%, then R1 = 15% after H or 5% after T, p̃ = 0.5. A payment at time 2 of 100 × max(R1 − 10%, 0): 5 after H, 0 after T.

  • Discount factors: D2 = 1/(1.10 × 1.15) = 0.7905 after H, 1/(1.10 × 1.05) = 0.8658 after T, so B0,2 = 0.8282.
  • Forward measure: P̃2(H) = 0.5 × 0.7905 / 0.8282 = 0.4773, P̃2(T) = 0.5227.
  • Price: 0.8282 × (0.4773 × 5) = 0.8282 × 2.3864 = 1.9763, the same as Ẽ[D2 V2] = 0.5 × 0.7905 × 5.

Common mistake: Multiplying the risk-neutral average payoff by the bond price: 0.8282 × 2.5 = 2.0704 is wrong when rates are random, because the payoff and the discount factor move together.

Every formula in this chapter

10 formulas in the order you meet them. Each one comes with what it means, where a quant uses it on the desk, a worked example and Python you can copy or run in your browser. The expected output is in the comments, and every snippet is run against it before the page goes live.

  1. 6.1The discount process
  2. 6.2Risk-neutral pricing with random rates
  3. 6.3The zero-coupon bond price
  4. 6.4The yield
  5. 6.5The forward price
  6. 6.6The futures price and its gap to the forward
  7. 6.7The swap rate
  8. 6.8Caps, floors and their parity
  9. 6.9The forward measure
  10. 6.10Fitting the rate tree to today’s curve
6.1

The discount process

Dn = 1(1 + R0)(1 + R1)···(1 + Rn−1),   D0 = 1
t = 0t = 1t = 21÷ 1.04HT0.961540.96154÷ 1.05÷ 1.034HH, HTTH, TT0.915750.92992
D1 is 0.96154 on every path. The second step divides by the rate the first toss set, so D2 splits H from T only.
What it means
What 1 paid at time n is worth today along one path of the tree. Each period discounts at the rate set at the start of that period, so Dn is already known at time n − 1. With random rates it is a random number, not a constant.
Where a quant uses it
A rates Monte Carlo engine carries it along every simulated path. At each step it divides by 1 + rΔt at that path’s own short rate, and each cash flow on the path is valued by multiplying it by the running product.
Example
The chapter’s tree: R0 = 4%, then R1 = 5% after H or 3.4% after T. D1 = 1/1.04 = 0.96154 on every path. D2 = 1/(1.04 × 1.05) = 0.91575 after H and 1/(1.04 × 1.034) = 0.92992 after T, whatever the second toss.
Remember it
Divide once per period, by the rate fixed when that period starts.
Python · runs as isRun in browser
from itertools import product

R0, R1 = 0.04, {"H": 0.05, "T": 0.034}   # the chapter's rate tree
for w in product("HT", repeat=2):
    D1 = 1 / (1 + R0)                     # known at time 0
    D2 = D1 / (1 + R1[w[0]])              # known at time 1: R1 is set by the first toss
    print("".join(w), round(D1, 5), round(D2, 5))

# Output: D2 depends only on the first toss
# HH 0.96154 0.91575
# HT 0.96154 0.91575
# TH 0.96154 0.92992
# TT 0.96154 0.92992
6.2

Risk-neutral pricing with random rates

Vn = Ẽn[Dm Vm]Dn,   0 ≤ n ≤ m
t = 0t = 1t = 2105103.410010096.1538÷ 1.05÷ 1.034avg ÷ 1.04HT
Each step back divides by that node’s own rate: 105 and 103.4 both become 100, and averaging and dividing by 1.04 gives 96.1538 today.
What it means
A payoff Vm at time m is worth, at time n, the risk-neutral average of its discounted value, turned back into time-n money by dividing by Dn. Taken one period at a time it is the chapter 1 step with the node’s own rate: Vn = (p̃ Vn+1(H) + q̃ Vn+1(T)) / (1 + Rn).
Where a quant uses it
Every rates pricer computes this. A tree rolls it back node by node, which is how callable bonds and Bermudan swaptions are priced; a Monte Carlo engine averages DmVm over simulated paths. Checking that the two give the same number is a standard model test.
Example
An asset pays 100(1 + R1) at time 2: 105 after H, 103.4 after T. One step back it is worth 105/1.05 = 100 or 103.4/1.034 = 100, and today 100/1.04 = 96.1538. That is right: it is what 100 deposited at time 1 grows to.
Remember it
Average the two next values, divide by this node’s own rate, repeat back to today.
Python · runs as isRun in browser
R0, R1 = 0.04, {"H": 0.05, "T": 0.034}
V2 = {w: 100 * (1 + R1[w]) for w in "HT"}     # pays 100(1 + R1) at time 2

# roll back one period at a time, each node at its own rate
V1 = {w: V2[w] / (1 + R1[w]) for w in "HT"}   # V2 is already known at time 1
V0 = 0.5 * (V1["H"] + V1["T"]) / (1 + R0)
print(round(V1["H"], 4), round(V1["T"], 4), round(V0, 4))  # 100.0 100.0 96.1538

# or average D2 * V2 over the paths in one go
D2 = {w: 1 / ((1 + R0) * (1 + R1[w])) for w in "HT"}
print(round(0.5 * (D2["H"] * V2["H"] + D2["T"] * V2["T"]), 4))  # 96.1538
6.3

The zero-coupon bond price

Bn,m = Ẽn[DmDn],   Bm,m = 1
t = 0t = 1t = 24%5%3.4%110.952380.967120.92284B(0,2)pays 1pays 1
Rates sit in the nodes, bond prices under them. Start from 1 at maturity and roll back: 0.95238 and 0.96712 average to 0.92284 today.
What it means
The price at time n of 1 paid at time m: card 6.2 with Vm = 1. In practice, put 1 at maturity and roll back, averaging the two next values and discounting at each node’s own rate. Today’s prices B0,1, B0,2, … are the discount curve.
Where a quant uses it
The first test of any short-rate tree or simulation is whether it gives back today’s discount factors. If it misprices the zero-coupon bonds, every swap, cap and callable bond priced on it carries the same error. Card 6.10 fixes this by construction.
Example
B0,1 = 1/1.04 = 0.96154. At time 1 the remaining bond is 1/1.05 = 0.95238 (H) or 1/1.034 = 0.96712 (T), so B0,2 = 0.5 × (0.95238 + 0.96712)/1.04 = 0.92284.
Remember it
The same rollback as card 6.2, with a payoff of 1 in every final state.
Python · runs as isRun in browser
def zcb(rates, p=0.5):
    # rates[n][k]: short rate at time n after k up moves (recombining tree)
    B = [1.0] * (len(rates) + 1)                 # 1 at maturity in every state
    for n in range(len(rates) - 1, -1, -1):
        B = [(p*B[k + 1] + (1 - p)*B[k]) / (1 + rates[n][k]) for k in range(n + 1)]
    return B[0]

tree = [[0.04], [0.034, 0.05]]                   # the chapter's tree, down then up
print(round(zcb(tree[:1]), 5))                   # 0.96154
print([round(1 / (1 + r), 5) for r in tree[1]])  # [0.96712, 0.95238]
print(round(zcb(tree), 5))                       # 0.92284
6.4

The yield

Yn,m = −1m − n log Bn,m,   so Bn,m = e−(m−n)Yn,m
once a periodcontinuousm = 1m = 24.000%3.922%4.097%4.015%8.2 bp
Both curves slope up. The same two-period bond reads 4.015% or 4.097%: only the compounding differs.
What it means
The one constant rate, compounded continuously, that grows the bond price back to 1 at maturity. Prices and yields carry the same information; plot Y0,m against m and you have the yield curve. Compounded once a period instead, the same bond yields Bn,m−1/(m−n) − 1.
Where a quant uses it
Curves are quoted in yields but stored as discount factors, and the curve system converts with a stated compounding and day-count convention. Mixing conventions is a classic source of basis-point errors: here the two-period yield moves by 8.2 basis points just from the compounding.
Example
B0,2 = 0.92284 gives Y0,2 = −log(0.92284)/2 = 4.015% per period, against 3.922% for one period, so the curve slopes up. Compounded once a period, the same bond yields 4.097%, the figure in the hard parts above.
Remember it
The yield is the one flat rate that grows the bond’s price back to 1.
Python · runs as isRun in browser
from math import log

B = {1: 1 / 1.04, 2: 0.5 * (1/1.05 + 1/1.034) / 1.04}   # B(0,1), B(0,2) from the tree
for m, price in B.items():
    cont = -log(price) / m             # continuously compounded, per period
    per = price ** (-1 / m) - 1        # compounded once a period
    print(m, round(100 * cont, 3), round(100 * per, 3))

# Output: yields in % per period; the curve slopes up
# 1 3.922 4.0
# 2 4.015 4.097
6.5

The forward price

Forn,m = SnBn,m = Ẽn[Dm Sm]Dn Bn,m
t = 0t = 296.1538spot S0÷ 0.922836bond B(0,2)H 105+0.806For 104.194T 103.4−0.794discounted: +0.738 and −0.738, so the contract is worth 0
Spot divided by the bond price lands at 104.194, between the two outcomes. Discounted, the gain and the loss cancel exactly.
What it means
The price fixed at time n for buying the asset at time m, chosen so that the contract is worth nothing when it is agreed: Ẽn[Dm(Sm − Forn,m)] = 0. Buy the asset now and pay for it by selling Sn/Bn,m zero-coupon bonds: at m you hold Sm and owe exactly Forn,m. This is for an asset that pays nothing before m.
Where a quant uses it
Bond and equity forwards are priced this way: spot divided by the discount factor to delivery, after taking off the present value of any coupons or dividends paid before then. Repo desks quote bond forwards like this. It needs no model of how rates move, only today’s Bn,m.
Example
The asset paying 100(1 + R1) at time 2 costs S0 = 96.1538 (card 6.2), and B0,2 = 0.922836, so For0,2 = 96.1538/0.922836 = 104.194.
Remember it
Forward = spot ÷ bond price: buy now, fund it with bonds, repay at m.
Python · runs as isRun in browser
R0, R1 = 0.04, {"H": 0.05, "T": 0.034}
D2 = {w: 1 / ((1 + R0) * (1 + R1[w])) for w in "HT"}
S2 = {w: 100 * (1 + R1[w]) for w in "HT"}           # the asset at time 2
E = lambda X: 0.5 * X["H"] + 0.5 * X["T"]           # risk-neutral average

S0 = E({w: D2[w] * S2[w] for w in "HT"})
B02 = E(D2)
For = S0 / B02
print(round(S0, 4), round(B02, 6), round(For, 3))   # 96.1538 0.922836 104.194

# a forward contract struck at For is worth nothing today
print(abs(E({w: D2[w] * (S2[w] - For) for w in "HT"})) < 1e-12)  # True
6.6

The futures price and its gap to the forward

Futn,m = Ẽn[Sm],   For0,m − Fut0,m = C̃ov(Dm, Sm)B0,m
T, rate 3.4%H, rate 5%103.4105zoomFor 104.194Fut 104.2000.006For − Fut = −0.00567 / 0.922836 = −0.00614
Futures is the plain average of 105 and 103.4. Discounting gives the low-rate outcome more weight, so the forward sits 0.006 lower.
What it means
A futures position is settled every period: at n + 1 you receive Futn+1,m − Futn,m, or pay it if it is negative. Each payment must be worth zero, and since Dn+1 is known at time n it drops out. So the futures price is a plain risk-neutral average of Sm, with no discounting. Writing Ẽ[DmSm] as B0,mFut0,m plus a covariance gives the gap. It is zero when rates are not random.
Where a quant uses it
Interest-rate futures (Eurodollar, now SOFR) imply rates a little above the matching forward rates. Before using futures to build the curve, a rates desk subtracts a convexity adjustment: this covariance term, estimated with a rate model. It grows with maturity and with rate volatility.
Example
Same asset: Fut0,2 = 0.5 × (105 + 103.4) = 104.2, against For0,2 = 104.194. The asset is high when rates are high, which is when D2 is low, so the covariance is negative: −0.00567/0.922836 = −0.00614. The futures price sits 0.006 above the forward.
Remember it
Futures: plain average of Sm. Forward: discount-weighted average. They agree when rates are not random.
Python · runs as isRun in browser
R0, R1 = 0.04, {"H": 0.05, "T": 0.034}
D2 = {w: 1 / ((1 + R0) * (1 + R1[w])) for w in "HT"}
S2 = {w: 100 * (1 + R1[w]) for w in "HT"}
E = lambda X: 0.5 * X["H"] + 0.5 * X["T"]
DS = {w: D2[w] * S2[w] for w in "HT"}

Fut = E(S2)                                    # plain average, no discounting
For = E(DS) / E(D2)                            # card 6.5
cov = E(DS) - E(D2) * E(S2)
print(round(Fut, 3), round(For, 3))            # 104.2 104.194
print(round(cov, 5), round(For - Fut, 5), round(cov / E(D2), 5))  # -0.00567 -0.00614 -0.00614
6.7

The swap rate

SRm = 1 − B0,mB0,1 + B0,2 + ··· + B0,m
t = 0receivefloatingpayfixed4%H 5%T 3.4%4.095%4.095%t = 1t = 2each leg is worth 0.077164 today
Receive floating, pay a fixed 4.095% on each date. At that rate both legs are worth 0.077164 today, so the swap costs nothing.
What it means
In a swap one side pays the floating rate Rn−1 at each date n = 1, …, m and the other pays a fixed K, on a notional of 1. Each floating payment is worth Ẽ[DnRn−1] = B0,n−1 − B0,n, so the floating leg adds up to 1 − B0,m. The swap rate is the K that makes the two legs equal, so the swap costs nothing to enter.
Where a quant uses it
Swap desks quote par swap rates for each maturity, and curve building runs this formula backwards: from the quoted rates it solves for B0,1, B0,2, … one maturity at a time. This is bootstrapping, and it needs no model of how rates move.
Example
m = 2: (1 − 0.922836)/(0.961538 + 0.922836) = 4.095%. The floating payment at time 2 is worth 0.5 × (0.05/(1.04 × 1.05) + 0.034/(1.04 × 1.034)) = 0.038702 = B0,1 − B0,2.
Remember it
Floating leg is 1 minus the last bond; divide by the bond sum.
Python · runs as isRun in browser
R0, R1 = 0.04, {"H": 0.05, "T": 0.034}
D1 = 1 / (1 + R0)
D2 = {w: D1 / (1 + R1[w]) for w in "HT"}
B1, B2 = D1, 0.5 * (D2["H"] + D2["T"])           # B(0,1), B(0,2)

# R1 paid at time 2, valued path by path, against B(0,1) - B(0,2)
print(round(0.5 * (D2["H"]*R1["H"] + D2["T"]*R1["T"]), 6), round(B1 - B2, 6))  # 0.038702 0.038702

SR = (1 - B2) / (B1 + B2)
print(round(100 * SR, 3))                        # 4.095
# bootstrapping: B(0,2) back from the quoted swap rate
print(round((1 - SR * B1) / (1 + SR), 5))        # 0.92284
6.8

Caps, floors and their parity

Capm = ∑n=1m Ẽ[Dn(Rn−1 − K)+],   Capm − Floorm = 1 − B0,m − K ∑n=1m B0,n
caplet+1%00.004579floorlet00.6%0.002790R1 − K+1%−0.6%0.001789−−==K = 4% · T: R1 = 3.4% · H: R1 = 5%
Caplet minus floorlet pays R1 − K in both states, +1% or −0.6%, so 0.004579 − 0.002790 = 0.001789, the swap value.
What it means
A cap pays (Rn−1 − K)+ at each date n, so a borrower paying the floating rate never pays more than K. A floor pays (K − Rn−1)+. Since x+ − (−x)+ = x, a cap minus a floor pays Rn−1 − K on every date: it is the swap of card 6.7.
Where a quant uses it
Companies with floating-rate loans buy caps to limit their interest bill. Cap and floor desks use parity to check their volatility surface: whatever volatility is used, cap minus floor at the same strike must equal the swap value at that strike, which comes from the curve alone.
Example
K = 4%, m = 2. The first payment, on R0 = 4%, is zero. The second caplet is worth 0.5 × 1%/(1.04 × 1.05) = 0.004579 and the floorlet 0.5 × 0.6%/(1.04 × 1.034) = 0.002790. The difference, 0.001789, equals 1 − 0.922836 − 0.04 × (0.961538 + 0.922836).
Remember it
Cap minus floor is a swap: the kinks cancel, the straight line stays.
Python · runs as isRun in browser
R0, R1, K = 0.04, {"H": 0.05, "T": 0.034}, 0.04
D1 = 1 / (1 + R0)
D2 = {w: D1 / (1 + R1[w]) for w in "HT"}
B1, B2 = D1, 0.5 * (D2["H"] + D2["T"])

# payments at time 1 (on R0) and time 2 (on R1), discounted path by path
cap = D1*max(R0 - K, 0) + 0.5*sum(D2[w]*max(R1[w] - K, 0) for w in "HT")
floor = D1*max(K - R0, 0) + 0.5*sum(D2[w]*max(K - R1[w], 0) for w in "HT")
print(round(cap, 6), round(floor, 6))                         # 0.004579 0.00279
print(round(cap - floor, 6), round(1 - B2 - K*(B1 + B2), 6))  # 0.001789 0.001789
6.9

The forward measure

Zm,m = DmB0,m,   P̃m(ω) = Zm,m(ω) P̃(ω),   Vn = Bn,m Ẽmn[Vm]
risk-neutralH, rate 15%0.5T, rate 5%0.5forward, × D2 / B(0,2)H, D2 0.79050.47727T, D2 0.86580.522730.82816 × 0.47727 × 5 = 1.9763not 0.82816 × 2.5 = 2.0704
Weighting each path by D2/B0,2 moves weight to T, where rates are low. Then price = bond × plain average: 1.9763.
What it means
Count money in zero-coupon bonds maturing at m instead of in the bank account. Zm,m is positive and averages to 1 under P̃, so it reweights the paths, tilting them towards low-rate paths where Dm is high. Under P̃m the random discounting leaves the average: price = bond price × average payoff. The forward price Forn,m is a martingale under P̃m, so For0,m = Ẽm[Sm].
Where a quant uses it
This is how caplets and swaptions are priced and quoted. Under the forward measure for the payment date the forward rate is a martingale, so a caplet is a discount factor times a Black call on the forward rate. Cap volatilities are quoted through that formula, and the LIBOR market model is built on it.
Example
The chapter’s second tree: R0 = 10%, then R1 = 15% or 5%, and a payment of 100 × (R1 − 10%)+ = 5 or 0 at time 2. B0,2 = 0.82816 and P̃2(H) = 0.47727, so the price is 0.82816 × 0.47727 × 5 = 1.9763. Using P̃ instead gives 0.82816 × 2.5 = 2.0704, which is wrong.
Remember it
Count in bonds: low-rate paths gain weight, and the discounting moves outside the average.
Python · runs as isRun in browser
R0, R1 = 0.10, {"H": 0.15, "T": 0.05}
D2 = {w: 1 / ((1 + R0) * (1 + R1[w])) for w in "HT"}
B02 = 0.5 * (D2["H"] + D2["T"])
Pm = {w: 0.5 * D2[w] / B02 for w in "HT"}            # P~2 = Z(2,2) * P~, sums to 1
V2 = {w: 100 * max(R1[w] - 0.10, 0) for w in "HT"}   # pays 5 after H, 0 after T

print(round(B02, 5), round(Pm["H"], 5), round(Pm["T"], 5))  # 0.82816 0.47727 0.52273
print(round(B02 * sum(Pm[w] * V2[w] for w in "HT"), 4))     # 1.9763
print(round(0.5 * sum(D2[w] * V2[w] for w in "HT"), 4))     # 1.9763
# wrong: bond price times the risk-neutral average payoff
print(round(B02 * 0.5 * (V2["H"] + V2["T"]), 4))            # 2.0704
6.10

Fitting the rate tree to today’s curve

Beyond the chapter
Rn(k) = anuk,   with an chosen so that  ∑k=0n Qn(k)1 + anuk = B0,n+1market
n = 0n = 1n = 2u = 5/3.44%3.4%5%2.892%4.253%6.255%× u× uB(0,1) 0.961538B(0,2) 0.922836B(0,3) 0.884
Each column’s level is solved so the tree reprices one more market bond, shown underneath; the ratio u between neighbours stays fixed.
What it means
Fix the tree’s shape from volatility (each up move multiplies the rate by u), then solve for one level an per period so that the tree reprices every zero-coupon bond in the market today. Qn(k) is today’s value of 1 paid at node k after n periods; it is carried forward one period at a time, so each an is a search for one number. This is the Black–Derman–Toy idea with one constant volatility; Ho–Lee moves the rate by an added step instead of a ratio.
Where a quant uses it
Rates desks fit their short-rate trees (Ho–Lee, Black–Derman–Toy, Hull–White) this way before pricing callable bonds or Bermudan swaptions, so the tree agrees with the curve that prices the swaps. The volatility, here u, is then fitted to cap or swaption prices.
Example
Feed in B0,1 = 1/1.04 and B0,2 = 0.922836 with u = 5/3.4, and the search returns the chapter’s tree: 4%, then 3.4% or 5%. Add a three-period bond at 0.884 and the time-2 rates come out at 2.892%, 4.253% and 6.255%, with all three bonds repriced.
Remember it
Shape from volatility, level from the curve: one level per period, one bond each.
Python · runs as isRun in browser
mkt = [1/1.04, 0.922836, 0.884]   # today's zero-coupon prices B(0,1), B(0,2), B(0,3)
u = 5 / 3.4                       # up-node rate / down-node rate at each step
Q = [1.0]                         # Q[k]: value today of 1 paid at node k (k = up moves)
for n, target in enumerate(mkt):
    bond = lambda a: sum(q / (1 + a * u**k) for k, q in enumerate(Q))
    lo, hi = 0.0, 1.0
    for _ in range(60):           # bisection: the bond price falls as the level a rises
        a = (lo + hi) / 2
        lo, hi = (a, hi) if bond(a) > target else (lo, a)
    R = [a * u**k for k in range(n + 1)]
    print(n, [round(100 * r, 3) for r in R])
    half = [q / (1 + r) / 2 for q, r in zip(Q, R)]   # each node passes half to each child
    Q = [(half[k - 1] if k else 0) + (half[k] if k <= n else 0) for k in range(n + 2)]
print("tree prices B(0,3):", round(sum(Q), 6))

# Output: rates in % at each node, then the check
# 0 [4.0]
# 1 [3.4, 5.0]
# 2 [2.892, 4.253, 6.255]
# tree prices B(0,3): 0.884

Where these ideas come from

Interview questions

Why can futures and forward prices differ?

Futures settle gains and losses every day. If the asset tends to rise when rates rise, gains are reinvested at higher rates and losses are funded at lower ones, so the futures price sits above the forward. With non-random rates they are equal.

How do you get a zero-coupon bond price from a short-rate tree?

Put 1 at maturity and work backwards: at each node, average the two next values with the risk-neutral probabilities and discount at that node’s rate.

Yield Curve Quant Notes & Lab →

Volume II is next

Brownian motion, Itô’s formula, Girsanov, the Black–Scholes PDE, exotics, change of numéraire, term-structure models and jumps: the same format, one live model per chapter.

Prepare with the Stochastic Calculus Interview Playbook