我使用R来估计4个时间序列的多变量GARCH(1,1)模型。我用rmgarch包试了一下。好像我使用它错了,但我不知道我的错误是什么。第一次使用。
library(quantmod)
library(fBasics)
library(rmgarch)
#load data, time series closing prices, 10 year sample
#DAX 30
getSymbols('^GDAXI', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
GDAXI.DE=GDAXI[ , "GDAXI.Close"]
#S&P 500
getSymbols('^GSPC', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
GSPC=GSPC[ , "GSPC.Close"]
#Credit Suisse Commodity Return Strat I
getSymbols('CRSOX', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
CRSOX=CRSOX[ , "CRSOX.Close"]
#iShares MSCI Emerging Markets
getSymbols('EEM', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
EEM=EEM[ , "EEM.Close"]
#calculating log returns of the time series
log_r1=diff(log(GDAXI.DE[39:2575]))
log_r2=diff(log(GSPC))
log_r3=diff(log(CRSOX))
log_r4=diff(log(EEM))
#return vector
r_t=cbind(log_r1, log_r2,log_r3, log_r4)
#specifying and fitting the model
model = multispec(replicate(4, ugarchspec(variance.model = c(1,1))))
model_order = mgarchspec(model, Order = c(1, 1), distribution ='mvnorm')
fit = mgarchfit(model_order, data = r_t, solver = 'solnp',fit.control = list(eval.se = TRUE))
print(fit.1)
答案 0 :(得分:7)
下面你会发现多变量DCC和ADCC Garch模型的并行实现。目前还不清楚你想要实现什么,但我认为你正在寻找每个变量之间的某种相关性。或者至少是一种不相关的波动性衡量指标。我的代码基于可在此处找到的代码:"Multivariate Garch implementation"。我强烈推荐阅读此内容。
像以前一样加载所有系列
library(rmgarch)
library(parallel)
library(quantmod)
确保数据的长度相等,并计算时间序列的日志返回值
Dat<-data.frame(GDAXI.DE[-c(1:22)],GSPC,CRSOX,EEM)
Dat<-apply(Dat,2,function(x) Delt(x,k=1,type="log"))
指定您的单变量garch过程以及多变量模型。在这里,我包括vanilla DCC-GARCH以及非对称DCC-GARCH模型规范
xspec = ugarchspec(mean.model = list(armaOrder = c(1, 1)), variance.model = list(garchOrder = c(1,1), model = 'sGARCH'), distribution.model = 'norm')
uspec = multispec(replicate(4, xspec))
spec1 = dccspec(uspec = uspec, dccOrder = c(1, 1), distribution = 'mvnorm')
spec1a = dccspec(uspec = uspec, dccOrder = c(1, 1), model='aDCC', distribution = 'mvnorm')
在执行计算密集型模型时,我建议使用并行方法。幸运的是rmgarch
内置了此功能。因此,让我们打开我们想要执行分析的群集数量
cl = makePSOCKcluster(4)
multf = multifit(uspec, Dat, cluster = cl)
我们现在终于可以适应模型了
fit1 = dccfit(spec1, data = Dat, fit.control = list(eval.se = TRUE), fit = multf, cluster = cl)
fit_adcc = dccfit(spec1, data = Dat, fit.control = list(eval.se = TRUE), fit = multf, cluster = cl)
print(fit1)
print(fit_adcc)
务必记住使用
关闭群集stopCluster(cl)
我希望这可以帮助你找到你想要的东西!