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

Decomposition and Cycles

6 algorithms in Statistical Time Series.

In this family#

  1. STL Decomposition contract

    Seasonal-trend decomposition by loess: splits a series into seasonal, trend and remainder. Unlike a fixed seasonal index it lets the seasonal shape evolve, which is why it survives series where the pattern drifts.

    stlDecompose(values, period, seasonalWindow, trendWindow, robustIterations)
  2. Hodrick-Prescott Filter contract

    Separates trend from cycle by penalising trend curvature. Ubiquitous in macro and heavily criticised: it produces spurious cycles at the ends of the sample, so the most recent values — the ones you care about — are the least reliable.

    hpFilter(values, smoothing)
  3. Baxter-King Filter contract

    A band-pass filter isolating fluctuations between two periodicities. Being a symmetric moving average it consumes K observations at **each** end, so the filtered series is shorter than the input at both.

    bkFilter(values, low, high, K)
  4. Christiano-Fitzgerald Filter contract

    An asymmetric band-pass filter that uses the whole sample, so unlike Baxter-King it produces values at the ends. The trade is that the filter weights differ at each observation, which makes it non-stationary by construction.

    cfFilter(values, low, high, drift)
  5. Fast Fourier Transform Periodogram contract

    Estimates spectral power by frequency. Peaks suggest periodicity — but a trend leaks power across every frequency, which is why detrending is a parameter here rather than an afterthought.

    fftPeriodogram(values, sampleFrequency, detrend, window)
  6. Wavelet Decomposition contract

    Haar wavelet decomposition: splits the series into detail at successive scales plus a residual approximation. Unlike Fourier it localises in *time* as well as frequency, so it can say when a frequency was present.

    haarWavelet(values, levels)

What they share#

Every topic here is a record-transform, so once you have called one the rest follow the same shape. Import paths differ only in the final segment:

ts
import { stlDecompose } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/stl-decomposition";
import { hpFilter } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/hodrick-prescott-filter";

Read them in the order above — the sequence is pedagogical, not alphabetical.

Where this sits#

Statistical Time Series collects 29 algorithms across 5 families. For the concept behind this family rather than the call signatures, see the concept guides.