Module 11 · Financial Risk and Performance Statistics Lesson 104 of 120

Loss Distributions and Loss Quantiles

Building the loss tail with an explicit sign convention.

2:31 clip5:35:50–5:38:22 in the full courseWatch on YouTube

Transcript

16 sentences · select one to jump there

Check your understanding

Which side is the loss tail when loss equals minus return?

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.

104-loss-distributions-and-loss-quantiles.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 104 of 120
 * Loss Distributions and Loss Quantiles
 * Module 11: Financial Risk and Performance Statistics
 *
 * Scenario: Building the loss tail with an explicit sign convention
 * Rule:     loss = −return; loss quantile uses a declared rule
 *
 * Try it:   Which side is the loss tail when loss equals minus return?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-risk-and-performance-statistics/loss-distributions-and-loss-quantiles/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson104() {
  const returns=[.03,.015,.01,-.01,-.02];
  const losses=returns.map(r=>-r).sort((a,b)=>a-b);
  const p=.8,h=(losses.length-1)*p,i=Math.floor(h);
  const q=losses[i]+(h-i)*(losses[i+1]-losses[i]);
  const result={losses,q80:q};
  return result;
}

export const checkedResult = {"losses":[-0.03,-0.015,-0.01,0.01,0.02],"q80":0.012000000000000002};

// Run this file directly: npx tsx lessons/11-financial-risk-and-performance-statistics/104-loss-distributions-and-loss-quantiles.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson104(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "losses": [
    -0.03,
    -0.015,
    -0.01,
    0.01,
    0.02
  ],
  "q80": 0.012000000000000002
}

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

Lesson notes

The rule

loss = −return; loss quantile uses a declared rule