Module 6 · Probability and Random Variables Lesson 56 of 120

Discrete and Continuous Random Variables

Distinguishing uncertain counts from uncertain amounts.

2:36 clip2:57:33–3:00:10 in the full courseWatch on YouTube

Transcript

17 sentences · select one to jump there

Check your understanding

Must an expected value be one of the possible individual outcomes?

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.

056-discrete-and-continuous-random-variables.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 056 of 120
 * Discrete and Continuous Random Variables
 * Module 06: Probability and Random Variables
 *
 * Scenario: Distinguishing uncertain counts from uncertain amounts
 * Rule:     a random variable maps outcomes to numbers
 *
 * Try it:   Must an expected value be one of the possible individual outcomes?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/discrete-and-continuous-random-variables/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson056() {
  const losses=[0,100,500], probabilities=[.90,.08,.02];
  const result = {positiveLossProbability: probabilities[1]+probabilities[2],
    expectedLoss: losses.reduce((s,l,i)=>s+l*probabilities[i],0)};
  return result;
}

export const checkedResult = {"positiveLossProbability":0.1,"expectedLoss":18};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "positiveLossProbability": 0.1,
  "expectedLoss": 18
}

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

Lesson notes

The rule

a random variable maps outcomes to numbers