DF-GLS Test
The DF-GLS Test of Elliott, Rothenberg and Stock (1996) is the Augmented Dickey-Fuller Test on a series whose constant and trend were removed by generalised least squares (GLS) instead of OLS. The ordinary tests have little power against a stationary series that is close to a unit root, such as a slowly reverting spread or rate. Elliott, Rothenberg and Stock showed that estimating the constant and trend on quasi-differences, at a nearby stationary alternative, raises that power close to the best attainable.
The formula for the DF-GLS Test starts from the quasi-differences of the series at the local alternative bar(alpha), with bar(c) = -7 with a constant and -13.5 with a constant and trend:
\[\bar{\alpha} = 1 + \frac{\bar{c}}{T}\] \[y_{\alpha,1} = y_{1}\] \[y_{\alpha,t} = y_{t} - \bar{\alpha} \cdot y_{t-1}\]The deterministic terms \(z_{t}\) (1, or 1 and t with a trend) are quasi-differenced alike into \(Z_{\alpha}\), the OLS regression of the quasi-differenced series \(Y_{\alpha}\) on them estimates their coefficients, and the detrended series is the series minus these terms:
\[\hat{\delta} = (Z'_{\alpha} \cdot Z_{\alpha})^{-1} \cdot Z'_{\alpha} \cdot Y_{\alpha}\] \[y_{d,t} = y_{t} - z'_{t} \cdot \hat{\delta}\]The statistic is the t-statistic of the ADF regression without deterministic terms on the detrended series:
\[\Delta y_{d,t} = \gamma \cdot y_{d,t-1} + \sum_{i=1}^{p} \delta_{i} \cdot \Delta y_{d,t-i} + \epsilon_{t}\] \[\text{DF GLS} = \frac{\hat{\gamma}}{\text{SE}(\hat{\gamma})}\]Where \(y_{t}\) is the level of the series, T the number of observations, \(\delta_{i}\) the coefficients of the p lagged changes, chosen by the AIC as in the Augmented Dickey-Fuller Test, \(\epsilon_{t}\) the error and SE the standard error. The unit root is rejected when the statistic lies below the critical value, or its p-value below the significance level (0.05 for the 5% level). With a constant the p-value and critical values are those of MacKinnon (1994, 2010) for the Dickey-Fuller test without deterministic terms; with a trend the critical values come from Elliott, Rothenberg and Stock (1996), Table I, and there is no p-value. Its power gain is largest for a series that is only just stationary; like the Augmented Dickey-Fuller Test it rejects too often when the errors have a large negative moving-average term.
A unit root test asks whether a series wanders like a random walk, where every shock moves its level for good, or is stationary and returns to its mean or trend after a shock. The tests share the same null hypothesis, a unit root (a random walk, not mean-reverting), against the alternative that the series is stationary. Testing for it is a standard first step before modelling a price, spread or rate with mean-reverting methods, which assume stationarity, and before regressing one trending series on another, where a unit root in both makes the regression spurious. The tests differ in how they handle autocorrelated errors, structural breaks and the constant and trend, and in their power against a series that reverts only slowly. Not rejecting the unit root does not prove it: on a short sample a slowly reverting series and a random walk are hard to tell apart. The KPSS test swaps the null and the alternative and is the usual complement.
Also known as: DFGLS, ERS DF-GLS test, GLS-detrended Dickey-Fuller test.
In the Finance Toolkit this is get_unit_root_test with method="dickey_fuller_gls", the same function as Unit Root Test.
Example · EURUSD, USDJPY, GBPUSD · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_unit_root_test:
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_unit_root_test(method="dickey_fuller_gls")
| 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" |
method | str | The test. Options are: “augmented_dickey_fuller” (Augmented Dickey-Fuller Test), “phillips_perron” (Phillips-Perron Test), “zivot_andrews” (Zivot-Andrews Test, with a structural break), “dickey_fuller_gls” (DF-GLS Test), “ers_point_optimal” (ERS Point Optimal Test), “ng_perron” (Ng-Perron Test, four statistics). Defaults to “augmented_dickey_fuller”. | "augmented_dickey_fuller" |
regression | str | Which deterministic terms to include. For “augmented_dickey_fuller” one of “n” (none), “c” (constant) or “ct” (constant and trend); for “phillips_perron”, “dickey_fuller_gls”, “ers_point_optimal” and “ng_perron” one of “c” or “ct” (“n” is not supported, see econometrics.unitroot_model.get_phillips_perron_test for why); for “zivot_andrews” which break to allow for, one of “c” (a break in the level/intercept), “t” (a break in the trend slope) or “ct” (both). Defaults to “c”. | "ct" |
max_lag | int | The maximum number of lagged differences to consider in the AIC lag search of “augmented_dickey_fuller”, “zivot_andrews” (which selects a single lag length and reuses it for every break date), “dickey_fuller_gls” and “ers_point_optimal”, and in the modified AIC search of “ng_perron”. Not used with “phillips_perron”. Defaults to the Schwert (1989) rule of thumb, capped at (n - 5) // 3 for short samples. | 12 |
lags | int | The truncation lag for the Newey-West long-run variance estimate of “phillips_perron”, or a fixed number of lagged differences instead of the AIC search for “dickey_fuller_gls” and “ers_point_optimal”; not used by the other methods. Defaults to None, meaning the Schwert (1989) rule ceil(12 * (n / 100) ** 0.25), capped for short samples as the ADF lag search is, for “phillips_perron” and the AIC search for the other two. | 2 |
trim | float | The fraction of observations excluded from the candidate break date search at the start and end of the sample, for “zivot_andrews” only. Must be in [0, 1/3). Defaults to 0.15. | 0.1 |
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 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
Which returns:
| Item | EURUSD | USDJPY | GBPUSD |
|---|---|---|---|
| DF-GLS Statistic | -0.6470 | 0.7844 | -1.2019 |
| P-Value | 0.4349 | 0.8823 | 0.2100 |
| Lags Used | 2.0000 | 0.0000 | 0.0000 |
| Observations | 1,336.0000 | 1,351.0000 | 1,343.0000 |
| Critical Value 1% | -2.5674 | -2.5674 | -2.5674 |
| Critical Value 5% | -1.9412 | -1.9412 | -1.9412 |
| Critical Value 10% | -1.6166 | -1.6166 | -1.6166 |
| Reject Unit Root (5%) | 0.0000 | 0.0000 | 0.0000 |
8 rows
Using Your Own Data
get_unit_root_test 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_unit_root_test()
References
- Paper MacKinnon, J.G. (1994). “Approximate Asymptotic Distribution Functions for Unit-Root and Cointegration Tests.” Journal of Business & Economic Statistics, 12(2), 167-176.
- Paper Elliott, G., Rothenberg, T.J. and Stock, J.H. (1996). “Efficient Tests for an Autoregressive Unit Root.” Econometrica, 64(4), 813-836.
- Library Referenced against arch’s DFGLS (DF-GLS Test)