[R-SIG-Finance] How to know when an XTS row is at a particular interval

Brian G. Peterson brian at braverock.com
Thu Jul 7 22:42:10 CEST 2011


On Thu, 2011-07-07 at 13:27 -0700, Noah Silverman wrote:
> Hi,
> 
> 
> I have a big dataset of tick data.  (Actual transactions at sub-second frequency)
> 
> I've used R to convert this to an xts object.
> 
> Iterating through the series to simulate a trading day.
> 
> I'd like to know when a particular transaction is "on the minute" or "on the 5 minute" mark.  Of course, I can use all the great functions of xts to convert the series to bars of any frequency, but that's not what I want.  I'd like to iterate over all the transaction and then somehow know when I've hit a bar boundary.

With actual ticks, there will be few or no trades 'on the mark'. This is
why most tick-level analysis relies on the prevailing bid and offer,
since there is always *some* real price at any given time, even though
trades happen at discrete times.

Anyway, the function you need is 'endpoints', which will give you the
closest stamp to the mark, at whatever periodicity you want.

Then you can filter for the almost nonexistant transactions 'on the
mark'.


> One possible issue is if I don't have a transaction exactly at the bar.  (More of a theoretical question.)  For example, If I have a transaction at 11:59:59, and then the next transaction is at 12:00:01.  Then no transaction occurred exactly on the 1 minute boundary.  I'm not sure the best way to handle this.
> 
> The general "big picture' concept is that a trading strategy might only want to trigger on 5 minute bars, but I'd like to keep updating some of my indicators as individual trades flow in.  

Use bids and offers.

> Thoughts?
> 
> 
> --
> 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



More information about the R-SIG-Finance mailing list