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

Kanin Kaninski kaninski2000 at yahoo.com
Sun Feb 14 04:07:18 CET 2010


Continuing on the learning path... I have the followig xts time series:

                    LAST      
2009-12-15 00:00:00 "0.915447"
2009-12-15 00:04:59 "0.916005"
2009-12-15 00:09:59 "0.916167"
2009-12-15 00:15:00 "0.9162"  
2009-12-15 00:20:00 "0.916188"
2009-12-15 00:24:59 "0.916265"

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.

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.

> 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



More information about the R-SIG-Finance mailing list