Module 10 · Financial Time-Series Foundations Lesson 92 of 120

Levels, Changes, Differences, and Returns

Separating account levels, cash changes, and relative returns.

2:35 clip4:58:52–5:01:28 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Can a deposit-driven balance increase be treated automatically as investment 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.

092-levels-changes-differences-and-returns.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 092 of 120
 * Levels, Changes, Differences, and Returns
 * Module 10: Financial Time-Series Foundations
 *
 * Scenario: Separating account levels, cash changes, and relative returns
 * Rule:     difference=xₜ−xₜ₋₁; simple return=xₜ/xₜ₋₁−1
 *
 * Try it:   Can a deposit-driven balance increase be treated automatically as investment return?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-time-series-foundations/levels-changes-differences-and-returns/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson092() {
  const levels=[100,110,99];
  const differences=levels.slice(1).map((v,i)=>v-levels[i]);
  const simple=levels.slice(1).map((v,i)=>v/levels[i]-1);
  const log=levels.slice(1).map((v,i)=>Math.log(v/levels[i]));
  const result={differences,simple,log};
  return result;
}

export const checkedResult = {"differences":[10,-11],"simple":[0.10000000000000009,-0.09999999999999998],"log":[0.09531017980432493,-0.10536051565782628]};

// Run this file directly: npx tsx lessons/10-financial-time-series-foundations/092-levels-changes-differences-and-returns.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson092(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "differences": [
    10,
    -11
  ],
  "simple": [
    0.10000000000000009,
    -0.09999999999999998
  ],
  "log": [
    0.09531017980432493,
    -0.10536051565782628
  ]
}

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

Lesson notes

The rule

difference=xₜ−xₜ₋₁; simple return=xₜ/xₜ₋₁−1