R中的DCC Garch模型-矩阵乘法误差:矩阵逆问题

时间:2018-11-06 19:39:22

标签: r matrix rstudio solver

我试图对4个变量运行DCC Garch模型,但是在运行适合模型的代码的最后一行时遇到问题。

因此,我正在寻找解决此问题的方法,我的代码有什么问题吗?是我的资料集吗?我对R还是很陌生,对此有点挣扎。

我看到了类似的帖子,但给出的答案并没有启发我,这就是为什么我要发布自己的示例

这是我的代码,一瞥我的数据:

library(xts)
library(quantmod)
library(rmgarch)
library(rugarch)

MV<-read.csv(file = "Book17.csv", header = TRUE, sep = ";",dec = ".",stringsAsFactors = F)
head(MV) 


MV$Dates<-strptime(x=as.character(MV$Dates),format = "%d/%m/%Y %H:%M")


library(xts)
MV1<-xts(MV[-1], order.by=MV$Dates)
head(MV1) 


sapply(MV1, mode)
sapply(MV1, class)

str(MV1)

MV1$BTC_returns=diff(log(MV1$BTC))
MV1$XBTV8_returns=diff(log(MV1$XBTV8))
MV1$XBTX8_returns=diff(log(MV1$XBTX8))
MV1$BTCV8_returns=diff(log(MV1$BTCV8))
head(MV1) 


MV2 <- data.frame(MV1$BTC_returns, MV1$XBTV8_returns, MV1$XBTX8_returns, MV1$BTCV8_returns)

head(MV2)
                    BTC_returns XBTV8_returns XBTX8_returns BTCV8_returns
2018-09-04 07:30:00   -0.000262     -0.000262     -0.000262     -0.000262
2018-09-04 08:00:00    0.001732      0.001732      0.001732      0.001732
2018-09-04 08:30:00    0.001180      0.001180      0.001180      0.001180
2018-09-04 09:00:00    0.000442      0.000442      0.000442      0.000442
2018-09-04 09:30:00    0.003010      0.003010      0.003010      0.003010
2018-09-04 10:00:00   -0.002305     -0.002305     -0.002305     -0.002305

m = ncol(MV2)
uspec.n = multispec(replicate(m, ugarchspec(mean.model = list(armaOrder = c(1,0)))))

multf = multifit(uspec.n, MV2)


spec1 = dccspec(uspec = uspec.n, dccOrder = c(1, 1), distribution = 'mvnorm')


 MV_fit = dccfit(spec1, data = MV2, fit.control = list(eval.se = TRUE), fit = multf)
  

运行最后一行,我会收到以下错误消息:

MV_fit = dccfit(spec1, data = MV2, fit.control = list(eval.se = TRUE), fit = multf)

error: matrix multiplication: problem with matrix inverse; suggest to use solve() instead

0 个答案:

没有答案