joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
809 stars 223 forks source link

getOptionChain errors out #273

Closed viewasia closed 4 years ago

viewasia commented 5 years ago

Description

Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid, : object 'openinterest' not found

Expected behavior

Should return option chain given the time frame for specified symbol

Minimal, reproducible example

library(quantmod)
a <- getOptionChain("SPY", "2019/2020")

### Session Info
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] htmlwidgets_1.3      derivmkts_0.2.4      plumber_0.4.6        V8_2.1               stringi_1.4.3        rvest_0.3.4          xml2_1.2.0           stringr_1.4.0        magrittr_1.5        
[10] heatmaply_0.16.0     viridis_0.5.1        viridisLite_0.3.0    d3heatmap_0.6.1.2    rhandsontable_0.3.7  plotly_4.9.0         ggplot2_3.2.1        DT_0.8               lubridate_1.7.4     
[19] quantmod_0.4-15      TTR_0.23-4           xts_0.11-2           zoo_1.8-5            shinydashboard_0.7.1 shiny_1.3.2         

loaded via a namespace (and not attached):
 [1] httr_1.4.1         tidyr_0.8.3        jsonlite_1.6       foreach_1.4.7      gtools_3.8.1       assertthat_0.2.1   pillar_1.4.2       lattice_0.20-38    glue_1.3.1         digest_0.6.18     
[11] RColorBrewer_1.1-2 promises_1.0.1     colorspace_1.4-1   htmltools_0.3.6    httpuv_1.5.0       pkgconfig_2.0.2    purrr_0.3.2        xtable_1.8-4       scales_1.0.0       webshot_0.5.1     
[21] gdata_2.18.0       later_0.8.0        tibble_2.1.1       withr_2.1.2        lazyeval_0.2.2     mnormt_1.5-5       crayon_1.3.4       mime_0.6           MASS_7.3-51.3      gplots_3.0.1.1    
[31] tools_3.4.4        registry_0.5-1     data.table_1.12.0  munsell_0.5.0      cluster_2.0.7-1    compiler_3.4.4     caTools_1.17.1.2   rlang_0.3.1        grid_3.4.4         iterators_1.0.12  
[41] rstudioapi_0.10    bitops_1.0-6       base64enc_0.1-3    gtable_0.3.0       codetools_0.2-16   curl_3.3           TSP_1.1-6          R6_2.4.0           seriation_1.2-3    gridExtra_2.3     
[51] dplyr_0.8.0.1      KernSmooth_2.23-15 dendextend_1.12.0  Rcpp_1.0.1         png_0.1-7          gclus_1.3.2        tidyselect_0.2.5  
joshuaulrich commented 4 years ago

Sorry for my slow reply, and thanks for the report! I can replicate, and will investigate.

R> a <- quantmod::getOptionChain("SPY", "2019/2020")
Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid,  : 
  object 'openinterest' not found
viewasia commented 4 years ago

Likewise, for symbol 'V', package throws error Error in data.frame(Strike = strike, Last = lastprice, Chg = change, Bid = bid, : object 'volume' not found

Execution: getOptionChain("V", "2019/2020")

joshuaulrich commented 4 years ago

I just ran this code, and I can not replicate the issue.

R> tk <- c("SPY", "V", "MSFT", "F")
R> opts <- setNames(lapply(tk, getOptionChain, Exp = "2020"), tk)
R> lapply(opts, names)
$SPY
 [1] "Feb.24.2020" "Feb.26.2020" "Feb.28.2020" "Mar.02.2020" "Mar.04.2020"
 [6] "Mar.06.2020" "Mar.09.2020" "Mar.11.2020" "Mar.13.2020" "Mar.16.2020"
[11] "Mar.18.2020" "Mar.20.2020" "Mar.23.2020" "Mar.25.2020" "Mar.27.2020"
[16] "Mar.31.2020" "Apr.03.2020" "Apr.17.2020" "May.15.2020" "Jun.19.2020"
[21] "Jun.30.2020" "Jul.17.2020" "Sep.18.2020" "Sep.30.2020" "Oct.16.2020"
[26] "Nov.20.2020" "Dec.18.2020" "Dec.31.2020"

$V
 [1] "Feb.28.2020" "Mar.06.2020" "Mar.13.2020" "Mar.20.2020" "Mar.27.2020"
 [6] "Apr.03.2020" "May.15.2020" "Jun.19.2020" "Sep.18.2020" "Dec.18.2020"

$MSFT
 [1] "Feb.28.2020" "Mar.06.2020" "Mar.13.2020" "Mar.20.2020" "Mar.27.2020"
 [6] "Apr.03.2020" "Apr.17.2020" "May.15.2020" "Jun.19.2020" "Jul.17.2020"
[11] "Sep.18.2020" "Dec.18.2020"

$F
[1] "Feb.28.2020" "Mar.06.2020" "Mar.13.2020" "Mar.20.2020" "Mar.27.2020"
[6] "Apr.03.2020" "Jun.19.2020" "Sep.18.2020"

This suggests it was an intermittent problem with the Yahoo Finance servers, so I'm closing this issue.