joshuaulrich / quantmod

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

getSymbols.yahoo failing to download #313

Closed mcfsalla closed 3 years ago

mcfsalla commented 3 years ago

Description

I'm getting the following error message: Warning: Unable to import "ticker". Timeout was reached...

Expected behavior

A time series of each selected asset.

Minimal, reproducible example

[Insert sample data and code]

Session Info

portfolioPrices <- NULL
for (ticker in unique(
  c(tickers, tickers2, tickers3, tickers4, top_tickers, hedge_tickers))) {
  portfolioPrices <- cbind(portfolioPrices,
                           getSymbols.yahoo(test, periodicity = "daily", 
                                            auto.assign = FALSE)[, 6])
}
joshuaulrich commented 3 years ago

Your example isn't reproducible. I need something I can copy/paste into my R session to get the same results.

Also, your getSymbols() call uses test, not ticker. That could be the cause of your error. Please provide the output of sessionInfo() if it is not the cause.

I think you need something like this:

  portfolioPrices <- cbind(portfolioPrices,
            Ad(getSymbols(ticker, auto.assign = FALSE)))
mcfsalla commented 3 years ago

This is the correct script:

portfolioPrices <- NULL for (ticker in unique( c(tickers, tickers2, tickers3, tickers4, top_tickers, hedge_tickers))) { portfolioPrices <- cbind(portfolioPrices, getSymbols.yahoo(ticker, periodicity = "daily", auto.assign = FALSE)[, 6]) }

I've been running it like this for years, I guess we have an issue with yahoo website....

sessionInfo() output:

R version 4.0.2 (2020-06-22) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252

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

other attached packages: [1] magrittr_1.5 EIAdata_0.1.1 XML_3.99-0.5
[4] Quandl_2.10.0 riingo_0.3.0 ggrepel_0.8.2
[7] lubridate_1.7.9 GGally_2.0.0 PerformanceAnalytics_2.0.4 [10] quantmod_0.4.17.1 TTR_0.24.0 xts_0.12-0
[13] zoo_1.8-8 forcats_0.5.0 stringr_1.4.0
[16] dplyr_1.0.1 purrr_0.3.4 readr_1.3.1
[19] tidyr_1.1.1 tibble_3.0.3 ggplot2_3.3.2
[22] tidyverse_1.3.0 fPortfolio_3042.83.1 fAssets_3042.84
[25] fOptions_3042.86 fBasics_3042.89.1 timeSeries_3062.100
[28] timeDate_3043.102 rugarch_1.4-4

loaded via a namespace (and not attached): [1] colorspace_1.4-1 fMultivar_3042.80.1 ellipsis_0.3.1
[4] mclust_5.4.6 rprojroot_1.3-2 fs_1.5.0
[7] rstudioapi_0.11 farver_2.0.3 remotes_2.2.0
[10] spd_2.0-1 fansi_0.4.1 mvtnorm_1.1-1
[13] xml2_1.3.2 mnormt_2.0.1 robustbase_0.93-6
[16] knitr_1.29 pkgload_1.1.0 jsonlite_1.7.0
[19] nloptr_1.2.2.2 broom_0.7.0 kernlab_0.9-29
[22] dbplyr_1.4.4 compiler_4.0.2 httr_1.4.2
[25] backports_1.1.7 assertthat_0.2.1 Matrix_1.2-18
[28] cli_2.0.2 htmltools_0.5.0 prettyunits_1.1.1
[31] tools_4.0.2 ecodist_2.0.5 gtable_0.3.0
[34] glue_1.4.1 Rcpp_1.0.5 slam_0.1-47
[37] cellranger_1.1.0 vctrs_0.3.2 rneos_0.4-0
[40] xfun_0.16 GeneralizedHyperbolic_0.8-4 ps_1.3.4
[43] testthat_2.3.2 spatial_7.3-12 rvest_0.3.6
[46] lifecycle_0.2.0 devtools_2.3.1 DEoptimR_1.0-8
[49] MASS_7.3-51.6 scales_1.1.1 DistributionUtils_0.6-0
[52] hms_0.5.3 fCopulae_3042.82.1 RColorBrewer_1.1-2
[55] yaml_2.2.1 curl_4.3 memoise_1.1.0
[58] SkewHyperbolic_0.4-0 mvnormtest_0.1-9 reshape_0.8.8
[61] stringi_1.4.6 desc_1.2.0 energy_1.7-7
[64] boot_1.3-25 pkgbuild_1.1.0 truncnorm_1.0-8
[67] rlang_0.4.7 pkgconfig_2.0.3 bitops_1.0-6
[70] Rsolnp_1.16 evaluate_0.14 lattice_0.20-41
[73] labeling_0.3 ks_1.11.7 processx_3.4.3
[76] tidyselect_1.1.0 plyr_1.8.6 R6_2.4.1
[79] generics_0.0.2 DBI_1.1.0 pillar_1.4.6
[82] haven_2.3.1 withr_2.2.0 sn_1.6-2
[85] RCurl_1.98-1.2 modelr_0.1.8 crayon_1.3.4
[88] Rglpk_0.6-4 utf8_1.1.4 KernSmooth_2.23-17
[91] tmvnsim_1.0-2 rmarkdown_2.3 usethis_1.6.1
[94] grid_4.0.2 readxl_1.3.1 blob_1.2.1
[97] callr_3.4.3 reprex_0.3.0 digest_0.6.25
[100] numDeriv_2016.8-1.1 stats4_4.0.2 munsell_0.5.0
[103] sessioninfo_1.1.1 quadprog_1.5-8

mcfsalla commented 3 years ago

You can try this simplified version:

portfolioPrices <- NULL for (ticker in c("AAPL", "CVX")) { portfolioPrices <- cbind(portfolioPrices, getSymbols.yahoo(ticker, periodicity = "daily", auto.assign = FALSE)[, 6]) }

joshuaulrich commented 3 years ago

That works for me...

pp <- xts(, .Date(integer(0)))
for (ticker in c("AAPL", "CVX")) {
    pp <- merge(pp, Ad(getSymbols(ticker, auto.assign = FALSE)))
}
head(pp)
##            AAPL.Adjusted CVX.Adjusted
## 2007-01-02      2.586245     42.66032
## 2007-01-03      2.643649     42.24556
## 2007-01-04      2.624823     42.40787
## 2007-01-07      2.637785     42.94885
## 2007-01-08      2.856907     42.45595
## 2007-01-09      2.993625     41.72259

The issue may be the Yahoo server you're being routed to. Try again in a few hours and see if it's still an issue.

mcfsalla commented 3 years ago

It seems to work after a few attempts this morning. Can I choose the server I want to be routed to?

joshuaulrich commented 3 years ago

Can I choose the server I want to be routed to?

No, that's determined by Yahoo's backend. You don't have control over which you're routed to. You can try doing things like clearing cookies, but that's not guaranteed to work.

I'm going to close, since this is working.