gpt4 book ai didi

r - DCC-GARCH的实现

转载 作者:行者123 更新时间:2023-12-01 11:25:36 27 4
gpt4 key购买 nike

我在 R 中实现 DCC-GARCH 时遇到一些问题。当我在 R 中运行以下代码时,我总是收到相同的错误消息:

Error in UseMethod("convergence") : no applicable method for 'convergence' applied to an object of class "try-error"

不幸的是,我不知道如何解决这个问题......

    install.packages("fGarch")
install.packages("rugarch")
install.packages("rmgarch")
library(fGarch)
library(rmgarch)
library(rugarch)
library(tseries)
library(zoo)

#Daten runterladen
ibm <- get.hist.quote(instrument = "DB", start = "2005-11-21",
quote = "AdjClose")
sys<- get.hist.quote(instrument = "^STOXX50E", start = "2005-11-21",
quote = "AdjClose")

#Returns
retibm<-diff(log(ibm))
retsys<-diff(log(sys))

# univariate normal GARCH(1,1) for each series
garch11.spec = ugarchspec(mean.model = list(armaOrder = c(0,0)),
variance.model = list(garchOrder = c(1,1),
model = "sGARCH"),
distribution.model = "norm")

# dcc specification - GARCH(1,1) for conditional correlations
dcc.garch11.spec = dccspec(uspec = multispec( replicate(2, garch11.spec) ),
dccOrder = c(1,1),
distribution = "mvnorm")
dcc.garch11.spec

MSFT.GSPC.ret = merge(retsys,retibm)
plot(MSFT.GSPC.ret)
dcc.fit = dccfit(dcc.garch11.spec, data = MSFT.GSPC.ret)

我不确定这个分论坛是否合适,但它似乎比量化金融论坛更合适。如果有误,我深表歉意。

最佳答案

此问题是由 merge 的某种非标准行为引起的。当按列名合并时,我们默认有 all = FALSE。但是,当按行名称合并时,如本例所示,我们似乎有 all = TRUE,因此 MSFT.GSPC.ret 包含 NA 值。

所以,使用任一个

MSFT.GSPC.ret <- merge(retsys, retibm, all = FALSE)

dcc.fit <- dccfit(dcc.garch11.spec, data = na.omit(MSFT.GSPC.ret))

解决问题。

关于r - DCC-GARCH的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37459199/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com