joshuaulrich / quantmod

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

Error: argument "conn" is missing, with no default #323

Closed sillasgonzaga closed 3 years ago

sillasgonzaga commented 3 years ago

Description

I'm trying to run getSymbos.yahoo() for this specific ticker but it returns an error, even though it can be found on Yahoo Finance :

Minimal, reproducible example

getSymbols.yahoo("BIYW39.SA", auto.assign = FALSE)

Output:


> getSymbols.yahoo("BIYW39.SA", auto.assign = FALSE)
Warning: BIYW39.SA download failed; trying again.
Warning: Unable to import “BIYW39.SA”.
argument "conn" is missing, with no default
[1] "Error in open.connection(file, \"rt\") : HTTP error 404.\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in open.connection(file, "rt"): HTTP error 404.>

Session Info

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C               LC_TIME=pt_BR.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=pt_BR.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] timetk_2.6.0       quantmod_0.4.18    TTR_0.24.2         xts_0.12.1        
 [5] zoo_1.8-8          DBI_1.1.1          RSQLite_2.2.1      lubridate_1.7.9.2 
 [9] googlesheets_0.3.0 forcats_0.5.0      stringr_1.4.0      dplyr_1.0.2       
[13] purrr_0.3.4        readr_1.4.0        tidyr_1.1.2        tibble_3.0.5      
[17] ggplot2_3.3.2      tidyverse_1.3.0   

loaded via a namespace (and not attached):
 [1] fs_1.5.0           bit64_4.0.5        httr_1.4.2         tools_4.0.3       
 [5] backports_1.2.1    utf8_1.1.4         R6_2.5.0           rpart_4.1-15      
 [9] colorspace_2.0-0   nnet_7.3-14        withr_2.3.0        tidyselect_1.1.0  
[13] rematch_1.0.1      bit_4.0.4          curl_4.3           compiler_4.0.3    
[17] cli_2.2.0          rvest_0.3.6        xml2_1.3.2         scales_1.1.1      
[21] askpass_1.1        digest_0.6.27      rmarkdown_2.6      pkgconfig_2.0.3   
[25] htmltools_0.5.0    parallelly_1.22.0  dbplyr_2.0.0       rlang_0.4.10      
[29] readxl_1.3.1       rstudioapi_0.13    generics_0.1.0     jsonlite_1.7.2    
[33] magrittr_2.0.1     Matrix_1.3-2       Rcpp_1.0.6         munsell_0.5.0     
[37] fansi_0.4.2        lifecycle_0.2.0    furrr_0.2.1        stringi_1.5.3     
[41] yaml_2.2.1         snakecase_0.11.0   MASS_7.3-53        recipes_0.1.15    
[45] grid_4.0.3         blob_1.2.1         parallel_4.0.3     listenv_0.8.0     
[49] crayon_1.3.4       lattice_0.20-41    haven_2.3.1        splines_4.0.3     
[53] hms_0.5.3          knitr_1.30         pillar_1.4.7       codetools_0.2-18  
[57] reprex_0.3.0       glue_1.4.2         evaluate_0.14      rsample_0.0.8     
[61] modelr_0.1.8       vctrs_0.3.6        cellranger_1.1.0   gtable_0.3.0      
[65] openssl_1.4.3      future_1.21.0      assertthat_0.2.1   xfun_0.20         
[69] gower_0.2.2        janitor_2.0.1      prodlim_2019.11.13 broom_0.7.3       
[73] class_7.3-17       survival_3.2-7     timeDate_3043.102  tinytex_0.28      
[77] memoise_1.1.0      lava_1.6.8.1       globals_0.14.0     ellipsis_0.3.1    
[81] ipred_0.9-9       
joshuaulrich commented 3 years ago

HTTP 404 means the site is not found. That's most likely because Yahoo doesn't provide historical data for that ticker.

The Yahoo Finance page itself suggests that too. https://finance.yahoo.com/quote/BIYW39.SA/history?p=BIYW39.SA

So there's nothing I can fix here.

sillasgonzaga commented 3 years ago

That's a pity. Thanks for the quick reply.

aqsmith08 commented 3 years ago

@sillasgonzaga Did you figure out a solution here? I'm curious since I'm hitting a similar issue. Here's an example:

stock.list <- c("AAPL", "GFL.TO","RICHT.BD")
stock.df <- tidyquant::tq_get(stock.list, get = "stock.prices",
                              from = "2021-06-17", to = "2021-06-22")

It returns:

There were 50 or more warnings (use warnings() to see the first 50)

When I run warnings(), I see:

Warning messages:
1: Problem with `mutate()` column `data..`.
ℹ `data.. = purrr::map(...)`.
ℹ x = 'REAL.TO', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "REAL.TO", env = <environment>, verbose = FALSE, : Unable to import “REAL.TO”.
Operation was aborted by an application callback
 Removing REAL.TO.
