R - 建模多变量GARCH(rugarch和ccgarch)

时间:2013-06-01 15:38:12

标签: r time-series multivariate-testing volatility

第一次在这里问一个问题,我会尽力明确 - 但请告诉我是否应该提供更多信息!第二,这是一个很长的问题...希望很容易为某人解决;)!因此,使用“R”,我基于一些论文建模多变量GARCH模型(Manera et al.2012)。

我使用均值方程中的外部回归量对常数条件相关(CCC)和动态条件相关(DCC)模型进行建模;使用带有外部回归器的单变量GARCH的“R”版本3.0.1和带有“rugarch”版本1.2-2的版本,以及用于CCC / DCC模型的“ccgarch”软件包(版本0.2.0-2)。 (我目前正在研究“rmgarch”软件包 - 但它似乎只适用于DCC,我也需要CCC模型。)

我的模型的平均方程有问题。在我上面提到的论文中,CCC和DCC模型之间的平均方程的参数估计发生了变化!我不知道如何在R ... (目前,在Google上查看Tsay的书“金融时间序列分析”和恩格尔的书“预期相关性”以找出我的错误)

我的意思是“我的平均方程式在CCC和DCC模型之间不会改变”,它如下:我用包装rugarch指定我的n = 5时间序列的单变量GARCH。然后,我使用GARCH的估计参数(ARCH + GARCH术语)并将它们用于CCC和DCC函数“eccc.sim()”和“dcc.sim()”。然后,从eccc.estimation()和dcc.estimation()函数,我可以检索方差方程的估计以及相关矩阵。但不是平均等式。

我发布了R代码(可重现的和我的原始代码),仅用于单变量模型和CCC模型。谢谢你已经阅读我的帖子!!!!!

注意:在下面的代码中,“data.repl”是昏暗843x22的“动物园”对象(每日9件商品返回系列和解释变量系列)。多变量GARCH仅适用于5系列。

可重复的代码:

# libraries:
library(rugarch)
library(ccgarch)
library(quantmod)
# Creating fake data:
dataRegr <- matrix(rep(rnorm(3149,  11, 1),1), ncol=1, nrow=3149)
dataFuelsLag1 <- matrix(rep(rnorm(3149, 24, 8),2), ncol=2, nrow=3149)
#S&P 500 via quantmod and Yahoo Finance
T0 <- "2000-06-23"
T1 <- "2012-12-31"
getSymbols("^GSPC", src="yahoo", from=T0, to=T1)
sp500.close <- GSPC[,"GSPC.Close"], 
getSymbols("UBS", src="yahoo", from=T0, to=T1)
ubs.close <- UBS[,"UBS.Close"]
dataReplic <- merge(sp500.close, ubs.close, all=TRUE)
dataReplic[which(is.na(dataReplic[,2])),2] <- 0  #replace NA

### (G)ARCH modelling ###
#########################
# External regressors: macrovariables and all fuels+biofuel Working's T index
ext.regr.ext <- dataRegr
regre.fuels <- cbind(dataFuelsLag1, dataRegr)
### spec of GARCH(1,1) spec with AR(1) ###
garch11.fuels <- as.list(1:2)
for(i in 1:2){
  garch11.fuels[[i]] <- ugarchspec(mean.model = list(armaOrder=c(1,0), 
                                                     external.regressors = as.matrix(regre.fuels[,-i])))
}

### fit of GARCH(1,1) AR(1) ###
garch11.fuels.fit <- as.list(1:2)
for(i in 1:2){
  garch11.fuels.fit[[i]] <- ugarchfit(garch11.fuels[[i]], dataReplic[,i])
}
##################################################################
#### CCC fuels: with external regression in the mean eqaution ####
##################################################################
nObs <- length(data.repl[-1,1])
coef.unlist <- sapply(garch11.fuels.fit, coef)
cccFuels.a <- rep(0.1, 2)
cccFuels.A <- diag(coef.unlist[6,])
cccFuels.B <- diag(coef.unlist[7, ])
cccFuels.R <- corr.test(data.repl[,fuels.ind], data.repl[,fuels.ind])$r

# model=extended (Jeantheau (1998))
ccc.fuels.sim <- eccc.sim(nobs = nObs, a=cccFuels.a, A=cccFuels.A,
                          B=cccFuels.B, R=cccFuels.R, model="extended")
