Augmented Dickey-Fuller
Install and import#
npm install fintech-algorithmsimport { adf } from "fintech-algorithms/statistical-time-series/diagnostics/augmented-dickey-fuller";Signature#
adf(values, lags, criticalValue)Tests for a unit root. The null is that the series *has* one — so failing to reject is not evidence of stationarity, merely absence of evidence against a unit root. That asymmetry is the most misread thing in applied time series.
Parameters#
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series in chronological order, oldest first. |
lags | number | Number of lagged differences included to absorb serial correlation. min: 0 · integer: true |
criticalValue | number | Critical value to compare the statistic against, at the chosen significance level. |
Returns#
{ method, variant, nobs, lags, gamma, gamma_standard_error, statistic, decision, … }
The statistic, the coefficient and its standard error, and an explicit decision — so the conclusion is separable from the arithmetic.
Errors#
- When the sample is too short for the requested lag order — throws
Complexity: time O(n × lags²),
space O(n).
Worked example#
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input#
[0.49366418, 1.54242291, -0.82556495, 0.47513288, 0.50704417, -0.3816439]Showing 6 of 96 elements.
1-2.86Call#
adf(values, lags, criticalValue)Returns#
object with 15 fields: method, variant, nobs, regression_nobs, lags, gamma, gamma_standard_error, statistic, …
{
"method": "adf",
"variant": "constant-only-fixed-lag",
"nobs": 96,
"regression_nobs": 94,
"lags": 1,
"gamma": -0.3307327402574888,
"gamma_standard_error": 0.08555486242368153,
"statistic": -3.8657386721007945,
"critical_value": -2.86,
"reject_null": true,
"state": "reject-unit-root",
"reason": "statistic-below-boundary",
"coefficients": [0.09192051133561, -0.3307327402574888, -0.0052913498392460345],
"residual_sse": 84.25503279621253
}Showing 14 of 15 fields.
Other exports#
This module also exports
acf, pacf, kpss, ljungBox, zivotAndrews, runDiagnostic. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams#
Calculation flow#
Augmented Dickey-Fuller decision flow
flowchart TD
A["Ordered finite series"] --> B{"Contract valid?"}
B -- "No" --> X["Stop: explicit invalid state"]
B -- "Yes" --> C["Difference after warm-up"]
C --> D["Build fixed-lag constant-only OLS rows"]
D --> E["Compute gamma t-ratio"]
E --> F["Compare with nonstandard boundary"]
F --> G{"Declared strict decision rule"}
G --> H["Report machine state, null, and limitation"]
H --> I["Compare with KPSS"]
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#
- statsmodels.tsa.stattools.adfuller
- Distribution of the Estimators for Autoregressive Time Series with a Unit Root
- Evidence decisions