Module 2 · Financial Arithmetic, Time Value, and Returns Lesson 17 of 120

Log Return

Adding changes in log space without confusing wealth.

2:49 clip52:56–55:45 in the full courseWatch on YouTube

Transcript

21 sentences · select one to jump there

Check your understanding

How do you convert total log return back to simple 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.

017-log-return.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 017 of 120
 * Log Return
 * Module 02: Financial Arithmetic, Time Value, and Returns
 *
 * Scenario: Adding changes in log space without confusing wealth
 * Rule:     r = ln(P₁/P₀)
 *
 * Try it:   How do you convert total log return back to simple return?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-arithmetic-time-value-and-returns/log-return/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson017() {
  const prices = [100, 110, 99];
  if (!prices.every(p => Number.isFinite(p) && p > 0))
    throw new Error("Positive prices required");
  const logs = prices.slice(1).map((p, i) =>
    Math.log(p / prices[i]));
  const totalLog = logs.reduce((a, x) => a + x, 0);
  const result = {totalLog, simple: Math.expm1(totalLog)};
  return result;
}

export const checkedResult = {"totalLog":-0.010050335853501347,"simple":-0.009999999999999907};

// Run this file directly: npx tsx lessons/02-financial-arithmetic-time-value-and-returns/017-log-return.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson017(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "totalLog": -0.010050335853501347,
  "simple": -0.009999999999999907
}

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

Lesson notes

The rule

r = ln(P₁/P₀)