Skip to content

Aggregating 15 minute xts sequence to hourly

5 messages · Joshua Ulrich, Costas Vorlow

#
On Mon, Jun 16, 2014 at 3:41 AM, Costas Vorlow <costas.vorlow at gmail.com> wrote:
The "00" time is the beginning of the hour, not the end.  E.g.,
10:00:00 is the beginning of the 10-o'clock hour.
Again, those are the beginnings of the hours.  endpoints() and
period.apply() only use the timestamps in your data.  If you want to
round up to the beginning of the next hour, use align.time().
[,1]
2012-05-02 10:00:00    6
2012-05-02 11:00:00   22
2012-05-02 12:00:00   38
2012-05-02 13:00:00   54
2012-05-02 14:00:00   70
2012-05-02 15:00:00   86
2012-05-02 16:00:00  102
2012-05-02 17:00:00  118
2012-05-02 18:00:00  134
2012-05-02 19:00:00  150
2012-05-02 20:00:00   40
Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
1 day later
#
On Mon, Jun 16, 2014 at 7:04 AM, Costas Vorlow <costas.vorlow at gmail.com> wrote:
You still seem to think the "00" time is the end of the hour, but it's
not; it's the beginning.  The first 3 rows of 'observation' contain
data for the first hour (9 o'clock).  The fourth row is the beginning
of the second hour (10 o'clock).
ends <- endpoints(observation,'hours')+1

The above doesn't work because endpoints always includes the last
observation, which is now out of bounds.  You would need to adjust the
first and last 'ends' values.

ends <- endpoints(observation,'hours')+1
ends[1] <- 0
ends[length(ends)] <- nrow(observation)
ends <- unique(ends)
temp <- period.apply(observation, ends, sum)

Be very careful with the results in this 'temp' object though.  If you
merge it with another xts object, you will have a look-ahead bias
because you will know the aggregate for the time period before it has
occurred.