[R-SIG-Finance] Align 5 minute bars

Noah Silverman noahsilverman at ucla.edu
Fri Jun 17 04:54:59 CEST 2011


Good suggestion.  Exactly what I want.

However, in another message you suggested using aggregate or apply to generate my summary statistics.  I would need to do that before using to.period.  But, I want the summary states per-period.  (For example - number of transactions, number of up-ticks, etc.) 

The only way I can see to do this is the "long way".

1) Determine the endpoints of each bar, but don't convert to.period yet
2) Loop through each bar and generate the statistics from the transactions in that bar
3) Create a new data structure to hold the bar summaries

There must be a cleaner way.  Ideas?

--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095

On Jun 16, 2011, at 4:19 PM, Brian G. Peterson wrote:

> Your trade would have been *in* the bar.
> 
> typically, you'd use something of the type:
> 
> align.time(to.period(x,...)...) 
> 
> to first aggregate your trades into bars, and *then* align the bars.
> This doesn't create any look-ahead bias.
> 
>  - Brian
> 
> On Thu, 2011-06-16 at 13:29 -0700, Noah Silverman wrote:
>> Jeff,
>> 
>> If I understand the documentation correctly, align.time just shifts the time stamps of the existing bars.  That sounds dangerous as the individual ticks aren't moving.
>> 
>> For example, if a bar is currently set at:   18:39.46
>> We have a transaction at 18:39:48
>> As it stands, that transaction is in the *next* bar that would start at 18:39.47
>> If I use align.time, it will shift the bar to 18:40 BUT since we already have the OHLC summary, what happens to that transaction?
>> 
>> 
>> --
>> Noah Silverman
>> UCLA Department of Statistics
>> 8117 Math Sciences Building
>> Los Angeles, CA 90095
>> 
>> On Jun 16, 2011, at 12:40 PM, Jeff Ryan wrote:
>> 
>>> Look at align.time. Bars are stamped to the last obs in the period in to.period. 
>>> 
>>> HTH
>>> Jeff
>>> 
>>> Jeffrey Ryan    |    Founder    |    jeffrey.ryan at lemnica.com
>>> 
>>> www.lemnica.com
>>> 
>>> On Jun 16, 2011, at 2:25 PM, Noah Silverman <noahsilverman at ucla.edu> wrote:
>>> 
>>>> And another question...
>>>> 
>>>> When I use the xts function to.minutes5(), I get a nice OHLC summary, BUT the time stamps are "messy".  Since my first and/or last ticks are not exactly on the minute, every 5 minute bar is now on some mid-minute frequency. 
>>>> 
>>>> Example:
>>>> 
>>>> to.minutes5(ds, indexAt="endof")
>>>>                  ds.Open ds.High ds.Low ds.Close ds.Volume
>>>> 2007-01-01 18:34:44  882.50  883.75 880.50   880.50        83
>>>> 2007-01-01 18:39:46  880.75  881.00 880.00   880.50        18
>>>> 2007-01-01 18:44:52  880.25  880.25 879.50   880.00        25
>>>> 2007-01-01 18:49:03  880.25  881.75 880.25   881.50        83
>>>> 2007-01-01 18:52:11  881.50  881.50 881.50   881.50         9
>>>> 
>>>> 
>>>> 
>>>> Ideally, I'd love to have my bars aligned with round minute numbers.  i.e.
>>>> 18:30
>>>> 18:35
>>>> 18:40
>>>> etc...
>>>> 
>>>> Any suggestions?
>>>> 
>>>> --
>>>> 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.
>> 
>> _______________________________________________
>> 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