Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Out of interest does RTAQ offer anything not in another R package? Version 0.1 was released over two years ago, so it looks like a Dead Project. Anyway, you can still use XTS's <code>to.minute()</code> function, as it appears RTAQ use xts objects.</p> <p>Here is some sample code I use to take ticks and convert into bars, as well as adding other columns such as mean/sd:</p> <pre><code>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 </code></pre> <p>Instead of <code>align.time</code> I use <code>align.time.down</code>, so that ticks from 06:00:00 to 06:00:59.999 go into a bar labelled "06:00:00" not one labelled "06:01:00". This matches the historical data format I have. If you need it the definition is:</p> <pre><code>align.time.down=function(x,n){index(x)=index(x)-n;align.time(x,n)} </code></pre> <p>Finally, if you have whole minutes with no ticks, and still want a bar in your data for them, I use this (same k=60 as above):</p> <pre><code>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) </code></pre> <p>The <code>seq.exclude_final_period.POSIXt</code> function is defined as follows:</p> <pre><code>#' 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) } </code></pre> <p><code>period_from</code> and <code>period_to</code> are <code>POSIXct</code> objects, that describe the start and end of your trading session.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload