我正在估算一个VAR模型,以便以后了解我的实物价格和金融价格之间的关系。我从事商品工作。我已按照以下步骤进行操作,但不确定是否正确。另外,由于发现存在ARCH效果,因此我不确定该怎么办。
有人可以告诉我我的方法是否正确吗?如果我具有ARCH效应这一事实是我的VAR和/或Granger因果关系检验的问题?
##We verify stationarity of the price series:
#if not stationarity, we test co integration. If it is cointegrated, we estimate a VECM.
#If not stationary, we test co integration. If it is not cointegrated,
# I stationnarize the variables and estimate a VAR.
library(tseries)
adf.test(log_close_wk)
kpss.test(log_close_wk, null="Trend")
adf.test(log_price_wk)
kpss.test(log_price_wk, null="Trend")
#the null hypothesis of the existence of a unit root is NOT rejected hence the series
#is NOT stationary (there is a trend)
#Stationarity can come from the trend also, which is why I test with a KPSS test
#Now see if the spot and futures are partially cointegrated:
library(egcm)
egcm_finance <- egcm(log_close_wk, matrix(log_price_wk),include.const = T)
plot(egcm_finance$residuals,type = "l")
library(partialCI)
PCI_Spot_Futures<-fit.pci(log_close_wk, matrix(log_price_wk),
pci_opt_method = c("jp"),
par_model =c("ar1"), lambda = 0,
robust = FALSE, nu = 5)
test.pci(log_close_wk, matrix(log_price_wk), irobust=TRUE, alpha = 0.05, null_hyp =
c( "ar1"),imethod = "wilk",
pci_opt_method = c("jp"))
test.pci(log_close_wk, matrix(log_price_wk), irobust=TRUE, alpha = 0.05, null_hyp =
c( "rw"),imethod = "wilk",
pci_opt_method = c("jp"))
# a time series is classified as partially cointegrated, iif the random
#walk as well as the AR(1)-hypotheses are rejected. The p-value of 0.000 for
#both null model indicates that both are partially cointegrated in the
#considered period of time.WHICH IS THE CASE FOR ME!
##NOw we can run a VECM:
#I create dataframe with the couples of prices :
df_cl<-cbind(log_close_wk,log_price_wk)
library(vars)
#We find the lag order:
VARselect(df_cl) #4 lags / or 2 lags
library(tsDyn)
VECM(df_cl,4)
VECM(df_cl,2)
#Here my ECT coefficient is positive,
#It implies that the process it not converging in the long run.
#!It should be negative!!
#So we stationarize our variables and estimate a VAR model.
log_close_wk<-diff(log_close_wk)
log_price_wk<-diff(log_price_wk)
adf.test(log_close_exp_wk)
adf.test(log_price_wk)
###They are now stationary after one difference.
df_cl<-cbind(log_close_wk,log_price_wk)
#WE NOW ESTIMATE A VAR model:
#Number of lags:
library(vars)
#We find the lag order:
VARselect(df_cl) #5 lags / or1
fit<-VAR(df_cl,5)
fit
fit1<-VAR(df_cl,1)
fit1
#I should now test for serial autocorrelation using the Portmanteau test:
serial.test(fit, lags.pt = 10, type = "PT.asymptotic")
serial.test(fit1, lags.pt = 10, type = "PT.asymptotic")
#WE REJECT the hyp. of no serial correlation
#So we keep the model with no serial correlation :
#fit
#ARCH test (Autoregressive conditional heteroscedasdicity)
arch.test(fit, lags.multi = 10)
#so my data is conditionally heteroskedastic
#IS THAT A PROBLEM?????
summary(fit)
summary(fit2)
summary(fit3)
#Should I get rid of the ARCH effects?
#Granger Causality test
#Does CLOSE granger cause PRICE? ##BETTER?
grangertest(log_price_wk~ log_close_wk, order = 5)
#Does PRICE granger cause CLOSE?
grangertest(log_close_wk~ log_price_wk, order = 5)
#null hypothesis is rejected for both : i reject the hyp of no granger
causality(small pvalue)