arch.unitroot.VarianceRatio

class arch.unitroot.VarianceRatio(y: ndarray | DataFrame | Series, lags: int = 2, trend: 'n' | 'c' = 'c', debiased: bool = True, robust: bool = True, overlap: bool = True)[source]

Variance Ratio test of a random walk.

Parameters:
y: ndarray | DataFrame | Series

The data to test for a random walk.

lags: int = 2

The number of periods to use in the multi-period variance, which is the numerator of the test statistic. Must be at least 2.

trend: 'n' | 'c' = 'c'

“c” allows for a non-zero drift in the random walk, while “n” requires that the increments to y are mean 0. Not case sensitive.

debiased: bool = True

Indicates whether to use a debiased version of the test. Only applicable if overlap is True.

robust: bool = True

Indicates whether to use heteroskedasticity robust inference.

overlap: bool = True

Indicates whether to use all overlapping blocks. If False, the number of observations in y minus 1 must be an exact multiple of lags. If this condition is not satisfied, some values at the end of y will be discarded.

Raises:
  • TypeError – If y cannot be converted to numbers, lags is not an integer, debiased, robust or overlap is not a bool, or trend is not a str.

  • ValueError – If y is not 1-d or contains NaN or inf, lags is less than 2, or trend is not one of the options.

  • InfeasibleTestException – If y has too few observations for lags. At least lags + 1 observations are needed (lags + 2 if debiased), or 2 * lags if overlap is False. This is also a ValueError.

Notes

The null hypothesis of a VR is that the process is a random walk, possibly plus drift. Rejection of the null with a positive test statistic indicates the presence of positive serial correlation in the time series. See [1] for details about variance ratio testing.

References

Examples

>>> import numpy as np
>>> from arch.data.sp500 import load
>>> from arch.unitroot import VarianceRatio
>>> data = load()["Adj Close"].loc["2010-01-01":"2018-12-31"]
>>> data = np.log(data.resample("ME").last())  # End of month
>>> vr = VarianceRatio(data, lags=12)
>>> print(f"{vr.pvalue:0.4f}")
0.1504

Methods

summary()

Summary of test, containing statistic, p-value and critical values.

Properties

alternative_hypothesis

The alternative hypothesis.

critical_values

The critical values of the test.

debiased

Indicator to use debiased variances in the ratio.

lags

The number of lags used in the model.

nobs

The number of observations used when computing the test statistic.

null_hypothesis

The null hypothesis.

overlap

Indicator to use overlapping returns in the long-period variance estimator.

pvalue

The p-value for the test statistic.

robust

Indicator to use a heteroskedasticity robust variance estimator.

stat

The test statistic for a unit root.

trend

The deterministic trend term used in the test.

valid_trends

List of valid trend terms.

vr

The ratio of the long block lags-period variance to the 1-period variance.

y

The data used in the test statistic.