Part 1 · ProbabilityLesson 212 minQuant Bible §2.2
Expected value and linearity
The weighted average that prices every game, and the linearity trick that solves half of all interview questions.
Every price in finance is an expected value of something. An option, a bond, a bet on a dice game: once you can write down what it pays in each outcome and how likely each outcome is, the fair price is a weighted average. This lesson is about computing that average, and about one property of it that makes hard questions easy.
The weighted average
A random variable X has a probability mass function p(x) if it is discrete or a density f(x) if it is continuous. Its expected value (or mean, μ) weights every value by its probability:
E[X]=x∑xp(x)orE[X]=∫xf(x)dx.
The same recipe prices any payoff g(X): weight g(x) instead of x.
E[g(X)]=x∑g(x)p(x)or∫g(x)f(x)dx.
A fair six-sided die pays E[X]=(1+2+3+4+5+6)/6=3.5. If a game pays the roll, its fair price is $3.50. Pay less and you profit on average; pay more and you lose.
Pricing a choice: the re-roll game
Interviewers love to add a decision. Roll a die; you may re-roll once and must keep the second roll. What is the game worth? Work backwards. A fresh roll is worth 3.5, so keep anything above 3.5 and re-roll 1, 2 or 3:
E=63⋅3.5+61(4+5+6)=4.25.
If each re-roll costs $1, a re-roll is worth 3.5−1=2.5, so you only re-roll 1s and 2s: 62⋅2.5+61(3+4+5+6)=23/6≈3.83.
With unlimited $1 re-rolls the game is worth some value V, and the rule is to keep any face above V−1. Keeping 4, 5, 6 gives V=2.5+21(V−1), so V=4. Keeping 3 or more gives the same V=4, because a 3 is exactly break-even.
Figure 2.1The re-roll game on a real die3D model
Each glossy column is what the game is worth if you keep any roll of at least that face; the tallest is the optimal rule. Roll games with that rule and watch your average converge on the fair price. Turn on unlimited re-rolls and a cost to see the rule shift.
Figure 2.2Strategy lab for any dieInteractive
The same calculation as a chart, including a 100-sided die. Each bar is what the game is worth if you keep any roll of at least that face. The highest bar is the optimal rule and the fair price. Switch to a 100-sided die or unlimited re-rolls, then check the theory with 20,000 simulated games.
Linearity: the trick that solves half the questions
Expectation is linear: E[aX+b]=aE[X]+b. More surprisingly, it adds across any random variables, even dependent ones:
E[X1+X2+⋯+Xn]=E[X1]+E[X2]+⋯+E[Xn].
So when a question asks for the expected number of somethings, write the count as a sum of indicators, Ii=1 if thing i happens and 0 otherwise. Each indicator has E[Ii]=P(thing i), and you add those up. You never need the joint distribution.
Example. Ten boys and ten girls stand in a random line. What is the expected number of adjacent boy–girl pairs?
There are 19 neighbouring slots. Slot i is mixed with probability
P(mixed)=20⋅192⋅10⋅10=1910,
so the answer is 19×1910=10. The slots are dependent (a mixed slot changes who is left for the next one), and it doesn’t matter.
Figure 2.3Line-up simulatorInteractive
Each shuffle lines up 10 boys (blue) and 10 girls (orange) and counts mixed neighbours (green links). Run thousands of line-ups: the average converges on 10, exactly as linearity predicts.
In code
import numpy as nprng = np.random.default_rng(1)# Fair value of "roll, optionally re-roll once" by simulationfirst = rng.integers(1, 7, 1_000_000)second = rng.integers(1, 7, 1_000_000)payoff = np.where(first <= 3, second, first)print(payoff.mean()) # ≈ 4.25# Linearity: expected mixed neighbours in a line of 10 boys + 10 girlsline = np.array([0] * 10 + [1] * 10)mixed = []for _ in range(100_000): p = rng.permutation(line) mixed.append(np.sum(p[1:] != p[:-1]))print(np.mean(mixed)) # ≈ 10.0
Check yourself
A deck is shuffled. What is the expected number of positions where the card is the same as in a fresh, unshuffled deck of 52?
Each card is in its own position with probability 1/52. By linearity the expected number of fixed points is 52×1/52=1, for a deck of any size.