Augmented Dickey-Fuller (ADF)
Calculate the Augmented Dickey-Fuller (ADF) test for a unit root, per asset.
The test regresses the first difference of the series on its own lagged level and p lags of its own first difference. The null hypothesis is that the series has a unit root (is a random walk, not mean-reverting); the alternative is that it is stationary. This is a standard first step before modeling a price series or spread with mean-reverting methods, since those methods assume stationarity.
The formula is as follows:
\[\Delta \text{Yₜ} = \alpha + \text{γ} \cdot \text{Yₜ₋₁} + \operatorname{Σ}(i = 1..p) \text{δᵢ} \cdot \Delta \text{Yₜ₋ᵢ} + \text{epsilonₜ},\;\; \text{with Yₜ the column level (Adj Close by default) and regression="c" (the default); "ct" adds a trend beta*t and "n" drops alpha}\] \[\text{ADF} = \text{γ̂} / \operatorname{SE}(\text{γ̂}),\;\; \text{compared with MacKinnon (1994, 2010) critical values and p-values}\] \[p = \text{the number of lags that minimises the AIC},\;\; \text{searched from 0 up to max\_lag},\;\; \text{which defaults to min} (\operatorname{ceil}(12 \cdot (n / 100) ^{1 / 4}),\; (n - 5) / / 3)\]For more information about the method, see the following paper:
- Dickey, D.A. and Fuller, W.A. (1979). “Distribution of the Estimators for Autoregressive Time Series with a Unit Root.” Journal of the American Statistical Association, 74(366a), 427-431.
Also known as: ADF test, unit root test, stationarity test.
Augmented Dickey-Fuller (ADF) in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_augmented_dickey_fuller as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["EURUSD", "USDJPY", "GBPUSD"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.econometrics.get_augmented_dickey_fuller()
Or, after setting up the Finance Toolkit MCP, ask:
Were the euro against the dollar, the dollar against the yen and the pound against the dollar stationary from 2021 to 2025, according to the augmented Dickey-Fuller test?
Which returns:
| EURUSD | USDJPY | GBPUSD | |
|---|---|---|---|
| ADF Statistic | -1.83568 | -1.68762 | -1.81162 |
| P-Value | 0.362896 | 0.4375 | 0.374708 |
| Lags Used | 5 | 0 | 2 |
| Observations | 1345 | 1351 | 1349 |
| Critical Value 1% | -3.43522 | -3.4352 | -3.43521 |
| Critical Value 5% | -2.86369 | -2.86368 | -2.86368 |
| Critical Value 10% | -2.56792 | -2.56791 | -2.56791 |
| Reject Unit Root (5%) | 0 | 0 | 0 |
Using Your Own Data
get_augmented_dickey_fuller runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_augmented_dickey_fuller()
Parameters
get_augmented_dickey_fuller accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to test. Defaults to “Adj Close”. | "Return" |
max_lag | int | The maximum number of lagged differences to consider. Defaults to the Schwert (1989) rule of thumb, capped at (n - 5) // 3 for short samples. | 12 |
regression | str | Which deterministic terms to include, one of “n” (none), “c” (constant) or “ct” (constant and trend). Defaults to “c”. | "ct" |
include_benchmark | bool | Whether to include “Benchmark” among the assets tested. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |