#R 3.6.3
#MSBVAR 0.9.3
# Bivariate Granger causality testing for NVOL vs USDX
#setwd("g:/B16°­Ώμ/AAA_Science/Science_hwang/02_Program/data_in") # need to change in other computer
setwd("i:/B16°­Ώμ/AAA_Science/Science_hwang/new21/data_in") # need to change in other computer
library("readxl")
require(forecast) 
require(MSBVAR)
#
xnom<-read_excel("savMXNdata_R.xlsx",sheet="nom")
ndiffs(xnom$NVOLmax, alpha=0.05, test=c("kpss"))   # 0
ndiffs(xnom$NVOLmin, alpha=0.05, test=c("kpss"))   # 0
ndiffs(xnom$USDX, alpha=0.05, test=c("kpss"))      # 0

ndiffs(xnom$NVOLmax, alpha=0.01, test=c("kpss"))   # 0
ndiffs(xnom$NVOLmin, alpha=0.01, test=c("kpss"))   # 0
ndiffs(xnom$USDX, alpha=0.01, test=c("kpss"))      # 0

# NVOLmax vs USDX
granger.test(data.frame(xnom$NVOLmax,xnom$USDX), p=1)
granger.test(data.frame(xnom$NVOLmax,xnom$USDX), p=2)
granger.test(data.frame(xnom$NVOLmax,xnom$USDX), p=3)
granger.test(data.frame(xnom$NVOLmax,xnom$USDX), p=4)
granger.test(data.frame(xnom$NVOLmax,xnom$USDX), p=5)
granger.test(data.frame(xnom$NVOLmax,xnom$USDX), p=6)

# NVOLmin vs USDX
granger.test(data.frame(xnom$NVOLmin,xnom$USDX), p=1)
granger.test(data.frame(xnom$NVOLmin,xnom$USDX), p=2)
granger.test(data.frame(xnom$NVOLmin,xnom$USDX), p=3)
granger.test(data.frame(xnom$NVOLmin,xnom$USDX), p=4)
granger.test(data.frame(xnom$NVOLmin,xnom$USDX), p=5)
granger.test(data.frame(xnom$NVOLmin,xnom$USDX), p=6)

