我正在建立一个VAR模型来预测资产价格,并想知道我的方法在统计上是否合理,我所包括的测试是否相关,以及是否需要更多测试以确保基于输入变量的可靠预测。
下面是我当前的检查Granger因果关系并预测所选VAR模型的过程。
require("forecast")
require("vars")
#Read Data
da=read.table("VARdata.txt", header=T)
dac <- c(2,3) # Select variables
x=da[,dac]
plot.ts(x)
summary(x)
#Run Augmented Dickey-Fuller tests to determine stationarity and differences to achieve stationarity.
ndiffs(x[, "VAR1"], alpha = 0.05, test = c("adf"))
ndiffs(x[, "VAR2"], alpha = 0.05, test = c("adf"))
#Difference to achieve stationarity
d.x1 = diff(x[, "VAR1"], differences = 2)
d.x2 = diff(x[, "VAR2"], differences = 2)
dx = cbind(d.x1, d.x2)
plot.ts(dx)
#Lag optimisation
VARselect(dx, lag.max = 10, type = "both")
#Vector autoregression with lags set according to results of lag optimisation.
var = VAR(dx, p=2)
#Test for serial autocorrelation using the Portmanteau test
#Rerun var model with other suggested lags if H0 can be rejected at 0.05
serial.test(var, lags.pt = 10, type = "PT.asymptotic")
#ARCH test (Autoregressive conditional heteroscedasdicity)
arch.test(var, lags.multi = 10)
summary(var)
#Granger Causality test
#Does x1 granger cause x2?
grangertest(d.x2 ~ d.x1, order = 2)
#Does x2 granger cause x1?
grangertest(d.x1 ~ d.x2, order = 2)
#Forecasting
prd <- predict(var, n.ahead = 10, ci = 0.95, dumvar = NULL)
print(prd)
plot(prd, "single")
这种方法听起来合理吗?