ccc.fuels.eps <- ccc.fuels.sim$eps
ccc.fuels.est <- eccc.estimation(a=cccFuels.a, A=cccFuels.A,
                                 B=cccFuels.B, R=cccFuels.R,
                                 dvar=ccc.fuels.eps, model="extended")
ccc.fuels.condCorr <- round(corr.test(ccc.fuels.est$std.resid,
                                      ccc.fuels.est$std.resid)$r,digits=3)

我的原始代码:

### (G)ARCH modelling ###
#########################
# External regressors: macrovariables and all fuels+biofuel Working's T index
ext.regr.ext <- as.matrix(data.repl[-1,c(10:13, 16, 19:22)])
regre.fuels <- cbind(fuel.lag1, ext.regr.ext) #fuel.lag1 is the pre-lagged series
### spec of GARCH(1,1) spec with AR(1) ###
garch11.fuels <- as.list(1:5)
for(i in 1:5){
  garch11.fuels[[i]] <- ugarchspec(mean.model = list(armaOrder=c(1,0),
                                   external.regressors = as.matrix(regre.fuels[,-i])))
}# regre.fuels[,-i] => "-i" because I model an AR(1) for each mean equation

### fit of GARCH(1,1) AR(1) ###
garch11.fuels.fit <- as.list(1:5)
for(i in 1:5){
  j <- i
  if(j==5){j <- 7} #because 5th "fuels" is actually column #7 in data.repl
  garch11.fuels.fit[[i]] <- ugarchfit(garch11.fuels[[i]], as.matrix(data.repl[-1,j])))
}

#fuelsLag1.names <- paste(cmdty.names[fuels.ind], "(-1)")
fuelsLag1.names <- cmdty.names[fuels.ind]
rowNames.ext <- c("Constant", fuelsLag1.names, "Working's T Gasoline", "Working's T Heating Oil",
              "Working's T Natural Gas", "Working's T Crude Oil",
              "Working's T Soybean Oil", "Junk Bond", "T-bill", 
              "SP500", "Exch.Rate")
ic.n <- c("Akaike", "Bayes")
garch11.ext.univSpec <- univ.spec(garch11.fuels.fit, ols.fit.ext, rowNames.ext, 
                                  rowNum=c(1:15), colNames=cmdty.names[fuels.ind],
                                  ccc=TRUE)
##################################################################
#### CCC fuels: with external regression in the mean eqaution ####
##################################################################
# From my GARCH(1,1)-AR(1) model, I extract ARCH and GARCH
# in order to model a CCC GARCH model:
nObs <- length(data.repl[-1,1])
coef.unlist <- sapply(garch11.fuels.fit, coef)

cccFuels.a <- rep(0.1, length(fuels.ind))
cccFuels.A <- diag(coef.unlist[17,])
cccFuels.B <- diag(coef.unlist[18, ])
#based on Engle(2009) book, page 31:
cccFuels.R <- corr.test(data.repl[,fuels.ind], data.repl[,fuels.ind])$r

# model=extended (Jeantheau (1998))
# "allow the squared errors and variances of the series to affect
# the dynamics of the individual conditional variances
ccc.fuels.sim <- eccc.sim(nobs = nObs, a=cccFuels.a, A=cccFuels.A,
                                   B=cccFuels.B, R=cccFuels.R, model="extended")
ccc.fuels.eps <- ccc.fuels.sim$eps
ccc.fuels.est <- eccc.estimation(a=cccFuels.a, A=cccFuels.A,
                                          B=cccFuels.B, R=cccFuels.R,
                                          dvar=ccc.fuels.eps, model="extended")
ccc.fuels.condCorr <- round(corr.test(ccc.fuels.est$std.resid,
                                      ccc.fuels.est$std.resid)$r,digits=3)
colnames(ccc.fuels.condCorr) <- cmdty.names[fuels.ind]
rownames(ccc.fuels.condCorr) <- cmdty.names[fuels.ind]
lowerTri(ccc.fuels.condCorr, rep=NA)

2 个答案:

答案 0 :(得分:3)

您是否知道多变量GARCH模型有一整套rmgarch

根据其描述,它涵盖

  

可行的多变量GARCH模型,包括DCC,GO-GARCH和   连接函数-GARCH。

答案 1 :(得分:0)

好吧,我希望这还不算太晚。这是我从 rmgarch 手册中发现的内容:“CCC 模型是使用静态 GARCH copula(正常)模型计算的”。