Augmented ADF
Purpose
Does Augmented ADF solve the problem where residuals can be correlated ?
I am going to run the same code and include higher order lags and see how many of them are stationary ?
> sector.tests <- samesector > sector.tests$uroot <- 0 > sector.tests$kpss <- 0 > npairs <- dim(samesector)[1] > pair <- 1 > for (pair in 1:npairs) { + a <- samesector[pair, "tickeri"] + b <- samesector[pair, "tickerj"] + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + temp1 <- (grangertest(y1 ~ x1, order = 1))[2, 4] + if (temp1 < 0.05) { + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + fit.1 <- lm(y1 ~ x1 + 0) + error <- residuals(fit.1) + time <- 1:length(error) + fit.2 <- lm(error ~ time) + if (coef(summary(fit.2))[1, 4] > 0.05 & coef(summary(fit.2))[2, + 4] > 0.05) { + type.1 <- "nc" + type.2 <- "mu" + error.transf <- error + } + if (coef(summary(fit.2))[1, 4] < 0.05 & coef(summary(fit.2))[2, + 4] < 0.05) { + type.1 <- "ct" + type.2 <- "tau" + error.transf <- resid(fit.2) + } + if (coef(summary(fit.2))[1, 4] < 0.05 & coef(summary(fit.2))[2, + 4] > 0.05) { + type.1 <- "c" + type.2 <- "mu" + error.transf <- error - mean(error) + } + if (coef(summary(fit.2))[1, 4] > 0.05 & coef(summary(fit.2))[2, + 4] < 0.05) { + type.1 <- "c" + type.2 <- "mu" + error.transf <- error + } + t1 <- unitrootTest(error.transf, lags = 1, type = "ct")@test$p.value[1] + kpfit <- urkpssTest(error.transf, type.2, "short") + if (kpfit@test$test@teststat > kpfit@test$test@cval[2]) { + t2 <- 1 + } + else { + t2 <- 0 + } + sector.tests$uroot[pair] <- t1 + sector.tests$kpss[pair] <- t2 + } + temp2 <- (grangertest(x1 ~ y1, order = 1))[2, 4] + if (temp1 > 0.05 & temp2 < 0.05) { + y1 <- (security.db1[, b]) + x1 <- (security.db1[, a]) + fit.1 <- lm(y1 ~ x1 + 0) + error <- residuals(fit.1) + time <- 1:length(error) + fit.2 <- lm(error ~ time) + if (coef(summary(fit.2))[1, 4] > 0.05 & coef(summary(fit.2))[2, + 4] > 0.05) { + type.1 <- "nc" + type.2 <- "mu" + error.transf <- error + } + if (coef(summary(fit.2))[1, 4] < 0.05 & coef(summary(fit.2))[2, + 4] < 0.05) { + type.1 <- "ct" + type.2 <- "tau" + error.transf <- resid(fit.2) + } + if (coef(summary(fit.2))[1, 4] < 0.05 & coef(summary(fit.2))[2, + 4] > 0.05) { + type.1 <- "c" + type.2 <- "mu" + error.transf <- error - mean(error) + } + if (coef(summary(fit.2))[1, 4] > 0.05 & coef(summary(fit.2))[2, + 4] < 0.05) { + type.1 <- "c" + type.2 <- "mu" + error.transf <- error + } + t1 <- unitrootTest(error.transf, lags = 4, type = type.1)@test$p.value[1] + kpfit <- urkpssTest(error.transf, type.2, "short") + if (kpfit@test$test@teststat > kpfit@test$test@cval[2]) { + t2 <- 1 + } + else { + t2 <- 0 + } + sector.tests$uroot[pair] <- t1 + sector.tests$kpss[pair] <- t2 + } + if (temp1 > 0.05 & temp2 > 0.05) { + sector.tests$uroot[pair] <- 999 + sector.tests$kpss[pair] <- 999 + } + } |
> test <- sector.tests[sector.tests$uroot != 999, ] > dim(test) [1] 127 12 |
> length(which(test$uroot < 0.05)) [1] 39 |
Out of 127 pairs, there are about 39 pairs which pass unit root tests
5 PAIRS ARE KNOCKED OFF when unitrootTest is used with about 4 lags.