I have the following reproducible code.
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)
The output will be as follows:-
*---------------------------------*
* 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
How do I extract or save the forecast matrix as object so I can use the covariance matrix for portfolio optimization?
Thank you.
The dcc.focast
object you create is an S4 object. By default, print
calls its show
method, which just presents a summary.
You can access each of the elements in the object using the S4 method calls described in ?"DCCforecast-class"
(Note the double quotes). I think the one you want is rcov(dcc.focast)
, though it could be rcor
.
You can also access the multivariate forecast list using the slot
@mforecast
: dcc.focast@mforecast
and you can get the subsets by adding brackets: dcc.focast@mforecast[1]
.