Module 8 · Sampling, Estimation, and Statistical Inference Lesson 74 of 120

Law of Large Numbers

Why more observations can stabilize a rate without a monotone path.

2:44 clip3:57:20–4:00:04 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Must the running average get closer to the true mean at every step?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

074-law-of-large-numbers.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 074 of 120
 * Law of Large Numbers
 * Module 08: Sampling, Estimation, and Statistical Inference
 *
 * Scenario: Why more observations can stabilize a rate without a monotone path
 * Rule:     sample average approaches expectation under suitable assumptions
 *
 * Try it:   Must the running average get closer to the true mean at every step?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/sampling-estimation-and-statistical-inference/law-of-large-numbers/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson074() {
  const outcomes=[1,0,0,1,0,0,0,1];
  let total=0;
  const averages=outcomes.map((x,i)=>{total+=x; return total/(i+1);});
  const result={averages,last:averages.at(-1)!};
  return result;
}

export const checkedResult = {"averages":[1,0.5,0.3333333333333333,0.5,0.4,0.3333333333333333,0.2857142857142857,0.375],"last":0.375};

// Run this file directly: npx tsx lessons/08-sampling-estimation-and-statistical-inference/074-law-of-large-numbers.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson074(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "averages": [
    1,
    0.5,
    0.3333333333333333,
    0.5,
    0.4,
    0.3333333333333333,
    0.2857142857142857,
    0.375
  ],
  "last": 0.375
}

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

sample average approaches expectation under suitable assumptions