简体   繁体   中英

DCC GARCH model- matrix error in R

I have a fitted DCC GARCH model to daily equity returns of over 70 financial institutions during 2010-2017.I am trying to construct cross-correlations among institutions. However, the code below gives me an error. The problem is I don't know the source of this error.

Below is my code:

rm(list = ls())
options(error=recover)
library(rmgarch)
library(xts)
library(foreign)

dat=read.csv("equity_returns2_2010-17_updated.csv", stringsAsFactors = FALSE)
tickers = unique(dat[,2])
R = do.call(cbind, lapply(1:length(tickers), function(i){
  tmp = dat[which(dat[,2]==tickers[i]),c(1,3)]
  tmp = xts(as.numeric(tmp[,2]), as.Date(strptime(tmp[,1],"%Y%m%d")))
  colnames(tmp)=tickers[i]
  return(tmp)
}))

head(R)
exc=sapply(1:ncol(R), function(i) length(which(is.na(R[,i]))))
exc=which(exc>1)
if(length(exc)>0) R = R[,-exc]
head(R)
which(is.na(R), arr.ind = TRUE)
R = na.omit(R)

m = ncol(R)
spec=ugarchspec(mean.model=list(armaOrder=c(1,0)),variance.model=list(garchOrder=c(1,1),model="gjrGARCH", variance.targeting=TRUE))
spec = multispec(replicate(m, spec))

mspec=dccspec(uspec = spec)
fit = dccfit(mspec, dat=R, solver=c("solnp","solnp"), solver.control=list(trace=1))

it works very well until "fit". Once I run fit it gives the following error:

.
.
.
.
Iter: 1 fn: 2654.2613    Pars:  36.63415  0.97195  0.10379  0.93518 -0.08157
Iter: 2 fn: 2654.2613    Pars:  36.63417  0.97195  0.10379  0.93518 -0.08157
solnp--> Completed in 2 iterations

Iter: 1 fn: 2654.2613    Pars:  36.63415  0.97195  0.10379  0.93518 -0.08157
Iter: 2 fn: 2654.2613    Pars:  36.63417  0.97195  0.10379  0.93518 -0.08157
solnp--> Completed in 2 iterations

error: matrix multiplication: inverse of singular matrix; suggest to use solve() instead

Any idea on how to fix the problem? Thanks in advance.

I dont see any problem with your code. I think you should go beyond the code and look into your data to see whats the problem. have you run this code with any other data set?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM