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

Drawdown and Maximum Drawdown

Tracking loss from a running wealth peak.

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

Transcript

20 sentences · select one to jump there

Check your understanding

Is wealth 92.4 back at its earlier peak of 110?

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.

103-drawdown-and-maximum-drawdown.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 103 of 120
 * Drawdown and Maximum Drawdown
 * Module 11: Financial Risk and Performance Statistics
 *
 * Scenario: Tracking loss from a running wealth peak
 * Rule:     drawdownₜ=wealthₜ/runningPeakₜ−1
 *
 * Try it:   Is wealth 92.4 back at its earlier peak of 110?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-risk-and-performance-statistics/drawdown-and-maximum-drawdown/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson103() {
  const returns=[.10,-.20,.05];
  let wealth=100,peak=100;
  const values=[wealth],drawdowns=[0];
  for(const r of returns){wealth*=1+r;peak=Math.max(peak,wealth);
    values.push(wealth);drawdowns.push(wealth/peak-1);}
  const result={values,drawdowns,maxDrawdown:Math.min(...drawdowns)};
  return result;
}

export const checkedResult = {"values":[100,110.00000000000001,88.00000000000001,92.40000000000002],"drawdowns":[0,0,-0.19999999999999996,-0.15999999999999992],"maxDrawdown":-0.19999999999999996};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "values": [
    100,
    110.00000000000001,
    88.00000000000001,
    92.40000000000002
  ],
  "drawdowns": [
    0,
    0,
    -0.19999999999999996,
    -0.15999999999999992
  ],
  "maxDrawdown": -0.19999999999999996
}

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

Lesson notes

The rule

drawdownₜ=wealthₜ/runningPeakₜ−1