[R-SIG-Finance] Rounding time series to nearest 5mn

Jeff Ryan jeff.a.ryan at gmail.com
Sun Feb 14 04:59:01 CET 2010


> I would like to quantize the time stamps so that 00:04:59 becomes 00:05:00, i.e. rounding the time series to the nearest (in this case) 5 minutes.
>

I general that is a bad idea, as you now have timestamps that refer to
data that occurs in the future.  Might look nice, but will likely cost
you money...

> What I could find on the net was the align function in the xts package. Unfortunately it doesnt really perform as expected: it has transformed a 5mn multiple timestamp (e.g. 00:00:00) into the next multiple (00:05:00). Moreover I understand that it always "round up" the time, rather than rounding to closest.

See above comment.  And per docs, it is as expected.

To clarify why 00:00:00 isn't set to 00:00:00, it is because the
function aggregates all values within the time block (5 min here) and
sets the time stamp to the beginning of the next block.  1:00:00 is
the start of the hour, and everything from that point onward to 1:05
(but not including) is pegged to 1:05.

Josh's reply should do what you want, but rounding down is a recipe
for disaster.

HTH
Jeff

>
>> tSerie_align<-align.time(tSerie, n=300)
>> head(tSerie_align)
>                    LAST
> 2009-12-15 00:05:00 "0.915447"
> 2009-12-15 00:05:00 "0.916005"
> 2009-12-15 00:10:00 "0.916167"
> 2009-12-15 00:20:00 "0.9162"
> 2009-12-15 00:25:00 "0.916188"
> 2009-12-15 00:25:00 "0.916265"
>
> Any ideas how I could transform this time series to look as follows:
>
>                    LAST
> 2009-12-15 00:00:00 "0.915447"
> 2009-12-15 00:05:00 "0.916005"
> 2009-12-15 00:10:00 "0.916167"
> 2009-12-15 00:15:00 "0.9162"
> 2009-12-15 00:20:00 "0.916188"
> 2009-12-15 00:25:00 "0.916265"
>
> Thank you in advance.
>
> /K
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list