SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.3.1 Expectation and LOTUSConcept · 30 min
      2. 5.3.2 Variance, and linearity of expectationConcept · 35 min
      3. 5.3.3 Skewness and kurtosisConcept · 30 min
      4. 5.3.4 Practice set: expectation and momentsPractice set · 20 min
      5. 5.3.5 Case study: return moments and value at riskCase study · 35 min

Level 5, Probability and statistics 5.3 Expectation and moments Lesson 1 of 5

ConceptLesson 5.3.1 in Level 5, Probability and statistics. About 30 minutes.

Expectation and LOTUS

The expected value

A random variable XX attaches a number to each outcome of an experiment (lesson 5.2.1). Its probability mass function (pmf), pX(x)=P(X=x)p_X(x) = P(X = x), gives the chance of each value xx. The expected value of XX weights each value by its chance and adds up.

Rule: Expected value

E[X]=∑xx pX(x)\mathbb{E}[X] = \sum_x x\,p_X(x)

The sum runs over every value XX can take. E[X]\mathbb{E}[X] is also called the mean of XX and written μ\mu (mu). It has the units of XX: dollars, days, dots on a die.

For a fair die, each face from 1 to 6 has probability 16\frac{1}{6}:

xx123456
pX(x)p_X(x)1/61/61/61/61/61/6
x pX(x)x\,p_X(x)1/62/63/64/65/66/6

The last row adds up to 216=3.5\frac{21}{6} = 3.5. No roll ever shows 3.5: an expected value need not be a value XX can take.

A game with a negative expected value

Roll a die. You win $4 on a six and lose $1 on anything else. Your winnings XX are 4 with probability 16\frac{1}{6} and −1-1 with probability 56\frac{5}{6}, so

E[X]=4⋅16+(−1)⋅56=−16\mathbb{E}[X] = 4 \cdot \tfrac{1}{6} + (-1) \cdot \tfrac{5}{6} = -\tfrac{1}{6}

That is a loss of about $0.17 a game: the game loses money on average. A prize of $5 would make it fair, with E[X]=0\mathbb{E}[X] = 0. A constant cc, which takes one value with probability 1, has E[c]=c\mathbb{E}[c] = c.

Try it

expected is the rule: a sum of value times probability. Fraction keeps exact fractions, so the die prints 7/2.

The last line averages the two possible winnings without their probabilities. That gives 1.5, which is wrong (common mistake 1).

⌘/Ctrl + Enter runs the cell

The balance point and the long-run average

Picture the pmf as bars standing on a ruler, each as heavy as its probability. The expected value is the point where the ruler balances. A fair die balances in the middle, at 3.5.

Each pmf balances at its expected value. The die is symmetric, so it balances in the middle. The waiting time is most often 1, but its long tail pulls the balance point out to 3.

Now count the rolls until a 5 or a 6 first appears. That count is geometric with p=13p = \frac{1}{3} (lesson 5.2.2), and one roll is the most likely count. Yet the mean is 3: the balance point is not the tallest bar.

The long-run average

Roll the die nn times and average the results. Each face turns up in about 16\frac{1}{6} of the rolls, so the average is close to ∑xx⋅16=3.5\sum_x x \cdot \frac{1}{6} = 3.5. As nn grows, the share of each face settles on its probability, and the average settles on E[X]\mathbb{E}[X].

That is what an expected value means in practice: the average result per try over a great many tries. Lesson 5.7.2 states it precisely as the law of large numbers, and case study 5.3.5 averages 1,000 daily returns this way.

Try it

100,000 simulated rolls from one seeded run. rng.integers(1, 7) draws whole numbers from 1 to 6: the upper end, 7, is left out.

The average of the first nn rolls wanders at first, then settles near 3.5. The last line plays the game 100,000 times: the average winnings are −0.16345-0.16345, close to −16≈−0.1667-\frac{1}{6} \approx -0.1667.

