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

Stationarity and Differencing Intuition

Removing a changing level without declaring stationarity solved.

2:39 clip5:13:58–5:16:38 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Does a smaller range after differencing prove stationarity?

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.

098-stationarity-and-differencing-intuition.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 098 of 120
 * Stationarity and Differencing Intuition
 * Module 10: Financial Time-Series Foundations
 *
 * Scenario: Removing a changing level without declaring stationarity solved
 * Rule:     first difference Δxₜ=xₜ−xₜ₋₁
 *
 * Try it:   Does a smaller range after differencing prove stationarity?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-time-series-foundations/stationarity-and-differencing-intuition/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson098() {
  const levels=[100,101,100,102,104];
  const differences=levels.slice(1).map((v,i)=>v-levels[i]);
  const result={differences,levelRange:Math.max(...levels)-Math.min(...levels),
    differenceRange:Math.max(...differences)-Math.min(...differences)};
  return result;
}

export const checkedResult = {"differences":[1,-1,2,2],"levelRange":4,"differenceRange":3};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "differences": [
    1,
    -1,
    2,
    2
  ],
  "levelRange": 4,
  "differenceRange": 3
}

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

Lesson notes

The rule

first difference Δxₜ=xₜ−xₜ₋₁