更快的替代功能“rollapply" [英] Faster alternative to function 'rollapply'

查看:32
本文介绍了更快的替代功能“rollapply"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对包含大约 7,000 行和 11,000 列的 xts 数据运行滚动窗口函数.我做了以下事情:

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)

我等了 12 个小时,但计算没有完成.但是,当我尝试使用小数据集时,如下所示:

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)

计算在 60 秒内完成.我在配备 Intel i5-2450M CPU、Windows 7 操作系统和 12 GB RAM 的计算机上运行它们.

the computation was done within 60 seconds. I ran them on computer with Intel i5-2450M CPU, Windows 7 OS and 12 GB RAM.

如果有任何更快的方法在大型 xts 数据集上执行上述计算,任何人都可以给我建议吗?

Can anyone please suggest me if there is any faster way to perform the above computation on a large xts data-set?

推荐答案

如果可以,将它们转换为动物园对象.rollapply.zoorollapply.xts 更有效(在这种情况下.我不确定哪个更有效):

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 

这篇关于更快的替代功能“rollapply"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