1

我已将财务数据框转换为xtsR 中的格式。但是,它删除了日期列的标题。

                     EURAUD  EURCAD  EURGBP   EURHKD
2013-10-01 00:00:00 1.45070 1.39638 0.83539 10.48859
2013-10-01 00:01:00 1.45058 1.39647 0.83539 10.48938
2013-10-01 00:02:00 1.45043 1.39636 0.83536 10.48825

问题是当我使用包中的rCov功能时highfrequency

> rc <- rCov(rData = x, makeReturns = TRUE)

它给了我以下错误:

Error in names(result) <- unique(as.Date(index(rData))) : 
'names' attribute [670] must be the same length as the vector [669]

我的理解是每列的长度必须相同,但是,如果我是正确的,由于标题问题,日期列会少一个。

请,如果有人能帮助我解决这个小问题,我将不胜感激?

输出:

structure(c(1.4507, 1.45058, 1.45043, 1.45035, 1.39638, 1.39647, 1.39636, 1.39641, 0.83539, 0.83539, 0.83536, 0.83538, 10.48859, 10.48938, 10.48825, 10.48868, 297.028, 297.028, 297.028, 297.028, 133.026, 133.071, 133.029, 133.003,1.62955,1.62925,1.62899,1.62898,43.82374,43.82374,43.82374,43.82374,43.82374,83.82374,8.68498,8.68568,8.68568,8.68568,8.68498,8.68498结构(c(1380571200、1380571260、1380571320、1380571380),tzone =“”,tclass = c(“POSIXct”,“POSIXt”)),.Dim = c(4L,10L),.Dimnames = list(NULL,c ("EURAUD"、"EURCAD"、"EURGBP"、"EURHKD"、"EURHUF"、"EURJPY"、"EURNZD"、"EURRUB"、"EURSEK"、"EURSGD"))

4

1 回答 1

2

我无法重现该错误。尝试开始新的 R 会话,然后重试。

library(highfrequency)
library(xts)

x <- structure(c(1.4507, 1.45058, 1.45043, 1.45035, 1.39638, 1.39647, 1.39636, 
  1.39641, 0.83539, 0.83539, 0.83536, 0.83538, 10.48859, 10.48938, 10.48825, 
  10.48868, 297.028, 297.028, 297.028, 297.028, 133.026, 133.071, 133.029, 
  133.003, 1.62955, 1.62925, 1.62899, 1.62898, 43.82374, 43.82374, 43.82374, 
  43.82374, 8.68498, 8.68568, 8.68498, 8.68423, 1.69654, 1.69687, 1.69678, 
  1.69688), class = c("xts", "zoo"), index = structure(c(1380571200, 1380571260, 
  1380571320, 1380571380), tzone = "", tclass = c("POSIXct", "POSIXt")), 
  .Dim = c(4L, 10L), .Dimnames = list(NULL, c("EURAUD", "EURCAD", "EURGBP", 
  "EURHKD", "EURHUF", "EURJPY", "EURNZD", "EURRUB", "EURSEK", "EURSGD")))
  


rCov(rData = x, makeReturns = TRUE)

给予:

              EURAUD       EURCAD       EURGBP       EURHKD EURHUF
EURAUD  2.057940e-08 8.396314e-10 2.393188e-09 2.649288e-09      0
EURCAD  8.396314e-10 1.164117e-08 3.686169e-09 1.480872e-08      0
EURGBP  2.393188e-09 3.686169e-09 1.862868e-09 4.850477e-09      0
EURHKD  2.649288e-09 1.480872e-08 4.850477e-09 1.896003e-08      0
EURHUF  0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00      0
EURJPY  1.544714e-08 3.966595e-08 6.656647e-09 5.146879e-08      0
EURNZD  3.207325e-08 4.856334e-10 5.584419e-09 3.074993e-09      0
EURRUB  0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00      0
EURSEK  6.430929e-09 8.450929e-09 8.267730e-10 1.121259e-08      0
EURSGD -1.385462e-08 1.882360e-08 3.315736e-09 2.277912e-08      0
              EURJPY        EURNZD EURRUB        EURSEK        EURSGD
EURAUD  1.544714e-08  3.207325e-08      0  6.430929e-09 -1.385462e-08
EURCAD  3.966595e-08  4.856334e-10      0  8.450929e-09  1.882360e-08
EURGBP  6.656647e-09  5.584419e-09      0  8.267730e-10  3.315736e-09
EURHKD  5.146879e-08  3.074993e-09      0  1.121259e-08  2.277912e-08
EURHUF  0.000000e+00  0.000000e+00      0  0.000000e+00  0.000000e+00
EURJPY  2.522492e-07 -1.069295e-08      0  6.958129e-08  7.100628e-08
EURNZD -1.069295e-08  5.940738e-08      0 -1.446182e-09 -2.770654e-08
EURRUB  0.000000e+00  0.000000e+00      0  0.000000e+00  0.000000e+00
EURSEK  6.958129e-08 -1.446182e-09      0  2.044932e-08  1.486076e-08
EURSGD  7.100628e-08 -2.770654e-08      0  1.486076e-08  4.411457e-08

packageVersion("highfrequency")
## [1] ‘0.8.0.1’
packageVersion("xts")
## [1] ‘0.12.1’
R.version.string
## [1] "R version 4.0.4 Patched (2021-03-05 r80091)"
于 2021-05-14T19:22:01.147 回答