Today

Time series dependence: Review

Dealing with nonstationary data

Integrated Series

What if source of nonstationarity not known?

Daily log price, S&P 500 (1-04-2010-Last Week): (Code)

#Install data library (uncomment if needed)
#install.packages("quantmod",
#  repos="http://cran.us.r-project.org") 
library(quantmod) #Use quantmod to download data
#Get S&P500 Data
getSymbols("^gspc",src="yahoo",from = "2010-01-01") 
spdata<-as.ts(GSPC) # Turn into time series format
sp500<-spdata[,6] #Extract just adjusted closing price
lsp500<-log(sp500) #Take logs
library(dynlm)
dftest<-dynlm(d(lsp500)~L(lsp500)+trend(lsp500))
#Plot log prices
ts.plot(lsp500)

Daily log price, S&P 500 (1-04-2010-Last Week): Looks persistent

Differenced daily log price, S&P 500 (Code)

#Plot Differenced series
ts.plot(diff(lsp500))

Differenced daily log price, S&P 500: looks less persistent

A tool for detecting dependence: the Autocorrelation Function (ACF)

Autocorrelation function of daily log price, S&P 500

#Plot Autocorrelation function of log S&P 500
acf(lsp500,lag.max=120)

Autocorrelation function of daily log price, S&P 500

Unit roots

Sources of unit roots

Problems with nonstationarity

What to do about it?

Unit root testing

Dickey-Fuller Test

Accounting for serial correlation in root testing

Testing for Unit Root in S&P 500 (log) price (Code)

library(urca)
#ADF tests
spADF0<-ur.df(lsp500,type="drift",lags=0)
t0<-spADF0@teststat[1] #t value, no lags
spADF1<-ur.df(lsp500,type="drift",lags=1)
t1<-spADF1@teststat[1] #t value, 1 lag
#Phillips Perron test
spPP<-ur.pp(lsp500,type="Z-tau",model="constant")
ppt<-spPP@teststat #t value, robust errors

Application: Testing for Unit Root in S&P 500 (log) price

What to do with series with a unit root

Persistent Data: Conclusions

Time Series Conclusions