Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #2691] Odd behavior in to.monthly #15

Closed
joshuaulrich opened this issue Feb 26, 2015 · 0 comments
Closed

[R-Forge #2691] Odd behavior in to.monthly #15

joshuaulrich opened this issue Feb 26, 2015 · 0 comments
Labels

Comments

@joshuaulrich
Copy link
Owner

Submitted by: john eckstein
Assigned to: Joshua Ulrich
R-Forge link

I have data which I pass through to.monthly with the goal of selecting the last data of the month. Sometimes the original data is of monthly periodicity, so in this case its just for convenience in aligning disparate data. When the only data point in a month is the first day of the month, to.monthly aligns on the last day of the previous month, causing nasty bugs. here is an example:

y <- xts(1:4, order.by=as.Date(c('2001-07-02', '2001-08-01', '2001-09-03', '2001-10-01')))
y.monthends <- to.monthly(y[,1], indexAt='lastof')[,4]

y.monthends then contains:
y[, 1].Close
2001-07-31 1
2001-07-31 2
2001-09-30 3
2001-09-30 4

I have a workaround but it seems like this is something that should be fixed.
I am working on windows 7, R 2.15.2, xts 0.9-3

Followups:

Date: 2013-04-22 02:04
Sender: Garrett See
This is a timezone issue. Essentially, it is doing the following, then extracting the month and adding 1 to it.

as.POSIXlt(c(.index(y)), origin='1970-01-01')
[1] '2001-07-01 19:00:00 CDT' '2001-07-31 19:00:00 CDT'
[3] '2001-09-02 19:00:00 CDT' '2001-09-30 19:00:00 CDT'

It should work as expected if the as.POSIXlt call used the indexTZ of the input. e.g.

as.POSIXlt(c(.index(y)), origin='1970-01-01', tz=indexTZ(y))
[1] '2001-07-02 UTC' '2001-08-01 UTC' '2001-09-03 UTC' '2001-10-01 UTC'

I submitted a possible patch: https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2710&group_id=118&atid=518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant