【问题标题】:Extracting the covariances out of a forecast从预测中提取协方差
【发布时间】:2015-06-17 18:40:35
【问题描述】:

我在从 R 中的预测中提取协方差时遇到了一些麻烦。这对你来说可能很容易,但我是 R 的初学者:

dcc.fcst = dccforecast(dcc.fit, n.roll=155, n.ahead=1)

print(rcov(dcc.fcst))

我得到的结果格式如下:

$`2015-04-23`
, , T+1

         rpf        rff
rpf 0.0001126362 0.0001125729

rff 0.0001125729 0.0001188316

$`2015-04-24`
, , T+1

        rpf         rff
rpf 0.0001058720 0.0001060763

rff 0.0001060763 0.0001129745

等等(总共 155 个这样的协方差矩阵)...

我试过公式:rcov(dcc.fcst)$ "%Y-%m-%d"[1,2,]

但它似乎不起作用。

【问题讨论】:

  • 我知道fcst1.fitted <- matrix(fitted(fcst1), ncol = 3, nrow = 500, byrow=TRUE) 在拥有 3 个资产和 500 个作为 out.sample 时有效。您可以对 sigma 做同样的事情:fcst1.sigma <- matrix(sigma(fcst1), ncol = 3, nrow = 500, byrow=TRUE) 因此,当您需要提取 协方差时,某种数组可能会起作用?
  • 谢谢你,jacob,我会试试的,虽然我已经手动修复了这个问题。

标签: r extract covariance


【解决方案1】:
cov.focast.line[i+1] = rcov(dcc.fcst)
outputcov <- matrix(unlist(cov.focast.line), ncol = 2, byrow = TRUE)
cov.focast1 <- c()
for (i in seq(from=2, to=NROW(outputcov), by=2)){
     cov.focast1[i/2] = outputcov[i,1]
}
cov.focast <- data.frame(cov.focast1)

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 2018-01-20
    • 2020-03-23
    • 1970-01-01
    相关资源
    最近更新 更多