⌘/Ctrl + Enter runs the cell

When the sum is infinite

The sum in the rule can fail to settle. Toss a coin until the first head. If that takes kk tosses, which has probability (12)k\left(\frac{1}{2}\right)^k, you win 2k2^k dollars.

Each term of the sum is 2k⋅(12)k=12^k \cdot \left(\frac{1}{2}\right)^k = 1, so the expected value is 1+1+1+⋯1 + 1 + 1 + \cdots. That series diverges (lesson 1.5.3), so the game has no finite expected value. If it paid nothing after 10 tails in a row, the expected value would be exactly $10: one dollar for each toss allowed.

A simulation shows the symptom: averages never settle. Rare long runs of tails pay huge amounts, so the more games you play, the larger the typical average.

Try it

For each number of games nn, the cell plays 100 separate runs of nn games. It prints the median of the 100 averages, the middle one once they are sorted. The number of tosses is geometric with p=12p = \frac{1}{2}.

In this seeded run the median grows by about 3 each time nn is multiplied by 10. It does not settle, because there is no number to settle on.

⌘/Ctrl + Enter runs the cell

The means of module 5.2's distributions

The same sum gives the mean of each distribution of module 5.2.

distributionvaluesE[X]\mathbb{E}[X]
Bernoulli(pp)0 or 1pp
Bin⁡(n,p)\operatorname{Bin}(n, p)0 to nnnpnp
Geom⁡(p)\operatorname{Geom}(p), trials to the first success1, 2, 3, …1p\frac{1}{p}
Poisson⁡(λ)\operatorname{Poisson}(\lambda)0, 1, 2, …λ\lambda

A Bernoulli variable is 1 with probability pp and 0 otherwise, so E[X]=0⋅(1−p)+1⋅p=p\mathbb{E}[X] = 0 \cdot (1 - p) + 1 \cdot p = p. The cell checks the other three, and lesson 5.3.2 shows why the binomial gives npnp.

Each mean reads naturally. Ten trials with p=0.3p = 0.3 give 3 successes on average, and waiting for a six takes 6 rolls on average. A Poisson count of rare events with rate λ=2.5\lambda = 2.5 averages 2.5.

Try it

The binomial sum has 11 terms. The geometric and Poisson sums have infinitely many, so the cell adds enough terms for the rest to be tiny.

For the geometric, the sums of the first 10, 20, 50 and 200 terms climb to 6. SciPy's .mean() gives each answer directly.

⌘/Ctrl + Enter runs the cell

The expected value of a function: LOTUS

A function of a random variable is another random variable. If XX is a die roll, its square Y=X2Y = X^2 is one, and so were the game's winnings. To find E[Y]\mathbb{E}[Y] you could work out the pmf of YY first, but you do not need to.

Rule: LOTUS

E[g(X)]=∑xg(x) pX(x)\mathbb{E}[g(X)] = \sum_x g(x)\,p_X(x)

Weight each value g(x)g(x) by the probability of xx. The name is short for the law of the unconscious statistician, because people use it without noticing that it is a rule.

Here is the same answer found both ways. Let XX take the values −1-1, 0, 1 and 2, each with probability 14\frac{1}{4}, and let Y=X2Y = X^2.

xx−1-1012
pX(x)p_X(x)1/41/41/41/4
g(x)=x2g(x) = x^21014
  • With LOTUS: E[X2]=14(1+0+1+4)=32\mathbb{E}[X^2] = \frac{1}{4}(1 + 0 + 1 + 4) = \frac{3}{2}.
  • Through the pmf of YY: YY is 0 with probability 14\frac{1}{4}, 1 with probability 12\frac{1}{2} (from x=−1x = -1 and x=1x = 1), and 4 with probability 14\frac{1}{4}. So E[Y]=0+12+1=32\mathbb{E}[Y] = 0 + \frac{1}{2} + 1 = \frac{3}{2}, the same.

