-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
getOptionChain does not pull down last trade date and implied volatility from Yahoo #304
Comments
I can add IV, but last trade is already returned in the oc <- quantmod::getOptionChain("SPY")
head(oc$puts)
Strike Last Chg Bid Ask Vol OI
SPY200518P00140000 140 0.01 0 0 0.01 1 844
SPY200518P00145000 145 0.06 0 0 0.01 3 50
SPY200518P00150000 150 0.01 0 0 0.01 2 1125
SPY200518P00155000 155 0.04 0 0 0.01 1 16
SPY200518P00160000 160 0.01 0 0 0.01 40 166
SPY200518P00165000 165 0.01 0 0 0.01 1 96 Maybe you meant |
Yes, you are correct, I do mean lastTradeDate. Both that and IV have value. Thank you! |
Just a heads up, I downloaded the github version of quantmod and am now running into issues with getOptionChain. Trying to run the following command: spy_chain = getOptionChain('SPY','2020') returns the error: Error in class(xx) <- cl : attempt to set an attribute on NULL If I tried to pull options for AAPL rather than SPY there didn't seem to be any issue there. |
Thanks for testing, and thanks for the report! I can replicate, and it looks like it's because the R> spy_chain = quantmod::getOptionChain('SPY','2020')
## Error in class(xx) <- cl : attempt to set an attribute on NULL
R> traceback()
## 6: .POSIXct(dftables$calls$lastTradeDate, tz = tz)
## 5: FUN(X[[i]], ...)
## 4: lapply(expiry.subset, getOptionChain.yahoo, Symbols = Symbols,
## .expiry.known = TRUE)
## 3: getOptionChain.yahoo(Symbols = "SPY", Exp = "2020")
## 2: do.call(Call, list(Symbols = Symbols, Exp = Exp, ...))
## 1: quantmod::getOptionChain("SPY", "2020")
R> .POSIXct
## function (xx, tz = NULL, cl = c("POSIXct", "POSIXt"))
## {
## class(xx) <- cl ## <- this line throws the error because 'xx' is NULL
## attr(xx, "tzone") <- tz
## xx
## }
## <bytecode: 0x5644f9943b28>
## <environment: namespace:base> I will fix. Thanks again! |
Converting the trade time to the exchange timezone before calling NewToOld() would throw an error when there was no lastTradeDate column, because of the call to .POSIXct(NULL). Add a 'tz' argument to NewToOld(), so we can pass in the exchange timezone. Now the call to .POSIXct() is after adding a 'LastTradeTime' column, and a call to .POSIXct(NA) does not throw an error. The obsolete code was necessary when we were scraping HTML and is no longer needed now that we're parsing JSON. Replace the call to mapply() with lapply(), since we are only looping over one list. We don't need gsub() to remove commas, because jsonlite::fromJSON() will return integers and numbers when applicable. We don't need to call type.convert() for the same reason. Plus it would convert the datetimes to character. See #304.
@rjvelasquezm this should be fixed in master now. |
Awesome, thanks a lot!! |
Description
getOptionChain from CRAN does not pull last trade or implied volatility from Yahoo.
Expected behavior
Both ot these should be pulled since they are useful.
Minimal, reproducible example
getOptionChain("SPY")
The text was updated successfully, but these errors were encountered: