Hi, I have some raw tick data. (Individual trades with 1 second resolution.) I'd like to convert them to 5 minute bars - that is easy enough with the xts package. However, I'd also like to generate some other summary statistics for each 5 minute bar. total volume, tick count, up ticks, down ticks, etc. Any suggestions on an easy way to do this? Thanks! -- Noah Silverman UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095
Volume stats and 5 minute bars
4 messages · Noah Silverman, Joshua Ulrich, Brian G. Peterson
On Thu, Jun 16, 2011 at 2:08 PM, Noah Silverman <noahsilverman at ucla.edu> wrote:
Hi, I have some raw tick data. (Individual trades with 1 second resolution.) I'd like to convert them to 5 minute bars - that is easy enough with the xts package. However, I'd also like to generate some other summary statistics for each 5 minute bar. ?total volume, tick count, up ticks, down ticks, etc. Any suggestions on an easy way to do this?
Look at the source for apply.daily and write an analogous apply.minutely function (with an arg to specify the number of minutes). Or just use period.apply: R> period.apply(x, endpoints(x, "minutes", 5), function(y) c(mean(y), sd(y)) )
Thanks! -- Noah Silverman UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
HTH, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com
On Thu, 2011-06-16 at 12:08 -0700, Noah Silverman wrote:
Hi, I have some raw tick data. (Individual trades with 1 second resolution.)
1 second trade data is not raw tick data. Just to be clear on terminology.
I'd like to convert them to 5 minute bars - that is easy enough with the xts package.
yes, to.period()
However, I'd also like to generate some other summary statistics for each 5 minute bar. total volume, tick count, up ticks, down ticks, etc.
use aggregate() or one of the apply functions on endpoints() using your five minute endpoints, cbind that aggregation to your 5 minute bars. then use align.time on the resulting object to line it up to the next even minute.
Any suggestions on an easy way to do this? Thanks! -- Noah Silverman UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
Nice, Thanks! -- Noah Silverman UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095
On Jun 16, 2011, at 5:18 PM, Brian G. Peterson wrote:
On Thu, 2011-06-16 at 12:08 -0700, Noah Silverman wrote:
Hi, I have some raw tick data. (Individual trades with 1 second resolution.)
1 second trade data is not raw tick data. Just to be clear on terminology.
I'd like to convert them to 5 minute bars - that is easy enough with the xts package.
yes, to.period()
However, I'd also like to generate some other summary statistics for each 5 minute bar. total volume, tick count, up ticks, down ticks, etc.
use aggregate() or one of the apply functions on endpoints() using your five minute endpoints, cbind that aggregation to your 5 minute bars. then use align.time on the resulting object to line it up to the next even minute.
Any suggestions on an easy way to do this? Thanks! -- Noah Silverman UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095
_______________________________________________ R-SIG-Finance at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
-- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock