Discretising intra-day data using zoo?
See the aggregate.zoo example in vignette("zoo-quickref") but round up
to the next 4 seconds instead of next Friday:
to4sec <- function(x) as.POSIXct(4*ceiling(as.numeric(x)/4), origin = "1970-01-01") aggregate(demo, to4sec, tail, 1)
spread ltp 2009-02-16 05:00:04 0.0050 48.715 2009-02-16 05:00:08 0.0025 48.715 2009-02-16 05:00:12 0.0025 48.715 2009-02-16 05:00:16 0.0025 48.715
On Sun, Nov 8, 2009 at 2:10 AM, Ajay Shah <ajayshah at mayin.org> wrote:
Folks,
I have a zoo object where the time-stamps are intra-day with
sub-second resolution. Can you take a look:
?library(zoo)
?print(load(url("http://www.mayin.org/ajayshah/tmp/demo.rda")))
?options("digits.secs"=6)
?head(demo)
?tail(demo)
My question is: How do I force this down to a uniform grid of (say)
four second resolution. In that case, we'd have readings for
? ?10:30:00
? ?10:30:04
? ?10:30:08
? ?10:30:12
out of this dataset. As with the standard
?zoo::aggregate(blah, tail, 1)
we'd take the last available record as of 10:30:08 and put this
information for that timepoint.
Suppose there is not a single record in the raw data from 10:30:04 to
10:30:09. Despite this, the resulting object should contain a record
for 10:30:08 with NA values (which can then be filled out e.g. using
na.locf()). How would we do this? This problem is not present in this
data, where records are plentiful. But discretisation code should be
general and handle this case right.
--
Ajay Shah ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?http://www.mayin.org/ajayshah
ajayshah at mayin.org ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.
_______________________________________________ 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.