Module 6 · Probability and Random Variables Lesson 57 of 120

Expected Value

Budgeting expected insurance loss without promising the average.

2:35 clip3:00:10–3:02:45 in the full courseWatch on YouTube

Transcript

20 sentences · select one to jump there

Check your understanding

Does E[X+Y]=E[X]+E[Y] require independence?

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.

057-expected-value.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 057 of 120
 * Expected Value
 * Module 06: Probability and Random Variables
 *
 * Scenario: Budgeting expected insurance loss without promising the average
 * Rule:     E[X] = Σpᵢxᵢ
 *
 * Try it:   Does E[X+Y]=E[X]+E[Y] require independence?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/expected-value/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson057() {
  const losses=[0,100,500], p=[.90,.08,.02];
  const contributions=losses.map((x,i)=>x*p[i]);
  const result={contributions, expected:contributions.reduce((a,b)=>a+b,0)};
  return result;
}

export const checkedResult = {"contributions":[0,8,10],"expected":18};

// Run this file directly: npx tsx lessons/06-probability-and-random-variables/057-expected-value.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson057(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "contributions": [
    0,
    8,
    10
  ],
  "expected": 18
}

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

Lesson notes

The rule

E[X] = Σpᵢxᵢ