SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.7.1 The Markov, Chebyshev and Jensen inequalitiesConcept · 35 min
      2. 5.7.2 The law of large numbersConcept · 30 min
      3. 5.7.3 The central limit theoremConcept · 35 min
      4. 5.7.4 Practice set: inequalities and limit theoremsPractice set · 25 min
      5. 5.7.5 Case study: the error of a Monte Carlo priceCase study · 35 min

Level 5, Probability and statistics 5.7 Inequalities and limit theorems Lesson 2 of 5

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

The law of large numbers

The sample mean is a random variable

Roll a die 10 times and average the results. Roll 10 more and the average changes. Before the rolls are made, their average is a random variable, with a distribution of its own.

Write X1,…,XnX_1, \ldots, X_n for nn draws that are independent and identically distributed, or i.i.d.: independent (lesson 5.1.3), and each with the distribution of one draw XX. That draw has mean μ\mu and variance σ2\sigma^2.

The sample mean is

Xˉn=X1+X2+⋯+Xnn\bar{X}_n = \frac{X_1 + X_2 + \cdots + X_n}{n}

Rule: Mean and variance of the sample mean

E[Xˉn]=μVar⁡(Xˉn)=σ2nσXˉn=σn\begin{gathered} \mathbb{E}[\bar{X}_n] = \mu \\[4pt] \operatorname{Var}(\bar{X}_n) = \frac{\sigma^2}{n} \\[4pt] \sigma_{\bar{X}_n} = \frac{\sigma}{\sqrt{n}} \end{gathered}

By linearity the sum has mean nμn\mu; dividing by nn gives μ\mu. The variances of independent draws add up to nσ2n\sigma^2, and dividing by nn divides the variance by n2n^2 (lesson 5.3.2). The standard deviation σn\frac{\sigma}{\sqrt{n}} is called the standard error of the mean: the typical size of the miss Xˉn−μ\bar{X}_n - \mu.

For a die, μ=3.5\mu = 3.5 and σ2=3512≈2.9167\sigma^2 = \frac{35}{12} \approx 2.9167:

rolls nn1101001,00010,000
Var⁡(Xˉn)\operatorname{Var}(\bar{X}_n)2.9166670.2916670.0291670.0029170.000292
σn\frac{\sigma}{\sqrt{n}}1.70780.54010.17080.0540.0171

Four times the rolls halve the standard error, and a hundred times divide it by 10. The variance falls like 1n\frac{1}{n}; the standard error only like 1n\frac{1}{\sqrt{n}}.

Lesson 5.6.3 met this σ2n\frac{\sigma^2}{n} for normals, where the mean of nn draws is exactly N(μ,σ2n)\mathcal{N}\left(\mu, \frac{\sigma^2}{n}\right). The mean and variance hold for any distribution; the shape is lesson 5.7.3's subject. Case study 5.3.5 used the same rule: with σ=1%\sigma = 1\%, the mean of 1,000 daily returns has standard error 1%1000≈0.0316%\frac{1\%}{\sqrt{1000}} \approx 0.0316\%.

Try it

The loop prints the table. Then, for each nn, 2,000 seeded repetitions of nn rolls: each row of the array is one repetition, and .mean(axis=1) averages each row.

The 2,000 sample means centre on 3.5, and their standard deviation is close to σn\frac{\sigma}{\sqrt{n}}: 0.5353, 0.1741 and 0.0537 in this run. The last line is case study 5.3.5's standard error, in percent.

⌘/Ctrl + Enter runs the cell

The law of large numbers

With a spread that shrinks to 0, the sample mean must close in on μ\mu. Chebyshev's inequality (lesson 5.7.1), applied to Xˉn\bar{X}_n with its variance σ2n\frac{\sigma^2}{n}, makes that precise.

Rule: Law of large numbers

P(∣Xˉn−μ∣≥ε)≤σ2n ε2→0 as n→∞\begin{gathered} P\big(|\bar{X}_n - \mu| \ge \varepsilon\big) \le \frac{\sigma^2}{n\,\varepsilon^2} \\[4pt] \to 0 \text{ as } n \to \infty \end{gathered}

