#========================================== #Example of Augmented DF Test and exchange rate data #Based on an example from Z&W #================================================= #=============================================== #First Get the series for Canadian/US log spot rates #Then get a picture of the series and its ACF #Then do the same for the first difference #================================================= uscn.spot = lexrates.dat[,"USCNS"] uscn.spot@title = "Log US/CN spot exchange rate" par(mfrow=c(2,2)) plot.timeSeries(uscn.spot, reference.grid=F,main="Log of US/CN spot exchange rate") xx = acf(uscn.spot) plot.timeSeries(diff(uscn.spot), reference.grid=F,main="First difference of log US/CN spot exchange rate") xx = acf(diff(uscn.spot)) #============================================== #Now look at the Augmented DF t-test, allowing for a constant and 6 lags #============================================== adft.out = unitroot(uscn.spot, trend="c", statistic="t",method="adf", lags=6) #====================================== #Check the class of the object we have created. #====================================== class(adft.out) #======================================= #Use one of the "generic methods" to look at this object. #Both print() and summary() are defined for objects of this class. #We can automactically call print() just by typing the name of our object. #================================================== adft.out #============================================ #We see that we "fail to reject" the hypothesis that our series has a unti root. #This is NOT quite the same as having positive evidence in FAVOR of our hypothesis; #Z&W are not quite precise in their language. # #From summary() we get information on the significance of the lagged differences in the #test model #=========================================== summary(adft.out) #=============================================== #The message here is that lags after the second look insignificant. #Thus, we try out the ADF test with fewer lags. #================================================ adft.out = unitroot(uscn.spot, trend="c", statistic="t",method="adf", lags=2) #=============================================================== #This time we see even less significance of the test, less evidence against the #null hypothesis. This is not the same as evidence for the hypothesis, but it #does point in that direction. #================================================================== #============================================================ #Let's do the second example from Z&W; #It is more generic; most stock price data has looks more like an I(1) #process than an I(0) process. That's why we always study returns #for stock prices. #======================================================== lnp = log(singleIndex.dat[,1]) lnp@title = "Log of S&P 500 Index" par(mfrow=c(2,2)) plot.timeSeries(lnp, reference.grid=F,main="Log of S&P 500 index") acf.plot(acf(lnp,plot=F)) plot.timeSeries(diff(lnp), reference.grid=F,main="First difference of log S&P 500 Index") acf.plot(acf(diff(lnp),plot=F)) #================================================ #The picture argues for "nonstationarity" though I would not be as confident of #a positive trend as Z&W seem to be. If we could spot trends by looking at #a plot of the prices, we would be rich beyond the dreams of avarice. Still, #log stock price having a trend is reasonalbe --- one expects a return after all. #Let's check out an ADF test with a constant and trend and 4 lagged differences #=================================================== adft.out = unitroot(lnp, trend="ct", lags=4) summary(adft.out) #===================================== #Here we also "fail to reject." #You'll get a similar story for almost any price series #==================================== #======================================= #Final story about unit root tests? # #They are lame in many respects, but they do give us something. #For example, in statistical arbitrage, one tries like hell to #construct a series that is mean reverting. #For such a series, we definitly want to run unit root tests #and keep our fingers crossed for a STRONG REJECTION. #That would be good news indeed.