0
votes

I am trying to calculate CoVariance on data frame:

cov_test <- CoVariance(returns, returns)

returns looks ~like that:

             A          B         C

28/02/1999 -0.018816 -0.011451 -0.026870

31/03/1999 0.004001 0.006580 0.002293

Error I get:

Error in merge.zoo(e1, e2, all = FALSE, retclass = NULL) : series cannot be merged with non-unique index entries in a series In addition: Warning messages: 1: In zoo(cd, order.by = index(x), ...) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 2: In zoo(rval, index(x)[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 3: In zoo(rval, index(x)[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 4: In zoo(cd, order.by = index(x), ...) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 5: In zoo(rval, index(x)[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique 6: In zoo(rval, index(x)[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique

However, when I use simple cov function in R, it works just fine...

Could anyone advise what could be the issue? I checked for duplicated rows with anyDuplicated(returns) and it returned 0. Also, broadly speaking, what is the main difference between CoVariance function from PerformanceAnalytics and simple cov function? Thank you.

1

1 Answers

0
votes

This works for me in R 3.6.1 with PerformanceAnalytics 1.5.3 and zoo 1.8-6:

library(PerformanceAnalytics)
returns <- data.frame(dt = as.Date(c('1999/02/28', '1999/03/31')), A=c(-0.018816, 0.004001), B=c(-0.011451, 0.006580), C=c(-0.02687, 0.002293))

z <- zoo(returns[,-1], returns[,1])
CoVariance(z,z)
                         A            B            C
Covariance: A 0.0001301539 1.028533e-04 0.0001663530
Covariance: B 0.0001028533 8.127924e-05 0.0001314595
Covariance: C 0.0001663530 1.314595e-04 0.0002126201

Perhaps your zoo object has not got an ordered index? Check the format of the dates when you construct your zoo object.