Module 4 · Location, Ranking, and Exploratory Summaries Lesson 33 of 120

Weighted Mean

Pooling merchant approval rates by exposure.

2:32 clip1:45:30–1:48:02 in the full courseWatch on YouTube

Transcript

22 sentences · select one to jump there

Check your understanding

Which figure describes all 1,000 attempts combined?

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.

033-weighted-mean.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 033 of 120
 * Weighted Mean
 * Module 04: Location, Ranking, and Exploratory Summaries
 *
 * Scenario: Pooling merchant approval rates by exposure
 * Rule:     weighted mean = Σ(wᵢxᵢ)/Σwᵢ
 *
 * Try it:   Which figure describes all 1,000 attempts combined?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/location-ranking-and-exploratory-summaries/weighted-mean/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson033() {
  const rates = [0.90, 0.50];
  const attempts = [100, 900];
  const weighted = rates.reduce((s,r,i) => s+r*attempts[i],0)
    / attempts.reduce((s,n) => s+n,0);
  const result = {unweighted: (rates[0]+rates[1])/2, weighted};
  return result;
}

export const checkedResult = {"unweighted":0.7,"weighted":0.54};

// Run this file directly: npx tsx lessons/04-location-ranking-and-exploratory-summaries/033-weighted-mean.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson033(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "unweighted": 0.7,
  "weighted": 0.54
}

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

Lesson notes

The rule

weighted mean = Σ(wᵢxᵢ)/Σwᵢ