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

Resampling, Aggregation, and Time Alignment

Install and import#

bash
npm install fintech-algorithms
ts
import { resamplingAggregationAndTimeAlignment } from "fintech-algorithms/foundations/financial-time-series-foundations/resampling-aggregation-and-time-alignment";

Signature#

resamplingAggregationAndTimeAlignment(input)

Cuts the series into consecutive fixed-size buckets and averages each one, coarsening the sampling frequency.

Parameters#

NameTypeNotes
inputD00InputReads values, a non-empty list of finite numbers, timestamps of the same length, and resampleSize, the number of observations per bucket.

Returns#

D00Output

aggregatedMeans holds one mean per bucket and bucketSizes their lengths, the last of which is short when the series does not divide evenly. alignment is the fixed label left-closed sequential buckets.

Errors#

  • When values is absent, empty, or holds a non-finite number — throws RangeError
  • When timestamps and values have different lengths — throws RangeError
  • When the series holds fewer than two observations — throws RangeError
  • When resampleSize is not a positive integer — throws RangeError

Complexity: time O(n^2), space O(n).

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#

resamplingAggregationAndTimeAlignment(input)

Returns#

object with 2 fields: aggregatedMeans, bucketSizes

{
  "aggregatedMeans": [101, 102.5, 105.5],
  "bucketSizes": [2, 2, 2]
}

Diagrams#

Resampling, Aggregation, and Time Alignment — article hero
Resampling, Aggregation, and Time Alignment — calculation ledger
Resampling, Aggregation, and Time Alignment — concept anatomy
Resampling, Aggregation, and Time Alignment — failure boundary
Resampling, Aggregation, and Time Alignment — method map
Resampling, Aggregation, and Time Alignment — scenario contrast

Calculation flow#

Reasoning flow — D00-F10-A05
flowchart LR
    A["Synthetic input + metadata"] --> B{"Contract valid?"}
    B -->|No| C["Reject or route with reason"]
    B -->|Yes| D["Apply Resampling, Aggregation, and Time Alignment"]
    D --> E["Formula: bucket statistic=aggregate{xₜ:t in declared interval}"]
    E --> F["Verified fixture output"]
    F --> G{"Interpretation within boundary?"}
    G -->|Yes| H["Report value + convention + audit"]
    G -->|No| I["Add companion view or narrower claim"]

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#