Module 7 · Probability Distributions and Simulation Basics Lesson 61 of 120

PMF, PDF, CDF, Survival, and Quantile Functions

Turning a loss model into probabilities and thresholds.

2:38 clip3:16:59–3:19:38 in the full courseWatch on YouTube

Transcript

20 sentences · select one to jump there

Check your understanding

Can a PDF have height two without violating probability rules?

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.

061-pmf-pdf-cdf-survival-and-quantile-functions.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 061 of 120
 * PMF, PDF, CDF, Survival, and Quantile Functions
 * Module 07: Probability Distributions and Simulation Basics
 *
 * Scenario: Turning a loss model into probabilities and thresholds
 * Rule:     F(x)=P(X≤x); S(x)=1−F(x); Q(p)=inf{x:F(x)≥p}
 *
 * Try it:   Can a PDF have height two without violating probability rules?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-distributions-and-simulation-basics/pmf-pdf-cdf-survival-and-quantile-functions/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson061() {
  const values=[0,1,2], p=[.2,.5,.3];
  const cdf=(x:number)=>values.reduce((s,v,i)=>s+(v<=x?p[i]:0),0);
  const quantile=(u:number)=>values.find(v=>cdf(v)>=u)!;
  const result={pmfAt1:p[1],cdfAt1:cdf(1),survivalAt1:1-cdf(1),q80:quantile(.8)};
  return result;
}

export const checkedResult = {"pmfAt1":0.5,"cdfAt1":0.7,"survivalAt1":0.30000000000000004,"q80":2};

// Run this file directly: npx tsx lessons/07-probability-distributions-and-simulation-basics/061-pmf-pdf-cdf-survival-and-quantile-functions.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson061(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "pmfAt1": 0.5,
  "cdfAt1": 0.7,
  "survivalAt1": 0.30000000000000004,
  "q80": 2
}

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

Lesson notes

The rule

F(x)=P(X≤x); S(x)=1−F(x); Q(p)=inf{x:F(x)≥p}