On Mon, Jun 16, 2014 at 3:41 AM, Costas Vorlow <costas.vorlow at
gmail.com> wrote:> Dear all,
>
> Why aggregation of 15 minute xts data happens on the 45th (3rd quarter) and
> not the exact hour close (i.e., 00) time?
>
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.
> For example, temp below is an xts sequence with 15-minute frequency:
>
>> quarters <- ISOdatetime(2012,05,02,9,0,0) + seq(0:39)*15*60;
>> set.seed(42);
>> observation <- xts(1:40, order.by=as.POSIXct(quarters));
>> head(observation);
> [,1]
> 2012-05-02 09:15:00 1
> 2012-05-02 09:30:00 2
> 2012-05-02 09:45:00 3
> 2012-05-02 10:00:00 4
> 2012-05-02 10:15:00 5
> 2012-05-02 10:30:00 6
>
>> ends<-endpoints(observation,'hours');
>> temp<-period.apply(observation, ends,sum);
>> temp
> [,1]
> 2012-05-02 09:45:00 6
> 2012-05-02 10:45:00 22
> 2012-05-02 11:45:00 38
> 2012-05-02 12:45:00 54
> 2012-05-02 13:45:00 70
> 2012-05-02 14:45:00 86
> 2012-05-02 15:45:00 102
> 2012-05-02 16:45:00 118
> 2012-05-02 17:45:00 134
> 2012-05-02 18:45:00 150
> 2012-05-02 19:00:00 40
>>
>
> I get the sum of every quarter within the hour on the third quarter. How
> can I implicitly calculate the sum of the quarterly data on the hour's
> close (10:00, 11:00, 12:00 and so on) ?
>
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().
> align.time(temp, 3600)
[,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
> Many thanks in advance,
> Costas
>
> __________________________________________________________________
>
> *Costas Vorlow
> <http://www.gravatar.com/avatar/49a9dee59073b1ed4a36440a06aeb81b> *
> *http://www.linkedin.com/in/costasvorlow
> <http://www.linkedin.com/in/costasvorlow>*
> *http://www.vorlow.com* <http://www.vorlow.com>
>
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
>
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com