For i.i.d. draws with mean μ\mu and finite variance σ2\sigma^2, and any distance ε>0\varepsilon > 0. However small a miss you name, the chance of missing by that much shrinks to 0. The law still holds when the variance is infinite, as long as the mean exists; then the bound is not available.

The bound also says how many draws are enough. For a die and a miss of ε=0.1\varepsilon = 0.1, it is 2.91670.01 n\frac{2.9167}{0.01\,n}: 0.2917 with 1,000 rolls and 0.0292 with 10,000.

The true chance is smaller. In 4,000 seeded repetitions of 1,000 rolls, the share that missed 3.5 by 0.1 or more was 0.0712, against the bound's 0.2917. Chebyshev's inequality must hold for every distribution, so it is cautious.

To push the bound down to δ=0.05\delta = 0.05, solve σ2nε2≤δ\frac{\sigma^2}{n\varepsilon^2} \le \delta: n≥σ2ε2δn \ge \frac{\sigma^2}{\varepsilon^2\delta}, here 5,834 rolls. Lesson 5.7.3 shows that about 1,121 rolls do the same job.

Try it

The first loop prints the bound for ε=0.1\varepsilon = 0.1. Then the share of 4,000 seeded repetitions of 1,000 rolls that missed by at least 0.1.

math.ceil rounds the guaranteed number of rolls up to a whole roll. The next line is σn\frac{\sigma}{\sqrt{n}} and 2σn\frac{2\sigma}{\sqrt{n}} for 5,000 rolls, for the explorer below.

The last line is 2σn\frac{2\sigma}{\sqrt{n}} at 10,000 rolls, and how many times wider Chebyshev's 95% guarantee σ0.05 n\frac{\sigma}{\sqrt{0.05\,n}} is, for the figure.

⌘/Ctrl + Enter runs the cell

One long run

The rule speaks about many repetitions of nn draws. A stronger version, the strong law of large numbers, speaks about one endless run: its running mean settles on μ\mu with probability 1. That is what a single simulation shows.

Choose the die and 5,000 draws. The readout compares the miss with σn≈0.0242\frac{\sigma}{\sqrt{n}} \approx 0.0242.

Press "Draw again" several times: each run wanders differently at first, and most end within 2σn≈0.0483\frac{2\sigma}{\sqrt{n}} \approx 0.0483 of 3.5. Then try the exponential, whose rare long draws make visible jumps.

Explore

Each point is the average of the first k draws. Pick a starting distribution and watch the running mean settle on the true mean as k grows; draw again for a different run.

020040060080010002345
True mean and standard deviation
μ = 3.5, σ = 1.7078
Mean of 1000 draws
3.565, off by 0.065; a typical miss is σ/√n = 0.054

Twenty runs of 10,000 rolls settle on 3.5 inside a band that narrows like 1n\frac{1}{\sqrt{n}}. Chebyshev's guarantee, dashed, is about 2.24 times wider.

Shares settle on probabilities

A share is a mean in disguise. For an event AA, let the indicator II be 1 when AA happens and 0 when not. It has mean p=P(A)p = P(A) and variance p(1−p)p(1 - p) (lesson 5.3.2).

The share of nn independent trials in which AA happens, written p^n\hat{p}_n, is the sample mean of nn indicators. The rules above apply with μ=p\mu = p and σ2=p(1−p)\sigma^2 = p(1 - p).

Rule: A share

E[p^n]=pσp^n=p(1−p)n\begin{gathered} \mathbb{E}[\hat{p}_n] = p \\[4pt] \sigma_{\hat{p}_n} = \sqrt{\frac{p(1 - p)}{n}} \end{gathered}

The share of successes in nn independent trials, each a success with probability pp, settles on pp. Its standard error shrinks like 1n\frac{1}{\sqrt{n}}, and is largest at p=12p = \frac{1}{2}.

This is why the share of sevens in lesson 5.1.1 settled on 16\frac{1}{6}, and how fast. Its standard error is 0.0373 after 100 rolls, 0.00373 after 10,000 and 0.000373 after a million.

That run's shares, 0.19, 0.1652 and 0.1665, missed 16\frac{1}{6} by 0.0233, −0.0015-0.0015 and −0.0002-0.0002. Each miss is less than one standard error: 0.63, 0.39 and 0.45 of one.

