# Regression of Two Random Walks # This illustrates how easy it is to get spurious regressions # when you just pick up two time series which are both I(1) processes, # as prices usually are. module(finmetrics) x=cumsum(rnorm(1000)) y=cumsum(rnorm(1000)) #Do the two plots --- they both do look like random walks (or price processes) par(mfrow=c(2,1)) plot(x) plot(y) #Now regress xyfit=lm(y~x) summary(xyfit) #You'll get a significant alpha and significant beta damn near every time! ################ #Just think how weird this is --- x and y are independent of each other! #This is an example of "spurious regression" # It is easy to "smell a rat" in this simple simulation, but you would be # amazed how many people do thinks like regress the price of SPY vs the price # of some bond fund --- # The problem here is PRICE. If one were to look at returns, # this problem would not show up. #What is the problem? The problem is that the residuals from the fit of #two I(1) processes can be either an I(1) process or an I(0) process. # If it is an I(0) process the regression is "legitimate" --- or at least no # worse than usual. # If the residual is an I(1) process --- or if you can't reject this possibilty # then the regression is JUNK (aka SPURIOUS). #Let's look at our RW regression residuals and see if the regression # was SPURIOUS. That is we # take z= y-beta*x and test it to see if we can reject that z is an I(1) process # That is we test z for a "unit root" --- # say using Augmented Dickey Fuller t-test #First we extract the beta from xyfit beta=coefficients(xyfit)[2] #Check beta # Now we get our residuals --- we could just pulled them out # from xyfit, but lets be explict: z= y-beta*x #Now we use unitroot to do the augmented Dickey-Fuller t-tests #We'll take 6 lags --- you can explore this choice if you like. #It seldom matters so long as you do have two or more lags. adft.out = unitroot(z, trend="c", statistic="t",method="adf", lags=6) summary(adft.out) #Most of the time (but not absolutely every time) you will fail to reject the hypothesis that # the residual series has a unit root. That is, you will fair to reject the hypothesis that # the z process is non-stationary, in fact I(1) --- or at least we can't say that it isn't I(1)