joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

allow to.period to operate on custom endpoint #302

Closed ethanbsmith closed 1 year ago

ethanbsmith commented 5 years ago

Description

I'd like to experiment with some analytics using alternate sampling frequencies. 2 examples are variants on 4 week periods, with periods always ending on Fridays.

z <- as.POSIXlt((as.Date("1900-01-01") + (0:(Sys.Date() - as.Date("1900-01-01")))))
z[z$wday == 5L & z$yday < 363L & z$yday %% 28L <= 6L]) #13, periods, with only the final final period of the year being > 4 weeks
z[z$wday == 5L & z$yday %% 28L <= 6L]) #exactly 4-week periods with periods in a years varying between 13 and 14

While i can calculate the endpoints quite easily, i can't find a way to integrate these into my other calculations and processes, without re-implementing most of the to.period function. Would it be possible to modify the to.period function to take a custom set of endpoints either as a new parameter, or overloading the existing period parameter?