Case study 4.7.5 attached a standard error p^(1−p^)/N\sqrt{\hat{p}(1 - \hat{p})/N} to a simulated probability. It is this rule with the unknown pp replaced by its estimate p^\hat{p}: with N=10,000N = 10{,}000 draws and p^=0.0293\hat{p} = 0.0293 it is 0.00169. How often the miss stays within two standard errors is lesson 5.7.3's question.

Try it

The first loop is lesson 5.1.1's sevens: the standard error at each nn, that run's miss, and the miss in standard errors.

The second loop recomputes case study 4.7.5's standard errors from its estimates.

⌘/Ctrl + Enter runs the cell

Simulation as a way to compute rests on this law. Case study 4.7.5 estimated a probability as a share, and case study 5.7.5 estimates an option price as an average.

What the law does not say

Nothing is certain at a fixed nn. Ten rolls can all show 6, with probability (16)10≈1.65×10−8\left(\frac{1}{6}\right)^{10} \approx 1.65 \times 10^{-8}, and then Xˉ10=6\bar{X}_{10} = 6. The law makes large misses unlikely, never impossible.

There is no law of averages. Toss a fair coin nn times. The number of heads minus n2\frac{n}{2} has standard deviation n2\frac{\sqrt{n}}{2}: 5 after 100 tosses, 50 after 10,000, 500 after a million.

That gap grows. Only the share closes in on 12\frac{1}{2}, because dividing by nn beats a gap that grows like n\sqrt{n}.

Nothing pushes the coin back towards even. After ten tails in a row, the next toss is still heads with probability 12\frac{1}{2}, by independence. Expecting otherwise is the gambler's fallacy.

It needs a mean. A Student t with ν=1\nu = 1 degree of freedom has no mean (lesson 5.4.4). Its running mean never settles: rare, enormous draws keep jolting it.

Lesson 5.3.1's coin game with no finite expected value behaves the same.

It needs independence, or something close to it. If every "draw" is a copy of the first, Xˉn=X1\bar{X}_n = X_1 for every nn, and nothing settles. Draws that are positively correlated settle more slowly than σn\frac{\sigma}{\sqrt{n}} says.

Try it

First the chance of ten sixes. Then one seeded run of a million coin tosses: at each nn, heads minus n2\frac{n}{2}, the share of heads, and n2\frac{\sqrt{n}}{2}. In this run the gap grows from 4 to 47 to 460 while the share closes in from 0.54 to 0.5005.

The last line is the running mean of a million seeded t draws with ν=1\nu = 1, after 102,103,…,10610^2, 10^3, \ldots, 10^6 of them. It jumps about without settling.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. The standard error is σn\frac{\sigma}{\sqrt{n}}, not σn\frac{\sigma}{n}. It is the variance that is divided by nn. A hundred times the draws give ten times the accuracy.
  2. There is no law of averages. Past draws do not make up for each other; each new draw is independent of them.
  3. The sum does not settle; the mean does. Heads minus n2\frac{n}{2} grows like n\sqrt{n} while the share closes in.
  4. The law promises nothing for a particular nn. Chebyshev's inequality gives a bound, and only a bound.
  5. No mean, no law. The running mean of t draws with ν=1\nu = 1 never settles.
  6. Copies are not independent draws. Averaging the same number nn times does not shrink its error.

The law of large numbers

0 of 11 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
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

  • For i.i.d. draws with mean μ\mu and variance σ2\sigma^2, the sample mean Xˉn\bar{X}_n has mean μ\mu, variance σ2n\frac{\sigma^2}{n} and standard error σn\frac{\sigma}{\sqrt{n}}.
  • Law of large numbers: P(∣Xˉn−μ∣≥ε)→0P(|\bar{X}_n - \mu| \ge \varepsilon) \to 0, and with a finite variance it is at most σ2nε2\frac{\sigma^2}{n\varepsilon^2} (Chebyshev). One long run settles on μ\mu too.
  • A share p^n\hat{p}_n is a mean of indicators. It settles on pp with standard error p(1−p)/n\sqrt{p(1 - p)/n}, estimated as p^(1−p^)/n\sqrt{\hat{p}(1 - \hat{p})/n} in a simulation.
  • The law gives no certainty at a fixed nn and no law of averages: the count's gap grows like n\sqrt{n}. It needs a mean, and independence.

Free further reading

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