出于兴趣,RTAQ是否提供任何不在其他R包中的东西? 0.1版在两年前发布,因此它看起来像一个死亡项目。无论如何,你仍然可以使用XTS的to.minute()
函数,因为它显示RTAQ使用xts对象。
下面是我用带刻度并转换成棒,以及添加其他列,如平均值/ SD一些示例代码:
k=60
...
bars=to.period(x,k,period="secs")
colnames(bars)=c("Open","High","Low","Close")
ep=endpoints(x,"secs",k)
bars$Volume=period.apply(x,ep,length)
bars$mean=period.apply(x,ep,mean)
bars$sd=period.apply(x,ep, function(x){apply(x,2,sd)})
align.time(bars,k) #Do this last
而不是align.time
我用align.time.down
,这样从06蜱:00:00至06:00:59.999进入标有“06:00:00”的酒吧,而不是标有“06:01:00”的酒吧。这与我拥有的历史数据格式相匹配。如果你需要它的定义是:
align.time.down=function(x,n){index(x)=index(x)-n;align.time(x,n)}
最后,如果你有整个分钟内无蜱,并仍然希望在您的数据为他们吧,我用这个(相同的K = 60以上):
full_index=do.call("c",mapply(
seq.exclude_final_period.POSIXt,period_from,period_to,by=k,SIMPLIFY=F
))
bars=merge(bars,xts(,full_index),all=TRUE)
的seq.exclude_final_period.POSIXt
函数定义如下:
#' Helper for process_one_day_of_ticks(); intended as a
#' replacement for seq.POSIXt (which will not exclude the final period).
#' @internal Use from=from+by instead of to=to-by to exclude the
# first period instead.
seq.exclude_final_period.POSIXt=function(from,to,by){
to=to-by #Make the final entry exclusive
seq(from,to,by)
}
period_from
和period_to
是POSIXct
对象,描述的开始和交易时段结束。
什么包定义了'aggregatets'函数? – 2012-07-25 13:42:13
看看'?to.period'和朋友。 – 2012-07-25 13:56:18
xts函数to.period的问题在于它将不均匀时间序列中的刻度线转换为另一个非均匀序列。 – marino89 2012-07-25 14:34:15