2: Problem with `mutate()` column `data..`.
ℹ `data.. = purrr::map(...)`.
ℹ x = 'YRI.TO', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "YRI.TO", env = <environment>, verbose = FALSE, : Unable to import “YRI.TO”.
argument "conn" is missing, with no default
 Removing YRI.TO.

etc

It eventually stops running my scripts (which is trying to get a lot of stock quotes) with Execution halted. I'd love to figure out how I can run this and handle the warning where it doesn't break my script.

Note - I know that I'm using tidyquant and not quantmod but it seems like we're both facing the same problem with the Yahoo Finance API.

joshuaulrich commented 3 years ago

@aqsmith08 the error was improved in #333. You're using tidyquant, but tq_get() is basically a wrapper around getSymbols(). It's not a different implementation.

Try the latest development version of quantmod and see what the actual error is. If it's HTTP 404, there's nothing I can do. That means Yahoo doesn't have historical data for the stock.

aqsmith08 commented 3 years ago

Thanks @joshuaulrich. It does look to be the HTTP 404.

> getSymbols.yahoo("RICHT.BD", auto.assign = FALSE)
Warning: RICHT.BD download failed; trying again.
Warning: Unable to import “RICHT.BD”.
argument "conn" is missing, with no default
[1] "Error in open.connection(file, \"rt\") : HTTP error 404.\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in open.connection(file, "rt"): HTTP error 404.>

I'll consider creating a blacklist of stock tickers and filter them out prior to running them through Yahoo Finance or consider another data source. Appreciate your quick reply!

IanWorthington commented 3 years ago

I had this exact same problem when calling with to="", which used to work. Removing the parameter and letting it default fixed my problem.

Don't know if that's a clue?

joshuaulrich commented 3 years ago

@IanWorthington did you encounter this in the latest development version? It should be fixed.

andreww2000 commented 3 years ago

getSymbols("BTC-USD") Warning: BTC-USD download failed; trying again. Error in getSymbols.yahoo(Symbols = "BTC-USD", env = , verbose = FALSE, : Unable to import “BTC-USD”. argument "conn" is missing, with no default

andreww2000 commented 3 years ago

This issue does not occur when using the get symbols sourced to FRED

joshuaulrich commented 3 years ago

This issue does not occur when using the get symbols sourced to FRED

Right. It's specific to Yahoo. It shouldn't occur for any other source.

BTC-USD works for me. Your issue might have been a temporary issue with Yahoo, or something specific to your setup.

R$ quantmod::getSymbols("BTC-USD")                                                                         
[1] "BTC-USD"
Warning message:
BTC-USD contains missing values. Some functions will not work if objects contain missing values in the
middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them. 
R$ head(`BTC-USD`)                                                                                         
           BTC-USD.Open BTC-USD.High BTC-USD.Low BTC-USD.Close BTC-USD.Volume BTC-USD.Adjusted
2014-09-17      465.864      468.174     452.422       457.334       21056800          457.334
2014-09-18      456.860      456.860     413.104       424.440       34483200          424.440
2014-09-19      424.103      427.835     384.532       394.796       37919700          394.796
2014-09-20      394.673      423.296     389.883       408.904       36863600          408.904
2014-09-21      408.085      412.426     393.181       398.821       26580100          398.821
2014-09-22      399.100      406.916     397.130       402.152       24127600          402.152
andreww2000 commented 3 years ago

This issue does not occur when using the get symbols sourced to FRED

Right. It's specific to Yahoo. It shouldn't occur for any other source.

BTC-USD works for me. Your issue might have been a temporary issue with Yahoo, or something specific to your setup.

R$ quantmod::getSymbols("BTC-USD")                                                                         
[1] "BTC-USD"
Warning message:
BTC-USD contains missing values. Some functions will not work if objects contain missing values in the
middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them. 
R$ head(`BTC-USD`)                                                                                         
           BTC-USD.Open BTC-USD.High BTC-USD.Low BTC-USD.Close BTC-USD.Volume BTC-USD.Adjusted
2014-09-17      465.864      468.174     452.422       457.334       21056800          457.334
2014-09-18      456.860      456.860     413.104       424.440       34483200          424.440
2014-09-19      424.103      427.835     384.532       394.796       37919700          394.796
2014-09-20      394.673      423.296     389.883       408.904       36863600          408.904
2014-09-21      408.085      412.426     393.181       398.821       26580100          398.821
2014-09-22      399.100      406.916     397.130       402.152       24127600          402.152

Thanks a lot for the reply. Its definitely due to my PC, my other computer runs it fine. When I first installed Quantmod on this PC it wouldnt load the most recent version. Any insight as to why my setup is experiencing this error with Yahoo?

ScharanCysne commented 3 years ago

Hey guys, just wanna comment that I solved this issue in my script by changing auto.assign to FALSE.

Example

From this:

getSymbols("KO", src = "yahoo", from = "2021-01-19", to = "2021-06-18", auto.assign = TRUE)

To this:

ko.data <- getSymbols("KO", src = "yahoo", from = "2021-01-19", to = "2021-06-18", auto.assign = FALSE)

It solved for me, maybe for some of you will too.