fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Rolling and Expanding Windows

Install and import#

bash
npm install fintech-algorithms
ts
import { rollingAndExpandingWindows } from "fintech-algorithms/financial-mathematics-statistics-and-data-foundations/financial-time-series-foundations/rolling-and-expanding-windows";

Signature#

rollingAndExpandingWindows(input)

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

input
{
  "timestamps": [
    "2025-01-01T00:00:00Z",
    "2025-01-02T00:00:00Z",
    "2025-01-03T00:00:00Z",
    "2025-01-04T00:00:00Z",
    "2025-01-05T00:00:00Z",
    "2025-01-06T00:00:00Z"
  ],
  "values": [100, 102, 101, 104, 106, 105],
  "lag": 1,
  "window": 3,
  "resampleSize": 2,
  "period": 3,
  "stationarityTolerance": 3,
  "alpha": 0.4,
  "splitIndex": 4
}

Call#

rollingAndExpandingWindows(input)

Returns#

object with 2 fields: rollingMean, expandingMean

{
  "rollingMean": [null, null, 101, 102.33333333333333, 103.66666666666667, 105],
  "expandingMean": [100, 101, 101, 101.75, 102.6, 103]
}

Diagrams#

Rolling and Expanding Windows — article hero
Rolling and Expanding Windows — calculation ledger
Rolling and Expanding Windows — concept anatomy
Rolling and Expanding Windows — failure boundary
Rolling and Expanding Windows — method map
Rolling and Expanding Windows — scenario contrast

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Financial Time-Series Foundations family#