[R-SIG-Finance] Discretising intra-day data -- how to get by with less memory?
Ajay Shah
ajayshah at mayin.org
Fri Nov 27 12:56:52 CET 2009
I'm using this function to convert intra-day data into a grid with an
observation each N seconds:
# This function consumes "z" a zoo object where timestamps are intraday
# and a period for discretisation Nseconds.
# The key ideas are from this thread:
# https://stat.ethz.ch/pipermail/r-sig-finance/2009q4/005144.html
intraday.discretise <- function(z, Nseconds) {
toNsec <- function(x) as.POSIXct(Nseconds*ceiling(as.numeric(x)/Nseconds),
origin = "1970-01-01")
d <- aggregate(z, toNsec, tail, 1)
# At this point there is one problem: NA records are not created
# for blocks of time in which there were no records.
# To solve this:
dreg <- as.zoo(as.ts(d))
class(time(dreg)) <- class(time(d))
dreg
}
This works correctly but it's incredibly memory-intensive. I'm running
out of core in running this for some problems.
Is there a way to write this which would use less RAM?
--
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