psytest.adftest module#
psytest.adftest#
This module contains the functions related to the Augmented Dickey-Fuller test for unit roots. The functions allow us to calculate both the test statistic and the asymptotic distribution of the test statistic. Additionally, it provides functions for rolling ADF tests and cumulative distribution functions based on a Wiener process.
- psytest.adftest.adfuller_fit(y: ndarray[tuple[int, ...], dtype[float64]], kmax: int) ndarray[tuple[int, ...], dtype[float64]] [source]#
Calculates the fitted values of the Augmented Dickey-Fuller regression.
- psytest.adftest.adfuller_stat(y: ndarray[tuple[int, ...], dtype[float64]], kmax: int) float [source]#
Calculates the test statistic for the Augmented Dickey-Fuller.
- Parameters:
- Returns:
tstat – The test statistic.
- Return type:
Notes
The Augmented Dickey-Fuller test statistic is calculated as: .. math:
\text{ADF} = \frac{\hat{\beta}}{\sqrt{\widehat{\mathrm{Var}}(\hat{\beta})}}
where \(\hat{\beta}\) is the coefficient of \(y_{t-1}\) and \(\widehat{\mathrm{Var}}(\hat{\beta})\) is its estimated variance in the regression:F .. math:
\Delta y_{t} = \alpha + \beta y_{t-1} + \sum_{k=2}^{kmax} \gamma_k \Delta y_{t-k} + \epsilon_t
- psytest.adftest.adfuller_dist(nobs: int, nreps: int, kmax: int) ndarray[tuple[int, ...], dtype[float64]] [source]#
Simulates the asymptotic distribution of the Augmented Dickey-Fuller test statistic.
- psytest.adftest.rolling_adfuller_stat(y: ndarray[tuple[int, ...], dtype[float64]], kmax: int, r1: float = 0, r2: float = 1.0) float [source]#
Calculates the Augmented Dickey-Fuller test statistic for a window of the time series.
- Parameters:
- Returns:
teststat – Value of the test statistic.
- Return type:
Notes
The rolling ADF test statistic is calculated as: .. math:
\text{ADF}(r_1, r_2) = \frac{\hat{\beta}}{\sqrt{\widehat{\mathrm{Var}}(\hat{\beta})}}
where \(\hat{\beta}\) is the coefficient of \(y_{t-1}\) and \(\widehat{\mathrm{Var}}(\hat{\beta})\) is its estimated variance in the regression: .. math:
\Delta y_{t} = \alpha + \beta y_{t-1} + \sum_{k=2}^{kmax} \gamma_k \Delta y_{t-k} + \epsilon_t
- Raises:
ValueError – If
r1
orr2
are not in the range [0, 1] or ifr1
is greater thanr2
.