Rounding time series to nearest 5mn
On Sat, Feb 13, 2010 at 9:07 PM, Kanin Kaninski <kaninski2000 at yahoo.com> wrote:
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.
It performs exactly as documented. Is that really unfortunate or unexpected?
"Description:
Change timestamps to the start of the next period, specified in
multiples of seconds."
[snip]
"Details:
This function is an S3 generic. The result is to round up to the
next period determined by ?n modulo x?."
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"
Make a new xts object:
new.tSerie <- xts(coredata(tSerie),index(tSerie)-1)
align.time(new.tSerie)
[,1]
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.916200
2009-12-15 00:20:00 0.916188
2009-12-15 00:25:00 0.916265
Best,
Josh
--
http://www.fosstrading.com
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.