Module 5 · Dispersion, Shape, and Robust Statistics Lesson 47 of 120

Coefficient of Variation and Scale Comparability

Comparing relative spread across positive-scale services.

2:35 clip2:27:37–2:30:13 in the full courseWatch on YouTube

Transcript

18 sentences · select one to jump there

Check your understanding

Does adding the same constant to every observation preserve CV?

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.

047-coefficient-of-variation-and-scale-comparability.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 047 of 120
 * Coefficient of Variation and Scale Comparability
 * Module 05: Dispersion, Shape, and Robust Statistics
 *
 * Scenario: Comparing relative spread across positive-scale services
 * Rule:     CV = standard deviation / mean
 *
 * Try it:   Does adding the same constant to every observation preserve CV?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/dispersion-shape-and-robust-statistics/coefficient-of-variation-and-scale-comparability/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson047() {
  const mean: number = 3.6, sampleSD = Math.sqrt(10.3);
  if (mean === 0) throw new Error("CV undefined at zero mean");
  const cv = sampleSD / Math.abs(mean);
  const result = {cv, percent: 100*cv};
  return result;
}

export const checkedResult = {"cv":0.8914892519934007,"percent":89.14892519934007};

// Run this file directly: npx tsx lessons/05-dispersion-shape-and-robust-statistics/047-coefficient-of-variation-and-scale-comparability.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson047(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "cv": 0.8914892519934007,
  "percent": 89.14892519934007
}

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

Lesson notes

The rule

CV = standard deviation / mean