Reputation: 1016
I have a question about xts to.hourly
and split
methods. It seems that it assumes that if my timestamp is 12:00 that it means a minute 12:00-12:01. However my data provider has 11:59-12:00 in mind. I didn't find any parameters on this. Is the only solution to simply lag my time series by one minute?
Upvotes: 0
Views: 76
Reputation: 176648
Your question is actually about the endpoints
function, which is what to.hourly
, split.xts
, and several other functions use to define intervals.
The endpoints
function "assumes" that your timestamps are actual datetimes, and a time of 12:00:00 is the beginning of the 12 o'clock hour. If your data have 1-minute resolution, a time of 12:00:00 falls in the interval of 12:00:00.0-12:00:59.999.
There is no parameter you can change to make xts behave as if a time of 12:00:00 means anything other than what it actually is.
If you're certain that your data provider is putting a timestamp of 12:00 on data that occur in the interval of 11:59:00.0-11:59:59.999, then you might be able to simply subtract a small value from the xts object index.
# assuming 'x' is your xts object
.index(x) <- .index(x) - 0.001
That said, you need to think carefully about doing this because making a mistake can cause you to have look-ahead bias.
Upvotes: 1