[R-SIG-Finance] PerformanceAnalytics seems to break rollapply

Bos, Roger roger.bos at rothschild.com
Fri Oct 5 21:04:41 CEST 2012


Unless I am making a user error, it seems that rollapply stops working with some functions after the PerformanceAnalytics packages has been loaded.  I provide reproducible code below:

test <- xts(1:10, order.by=Sys.time()+(1:10))
"w" <- function(x) {
                                                z <- scale(x)
       attributes(z) <- NULL
       z
}
rollapply(data=test, width=3, FUN=mean)
rollapply(data=test, width=3, FUN=scale)
rollapply(data=test, width=3, FUN=w)
require("PerformanceAnalytics")
rollapply(data=test, width=3, FUN=mean)
rollapply(data=test, width=3, FUN=scale)
rollapply(data=test, width=3, FUN=w)

The first three calls to rollapply work fine.  Then once the PerformanceAnalytics packages had been loaded "mean" still works but "scale" does not.  I suspect it is because of the attributes which scale creates, but I tried creating a function (called "w") which removes the attributes, but rollapply still does not work.

Here is the error I get:

> rollapply(data=test, width=3, FUN=w)
Error in xts(xx, tt, if (by == 1) attr(data, "frequency")) :
  NROW(x) must match length(order.by)
>


Thanks for any help or advice you can provide!

Roger J. Bos, CFA
Rothschild Asset Management, Inc.
Tel   +1 (212) 403-5471
Email roger.bos at rothschild.com
1251 Avenue of the Americas, NY, NY 10020

***************************************************************
This message is for the named person's use only. It may\...{{dropped:11}}



More information about the R-SIG-Finance mailing list