Faster alternative to rollapply

I need to run the crop function in the xts data, which contains about 7000 rows and 11,000 columns. I have done the following:

require(PerformanceAnalytics)
ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE)

I waited until 12 hours, but the calculation did not end. However, when I tried with a small data set as follows:

sample<-wddxts[,1:5]
ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE)

the calculation was carried out for 60 seconds. I ran them on a computer with an Intel i5-2450M processor, Windows 7 operating system and 12 GB of RAM.

Can someone suggest me if there is any faster way to do the above calculation on a large xts dataset?

+4
source share
1 answer

, . rollapply.zoo , rollapply.xts ( , ):

R> require(PerformanceAnalytics)
R> set.seed(21)
R> x <- .xts(rnorm(7000,0,0.01), 1:7000)
R> system.time({
+   r <- rollapply(x, 60, SemiDeviation, by.column=TRUE, fill=NA)
+ })
   user  system elapsed 
  9.936   0.111  10.075 
R> system.time({
+   z <- rollapplyr(as.zoo(x), 60, SemiDeviation, by.column=TRUE, fill=NA)
+ })
   user  system elapsed 
  1.950   0.010   1.964 
+3

All Articles