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

Downside Deviation and Target Shortfall

Measuring shortfall below a required return.

2:35 clip5:30:44–5:33:19 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Does this convention divide by two shortfall periods or all four periods?

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.

102-downside-deviation-and-target-shortfall.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 102 of 120
 * Downside Deviation and Target Shortfall
 * Module 11: Financial Risk and Performance Statistics
 *
 * Scenario: Measuring shortfall below a required return
 * Rule:     downside deviation = √mean(min(0,r−target)²)
 *
 * Try it:   Does this convention divide by two shortfall periods or all four periods?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-risk-and-performance-statistics/downside-deviation-and-target-shortfall/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson102() {
  const returns=[-.02,.01,-.01,.03],target=0;
  const shortfalls=returns.map(r=>Math.min(0,r-target));
  const result={shortfalls,
    downside:Math.sqrt(shortfalls.reduce((s,x)=>s+x*x,0)/returns.length),
    meanShortfall:-shortfalls.reduce((s,x)=>s+x,0)/returns.length};
  return result;
}

export const checkedResult = {"shortfalls":[-0.02,0,-0.01,0],"downside":0.011180339887498949,"meanShortfall":0.0075};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "shortfalls": [
    -0.02,
    0,
    -0.01,
    0
  ],
  "downside": 0.011180339887498949,
  "meanShortfall": 0.0075
}

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

Lesson notes

The rule

downside deviation = √mean(min(0,r−target)²)