joshuaulrich / quantmod

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

getDividends throws error for stocks with no history of split #366

Closed chrischeungnf closed 1 year ago

chrischeungnf commented 1 year ago

Description

getDividends throws error for stocks with no history of split. One example is ABBV.

Minimal, reproducible example

> library(quantmod)
> getDividends("ABBV")
Error in merge.xts(close, splits, dividends) : no xts object to merge

Session Info

R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale:
[1] C

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

other attached packages:
[1] jsonlite_1.8.3    curl_4.3.3        quantmod_0.4.20.2 TTR_0.24.3        xts_0.12.2       
[6] zoo_1.8-11        dplyr_1.0.10      readxl_1.4.1     

loaded via a namespace (and not attached):
 [1] rstudioapi_0.14  magrittr_2.0.3   tidyselect_1.2.0 lattice_0.20-45  R6_2.5.1         rlang_1.0.6     
 [7] fansi_1.0.3      tools_4.1.2      grid_4.1.2       utf8_1.2.2       cli_3.4.1        DBI_1.1.3       
[13] remotes_2.4.2    assertthat_0.2.1 tibble_3.1.8     lifecycle_1.0.3  vctrs_0.5.0      glue_1.6.2      
[19] compiler_4.1.2   pillar_1.8.1     cellranger_1.1.0 generics_0.1.3   pkgconfig_2.0.3 

Offending line

R/getDividends.R Line 43 is the offending line as it leads to unadjusting dividends for splits even though there is no split. Changing the line to

if(!split.adjust && length(split.events) > 0) {

should resolve the problem.

Best regards, Chris

joshuaulrich commented 1 year ago

Thanks for the report! I can replicate. I also found lots of other issues... I'll fix those too.