Smoothing, Baselines, and Naive Forecasts
Install and import#
npm install fintech-algorithmsimport { smoothingBaselinesAndNaiveForecasts } from "fintech-algorithms/foundations/financial-time-series-foundations/smoothing-baselines-and-naive-forecasts";Signature#
smoothingBaselinesAndNaiveForecasts(input)Runs simple exponential smoothing over the series and reports both the naive last-value forecast and the smoothed one.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | Reads values, a non-empty list of finite numbers, timestamps of the same length, and alpha, the weight placed on the newest observation. |
Returns#
D00Output
smoothed is the same length as the input and starts at its first value. naiveNext is the last observed level and smoothedNext the last smoothed one.
Errors#
- When
valuesis absent, empty, or holds a non-finite number — throws RangeError - When
timestampsandvalueshave different lengths — throws RangeError - When the series holds fewer than two observations — throws RangeError
- When
alphais outside the closed interval from zero to one — 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#
{
"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#
smoothingBaselinesAndNaiveForecasts(input)Returns#
object with 2 fields: smoothed, naiveNext
{
"smoothed": [
100,
100.80000000000001,
100.88000000000001,
102.12800000000001,
103.67680000000001,
104.20608000000001
],
"naiveNext": 105
}Diagrams#
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.
References#
- Time Series Plot — NIST/SEMATECH e-Handbook
- Common Pitfalls and Recommended Practices — scikit-learn
- Historical-example decision