Granger Vs Phillip Ouliaris Test
1)grangertest : How many pairs show cointegration from the 313 pairs ?
> library(lmtest) > sector.tests <- samesector > npairs <- dim(samesector)[1] > pair <- 1 > counter <- 0 > for (pair in 1:npairs) { + a <- sector.tests[pair, "tickeri"] + b <- sector.tests[pair, "tickerj"] + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + p1 <- (grangertest(y1 ~ x1, order = 1))[2, 4] + p2 <- (grangertest(x1 ~ y1, order = 1))[2, 4] + if (min(p1, p2) < 0.1) { + counter <- counter + 1 + } + } > print(paste(counter, "Using lmtest")) [1] "122 Using lmtest" |
There are about 122 pairs showing granger causality. ''
2)po.test (x←y): How many pairs show cointegration from the 313 pairs ?
> library(tseries) > sector.tests <- samesector > npairs <- dim(samesector)[1] > pair <- 1 > counter <- 0 > for (pair in 1:npairs) { + a <- sector.tests[pair, "tickeri"] + b <- sector.tests[pair, "tickerj"] + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + z <- cbind(y1, x1) + teststat <- (po.test(z))$p.value + if (teststat < 0.1) { + print(teststat) + counter <- counter + 1 + } + } > print(paste(counter, "Using po.test")) [1] "66 Using po.test" |
There are about 66 pairs showing cointegration using x←y ''
3)po.test (y←x): How many pairs show cointegration from the 313 pairs ?
> library(tseries) > sector.tests <- samesector > npairs <- dim(samesector)[1] > pair <- 1 > counter <- 0 > for (pair in 1:npairs) { + a <- sector.tests[pair, "tickeri"] + b <- sector.tests[pair, "tickerj"] + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + z <- cbind(x1, y1) + teststat <- (po.test(z))$p.value + if (teststat < 0.1) { + print(teststat) + counter <- counter + 1 + } + } > print(paste(counter, "Using po.test")) [1] "69 Using po.test" |
There are about 69 pairs showing cointegration using y←x ''
4)po.test (y←x and x←y): How many pairs show cointegration from the 313 pairs ?
> library(tseries) > sector.tests <- samesector > npairs <- dim(samesector)[1] > pair <- 1 > counter <- 0 > x <- matrix(data = 999, nrow = npairs, ncol = 3) > for (pair in 1:npairs) { + a <- sector.tests[pair, "tickeri"] + b <- sector.tests[pair, "tickerj"] + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + z <- cbind(x1, y1) + teststat1 <- (po.test(z))$p.value + z <- cbind(y1, x1) + teststat2 <- (po.test(z))$p.value + if (teststat1 < 0.1) + x[pair, 1] <- 1 + if (teststat2 < 0.1) + x[pair, 2] <- 1 + if (teststat1 < 0.1 & teststat2 < 0.1) + x[pair, 3] <- 1 + } > table(x[, 1], x[, 2]) 1 999 1 47 22 999 19 223 |
Populate grangertest against each pair
> sector.tests <- samesector > npairs <- dim(samesector)[1] > pair <- 1 > counter <- 0 > sector.tests$po.stat1 <- 999 > sector.tests$po.stat2 <- 999 > sector.tests$egtest.1 <- 999 > sector.tests$egtest.2 <- 999 > for (pair in 1:npairs) { + print(pair) + a <- sector.tests[pair, "tickeri"] + b <- sector.tests[pair, "tickerj"] + y1 <- (security.db1[, a]) + x1 <- (security.db1[, b]) + z <- cbind(y1, x1) + p <- (po.test(z))$p.value + sector.tests$po.stat1[pair] <- p + z <- cbind(x1, y1) + p <- (po.test(z))$p.value + sector.tests$po.stat2[pair] <- p + p <- (grangertest(y1 ~ x1, order = 1))[2, 4] + sector.tests$egtest.1[pair] <- p + p <- (grangertest(x1 ~ y1, order = 1))[2, 4] + sector.tests$egtest.2[pair] <- p + } > sector.tests$po.stat.min <- pmin(sector.tests$po.stat1, sector.tests$po.stat2) > sector.tests$egtest.min <- pmin(sector.tests$egtest.1, sector.tests$egtest.2) > sector.tests$po.stat1.st <- 0 > sector.tests$po.stat2.st <- 0 > sector.tests$egtest.1.st <- 0 > sector.tests$egtest.2.st <- 0 > sector.tests$po.stat1.st <- ifelse(sector.tests$po.stat1 < 0.1, + 1, 0) > sector.tests$po.stat2.st <- ifelse(sector.tests$po.stat2 < 0.1, + 1, 0) > sector.tests$egtest.1.st <- ifelse(sector.tests$egtest.1 < 0.1, + 1, 0) > sector.tests$egtest.2.st <- ifelse(sector.tests$egtest.2 < 0.1, + 1, 0) > sector.tests$postat.min.st <- ifelse(sector.tests$po.stat.min < + 0.1, 1, 0) > sector.tests$egtests.min.st <- ifelse(sector.tests$egtest.min < + 0.1, 1, 0) |
> temp <- data.frame(x = 1:311, stat1 = sector.tests$po.stat1.st, + stat2 = sector.tests$po.stat2.st, stat3 = sector.tests$egtest.1.st, + stat4 = sector.tests$egtest.2.st, pomin = sector.tests$postat.min.st, + egmin = sector.tests$egtests.min.st) |
> temp1 <- temp[temp$stat2 == 1 & temp$stat1 == 0, ] > table(temp1$egmin) 0 1 10 12 |
Out of 22 pairs which pass po test1 ONLY , 12 pass grangertest
> temp1 <- temp[temp$stat2 == 0 & temp$stat1 == 1, ] > table(temp1$egmin) 0 1 12 7 |
Out of 19 pairs which pass po test2 ONLY, 7 pass grangertest
> temp1 <- temp[temp$stat2 == 1 & temp$stat1 == 1, ] > table(temp1$egmin) 0 1 10 37 |
Out of 41 pairs which pass po test1 & potest 2 , 37 pass grangertest
> table(temp$pomin, temp$egmin) 0 1 0 157 66 1 32 56 |
Cross tab of Phillip Oularis test and Engle granger test