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

futures.expiry() fails #257

Closed
pjheink opened this issue Nov 13, 2018 · 4 comments
Closed

futures.expiry() fails #257

pjheink opened this issue Nov 13, 2018 · 4 comments
Assignees
Labels

Comments

@pjheink
Copy link

pjheink commented Nov 13, 2018

x is an xts time series and when calling: futures.expiry(x), a warning is thrown and the result is empty. I was expecting the indices of the futures expiration dates.

It seems that the months.xts() function (from months.R) isn't defined in my session (although futures.expiry() is defined). I can work around the problem by redefining futures.expiry() as:

futures.expiry <- function (x) {
  which(format(index(x), "%d") > 14 &
        format(index(x), "%d") < 22 &
        format(index(x), "%w") == 5 &
        as.numeric(format(index(x), "%m")) %in% c(3, 6, 9, 12)
        )
}

Here's a minimal session that reproduces the problem on my system:

library(quantmod)
x <- getSymbols("^GSPC", from="2018-09-06", to="2018-10-01", auto.assign=F)
futures.expiry(x)

This results in the following:

integer(0)
Warning message:
In as.numeric(months(x, TRUE)) %in% c(3, 6, 9, 12) :
  NAs introduced by coercion

Session Info:

R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] quantmod_0.4-13 TTR_0.23-4      xts_0.11-2      zoo_1.8-4      

loaded via a namespace (and not attached):
[1] compiler_3.4.0  tools_3.4.0     curl_3.2        yaml_2.2.0      grid_3.4.0      lattice_0.20-35
joshuaulrich added a commit that referenced this issue Nov 14, 2018
It's not clear how long these functions have been broken. The source of
the break started in 2008, when Jeff removed the generics and methods
for years(), quarters(), months(), etc. This might have been okay for
awhile, but perhaps S3 dispatch has become more restrictive since then
(e.g. a guess: methods in packages must be registered, not just named
like a S3 method).

The fix appears to be simple: use .indexmon() to replace the defunct
months.xts() method that isn't registered. Also delete the months.xts()
method to avoid more confusion.

Fixes #257.
@joshuaulrich
Copy link
Owner

Thanks for the report! It looks like the cause of this issue was removing S3 generics and methods for months(), years(), etc. back in 2008. This might have been okay for awhile, but S3 method dispatch may have become more restrictive over the years (e.g. -- and this is a guess -- methods in packages must be registered, not just named like a S3 method).

I just pushed a commit. I would really appreciate if you could test it to ensure it works for your situation!

@joshuaulrich joshuaulrich self-assigned this Nov 14, 2018
@pjheink
Copy link
Author

pjheink commented Nov 14, 2018

I installed quantmod from the 257-expiry branch and the futures.expiry() function works just fine now. Thanks!

@pjheink pjheink closed this as completed Nov 14, 2018
@pjheink
Copy link
Author

pjheink commented Nov 14, 2018

I'm not sure of the protocol... the problem seems to be fixed in the 257-expiry commit but should I have waited until you pushed this fix into the master before rating the problem Closed? Thanks!

@joshuaulrich
Copy link
Owner

Thanks for the testing and feedback! You don't need to close the issue. It would have been closed when I merged the branch into master. No worries though!

@joshuaulrich joshuaulrich added this to the Release 0.4-14 milestone Nov 24, 2018
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

2 participants