Skip to content
All library documents

Applying ADF Tests Across Multiple Return Series

Article Quant Q&A · Author: Aquarius

Summary

The document explains how to apply Augmented Dickey-Fuller tests to many company return series stored as columns in a data frame. Its suggested approach is to omit the date column, then use a column-wise operation or loop to run a univariate test on each company. The example describes using a test function with a selected lag setting and a constant term, while noting a concern that automatic lag selection may affect the result.

It also highlights a key issue when interpreting many tests: at a 5% significance level, testing thousands of independent random walks would produce some apparent rejections by chance. A Bonferroni adjustment is mentioned for independent tests, but stock returns are correlated, so the answer suggests bootstrapping critical values across the test statistics. The discussion does not provide a full implementation of the bootstrap procedure, and the code suggestions depend on specific R packages and test conventions.

Key ideas

  • Apply a univariate ADF test separately to each data frame column containing a return series.
  • Exclude the date column before applying the test across columns.
  • Testing many series creates false positives even when each series follows a random walk.
  • Bonferroni adjustment is a possible correction for independent tests, while correlated tests may require bootstrap critical values.

Tags

Full text
# Augmented Dickey-Fuller Test/ Unit Root test on multiple time series dataframe in R


# Augmented Dickey-Fuller Test/ Unit Root test on multiple time series dataframe in R












I have a dataset/dataframe in which I have calculated the daily log returns of five thousand companies and these companies are as column as well. I want carry out ADF test on this dataframe. I have found how to estimate ADF test on vector but could not find how to calculate it on dataframe or matrix structure. Additionally how can I leave out the date column when estimating ADF test on the companies.

The picture illustrates some portion of my dataset. The code I ran and error I received are as follows

```
library(tseries)
adf.test(logs, alternative = c("stationary", "explosive"),
     k = trunc((length(1)-1)^(1/3)))

Error in adf.test(logs, alternative = c("stationary", "explosive"), k = trunc((length(1) -  :  x is not a vector or univariate time series
```

## Answer by Kiwiakos (score 1, accepted)

https://quant.stackexchange.com/a/22582

It is not clear from the post if you are querying for the mechanics/code for looping over the series or the appropriate critical values. I here make a comment on the latter.

One of the main pitfalls when testing multiple hypotheses is the fact that a certain percentage would fail under the null (as this xkcd strip nicely illustrates https://xkcd.com/882/ ).

If you run a DF test on 10,000 stocks you would expect 500 to show up as mean reverting at 5% confidence, even if they are all independent random walks. One needs to account for this feature by lowering the confidence level.

If your tests are independent, then you could have a Bonferroni-type adjustment of the confidence level to incorporate myltiple testing (https://en.m.wikipedia.org/wiki/Bonferroni_correction). But stocks are not independent, and therefore your t-statistics are not independent neither. To account for their correlation I would use bootstrapped critical values on the vector of t-stats.

## Answer by Alejandro Andrade (score 1)

https://quant.stackexchange.com/a/22580

There a to ways that you can performe the ADF test to a data frame, first write a loop for applying the test to all the columns or use the apply function to your data. For leaving out the first column just create an other data frame like this: `da=yourDataName[,-1]`. the code for the ADF would be something like `apply(da,2,adfTest,lags=0,type="c")`. The 2 is saying that the function adfTest should be apply to the columns, the `adfTest` is from the package `fUnitRoots`, `lags=0` so it does not perform the test lagging the series and `type="c"` so it includes a constant. I don't like the test from timeSeries package because it will lag the series automatically so you will get "always" a stationary series.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.