从 R 中的拟合模型保存或提取方差协方差矩阵输出

Save or Extract variance covariance matrix output from fitted model in R

我有以下可重现的代码。

library(zoo)
library (rugarch)
library(rmgarch)
data("EuStockMarkets")
EuStockLevel <- as.zoo(EuStockMarkets)[,c("DAX","CAC","FTSE")]
EuStockRet <- diff(log(EuStockLevel))

## GARCH-DCC
    uspec = ugarchspec(mean.model = list(armaOrder = c(0,0)), variance.model = list(garchOrder = c(1,1), model = "sGARCH"), distribution.model = "norm")
    spec1 = dccspec(uspec = multispec( replicate(3, uspec) ),  dccOrder = c(1,1),  distribution = "mvnorm")
    fit1 = dccfit(spec1, data = EuStockRet, fit.control = list(eval.se=T))

#Forecasting 
    dcc.focast=dccforecast(fit1, n.ahead = 1, n.roll = 0)
    print(dcc.focast)

输出如下:-

*---------------------------------*
*       DCC GARCH Forecast        *
*---------------------------------*

Distribution         :  mvnorm
Model                :  DCC(1,1)
Horizon              :  1
Roll Steps           :  0
-----------------------------------

0-roll forecast: 
, , 1

       [,1]   [,2]   [,3]
[1,] 1.0000 0.7472 0.6790
[2,] 0.7472 1.0000 0.6897
[3,] 0.6790 0.6897 1.0000

如何将预测矩阵提取或保存为对象,以便我可以使用协方差矩阵进行投资组合优化?

谢谢。

您创建的dcc.focast对象是一个S4对象。默认情况下,print 调用其 show 方法,该方法仅显示摘要。

您可以使用 ?"DCCforecast-class" 中描述的 S4 方法调用访问对象中的每个元素(注意双引号)。我想你想要的是 rcov(dcc.focast),但也可能是 rcor.

您还可以使用 slot @mforecast: dcc.focast@mforecast 访问多变量预测列表,您可以通过添加括号来获取子集:dcc.focast@mforecast[1].