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

Trend, Seasonality, Cycles, and Remainder

Separating a growing business from a repeating weekly pattern.

2:38 clip5:08:51–5:11:29 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Does the code estimate unknown trend and seasonality from real data?

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.

096-trend-seasonality-cycles-and-remainder.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 096 of 120
 * Trend, Seasonality, Cycles, and Remainder
 * Module 10: Financial Time-Series Foundations
 *
 * Scenario: Separating a growing business from a repeating weekly pattern
 * Rule:     additive illustration: observed = trend + seasonal + remainder
 *
 * Try it:   Does the code estimate unknown trend and seasonality from real data?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/financial-time-series-foundations/trend-seasonality-cycles-and-remainder/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson096() {
  const trend=[10,11,12,13,14,15];
  const seasonal=[2,-2,2,-2,2,-2];
  const remainder=[0,0,0,0,0,0];
  const observed=trend.map((v,i)=>v+seasonal[i]+remainder[i]);
  const result={observed,recoveredTrend:observed.map((v,i)=>v-seasonal[i])};
  return result;
}

export const checkedResult = {"observed":[12,9,14,11,16,13],"recoveredTrend":[10,11,12,13,14,15]};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "observed": [
    12,
    9,
    14,
    11,
    16,
    13
  ],
  "recoveredTrend": [
    10,
    11,
    12,
    13,
    14,
    15
  ]
}

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

Lesson notes

The rule

additive illustration: observed = trend + seasonal + remainder