Reputation: 31
I have converted a financial data frame to an xts
format in R. But, it drops the header for the date column.
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
The problem is when I am using the rCov
function from the highfrequency
package.
> rc <- rCov(rData = x, makeReturns = TRUE)
It gives me the following error:
Error in names(result) <- unique(as.Date(index(rData))) :
'names' attribute [670] must be the same length as the vector [669]
What I have understood is that the length of each column must be the same, however, the date column is one less due to the header problem, if I am correct.
Please, I would be grateful if someone could help me with this little issue?
The dput:
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"))
Upvotes: 1
Views: 88
Reputation: 269526
I am unable to reproduce the error. Try starting a fresh session of R and then try again.
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)
giving:
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)"
Upvotes: 2