The second way had to merge the two values of xx that give y=1y = 1. LOTUS never needs that step.

For a fair die, LOTUS gives E[X2]=1+4+9+16+25+366=916≈15.17\mathbb{E}[X^2] = \frac{1 + 4 + 9 + 16 + 25 + 36}{6} = \frac{91}{6} \approx 15.17. With g(x)=1xg(x) = \frac{1}{x} it gives E[1X]=49120≈0.4083\mathbb{E}\left[\frac{1}{X}\right] = \frac{49}{120} \approx 0.4083.

Try it

expect_g is LOTUS: it applies g to each value and weights by pXp_X. The second line builds the pmf of YY by hand and agrees.

Then the die, exactly and from 100,000 seeded rolls: 15.2204 and 0.4073.

⌘/Ctrl + Enter runs the cell

The mean of g(X)g(X) is not gg of the mean

The mean of the squares is not the square of the mean. For the die, E[X2]=916≈15.17\mathbb{E}[X^2] = \frac{91}{6} \approx 15.17, but (E[X])2=3.52=12.25(\mathbb{E}[X])^2 = 3.5^2 = 12.25. They differ by 3512≈2.92\frac{35}{12} \approx 2.92, a number lesson 5.3.2 calls the variance.

The same happens with 1X\frac{1}{X}: E[1X]≈0.4083\mathbb{E}\left[\frac{1}{X}\right] \approx 0.4083, but 1E[X]=27≈0.2857\frac{1}{\mathbb{E}[X]} = \frac{2}{7} \approx 0.2857. Putting the mean into gg works only for straight lines, g(x)=ax+bg(x) = ax + b (lesson 5.3.2).

Case study 2.4.5 met this with g=ln⁡g = \ln. A fair flip of $20,000 on $100,000 has expected log wealth 11.4925, below ln⁡100,000=11.5129\ln 100{,}000 = 11.5129. Lesson 5.7.1 shows which way the gap goes for curves that bend up or down: Jensen's inequality.

Try it

Each line prints E[g(X)]\mathbb{E}[g(X)] and then g(E[X])g(\mathbb{E}[X]) for the die, as exact fractions.

Only the straight line, g(x)=10x−20g(x) = 10x - 20, gives the same number twice.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. Weight by the probabilities. Averaging the game's two outcomes, 4 and −1-1, gives 1.5; the expected value is −16-\frac{1}{6}.
  2. Check that the probabilities add up to 1 before trusting an expected value.
  3. Do not round a mean to a possible value. A die's mean is 3.5, not 3 or 4.
  4. The mean of a function is not the function of the mean. E[X2]\mathbb{E}[X^2] is larger than (E[X])2(\mathbb{E}[X])^2 unless XX never varies.
  5. In LOTUS, weight by the probabilities of XX. If you build the pmf of YY instead, add up the probabilities of every xx that gives the same yy.
  6. A simulated average can mislead. When the sum for E[X]\mathbb{E}[X] diverges, averages never settle. Check the sum, not only a simulation.

Expected values and LOTUS

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • E[X]=∑xx pX(x)\mathbb{E}[X] = \sum_x x\,p_X(x): each value weighted by its probability, in the units of XX. It is the balance point of the pmf and the long-run average of many draws.
  • A mean need not be a possible value, it can be negative, and it fails to exist when the sum diverges.
  • Means: Bernoulli pp, binomial npnp, geometric 1p\frac{1}{p} (trials to the first success), Poisson λ\lambda.
  • LOTUS: E[g(X)]=∑xg(x) pX(x)\mathbb{E}[g(X)] = \sum_x g(x)\,p_X(x), with no need for the pmf of g(X)g(X).
  • In general E[g(X)]≠g(E[X])\mathbb{E}[g(X)] \neq g(\mathbb{E}[X]): for the die, 916\frac{91}{6} against 12.2512.25. Straight lines are the exception.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.