Augmented Dickey-Fuller Test with R

Last Update: December 22, 2020

First order trend stationary time series consist of random processes that have constant mean which don’t exhibit trend pattern.

This topic is part of Pairs Trading Analysis with R course. Feel free to take a look at Course Curriculum.

This tutorial has an educational and informational purpose and doesn’t constitute any type of trading or investment advice. All content, including code and data, is presented for personal educational use exclusively and with no guarantee of exactness of completeness. Past performance doesn’t guarantee future results. Please read full Disclaimer.

Augmented Dickey-Fuller test  consists of evaluating whether time series was first order trend stationary with null hypothesis that it had a unit root and was not stationary.

1. Formula notation.

1.1. Augmented Dickey-Fuller test formula notation.

Where  = current period asset prices difference,  = regression constant term,  = regression coefficients,  = linear trend variable, = previous period asset price,  = previous periods asset prices differences,  = number of lags included within test, = regression residuals or forecasting errors.

1.2. Augmented Dickey-Fuller test formula notation constant and linear trend variable assumptions options.

Where  = regression constant term, = linear trend variable regression coefficient.

1.3. Augmented Dickey-Fuller test.

Augmented Dickey-Fuller individual test  coefficient t-statistic approximated :

• If Augmented Dickey-Fuller individual test  coefficient t-statistic approximated  level of statistical significance then time series was first order trend stationary with  level of statistical confidence.
• If Augmented Dickey-Fuller individual test  coefficient t-statistic approximated  level of statistical significance then higher differentiation order needed for first order trend stationary time series with  level of statistical confidence.

2. R script code example.

library('quantmod')
library('tseries')

2.2. Augmented Dickey-Fuller test data reading, training and testing ranges delimiting.

• Data: MSCI® Germany index replicating ETF (ticker symbol: EWG) daily adjusted close prices (2007-2016).
• Training and testing ranges delimiting not fixed and only included for educational purposes.
data <- xts(data[,2],order.by=as.Date(data[,1]))
colnames(data) <- 'ger'
tdata <- data['::2014-12-31']
fdata <- data['2015-01-02::']

2.3. Augmented Dickey-Fuller test prices chart.

• Augmented Dickey-Fuller test prices chart within training range.
tger <- tdata
plot(tger,main='tger Prices Chart')

2.4. Augmented Dickey-Fuller test calculation and output.

• Augmented Dickey-Fuller test calculation within training range.
• Augmented Dickey-Fuller test function includes constant and linear trend variable by default.
• Augmented Dickey-Fuller test function alternative hypothesis and lag order to calculate test statistic not fixed and only included for educational purposes.
In: