[R-SIG-Finance] Discretising intra-day data using zoo?

Ajay Shah ajayshah at mayin.org
Sun Nov 8 08:10:05 CET 2009


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.



More information about the R-SIG-Finance mailing list