興味深いことに、RTAQ は別の R パッケージにないものを提供していますか? バージョン 0.1 は 2 年以上前にリリースされたため、Dead Project のように見えます。とにかく、to.minute()RTAQ は xts オブジェクトを使用しているように見えるため、XTS の機能を引き続き使用できます。
これは、ティックを取得してバーに変換し、平均/標準偏差などの他の列を追加するために使用するサンプル コードです。
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.down06:00:00 から 06:00:59.999 までのティックが、「06:01:00」というラベルの付いたバーではなく、「06:00: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、取引セッションの開始と終了を記述するオブジェクトです。