I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following:
require(PerformanceAnalytics)
ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE)
I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows:
sample<-wddxts[,1:5]
ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE)
the computation was done within 60 seconds. I ran them on computer with Intel i5-2450M CPU, Windows 7 OS and 12 GB RAM.
Can anyone please suggest me if there is any faster way to perform the above computation on a large xts data-set?
If you can, convert them to zoo objects. rollapply.zoo
is more efficient than rollapply.xts
(in this case. I'm not sure which is more efficient in general):
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With