Skip to content
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

Only part of dividends history received when calling getDividends() #372

Closed
SamoPP opened this issue Feb 27, 2023 · 1 comment
Closed

Only part of dividends history received when calling getDividends() #372

SamoPP opened this issue Feb 27, 2023 · 1 comment
Assignees
Labels

Comments

@SamoPP
Copy link

SamoPP commented Feb 27, 2023

Description

When calling getDividends only part of historical data about dividends is returned.

Expected behavior

All dividends for particular symbol should be returned.

Minimal, reproducible example

R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(quantmod)
Loading required package: xts
Loading required package: zoo

Attaching package:zooThe following objects are masked frompackage:base:

    as.Date, as.Date.numeric


################################### WARNING ###################################
# We noticed you have dplyr installed. The dplyr lag() function breaks how    #
# base R's lag() function is supposed to work, which breaks lag(my_xts).      #
#                                                                             #
# If you call library(dplyr) later in this session, then calls to lag(my_xts) #
# that you enter or source() into this session won't work correctly.          #
#                                                                             #
# All package code is unaffected because it is protected by the R namespace   #
# mechanism.                                                                  #
#                                                                             #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
#                                                                             #
# You can use stats::lag() to make sure you're not using dplyr::lag(), or you #
# can add conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop   #
# dplyr from breaking base R's lag() function.                                #
################################### WARNING ###################################
Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
> 
> GSY <- getSymbols("GSY", from="1990-01-01", auto.assign=FALSE)
> GSY.dividends <- getDividends("GSY")
> print(GSY.dividends)
           GSY.div
2008-03-25   0.135
2008-04-24   0.085
2008-05-23   0.078
2008-06-24   0.081
2008-07-25   0.077
2008-08-25   0.073
2008-09-24   0.081
2008-10-27   0.080
2008-11-21   0.048
2008-12-24   0.168
2009-01-26   0.031
2009-02-23   0.023
2009-03-25   0.017
2009-04-24   0.017
2009-05-22   0.014
2009-06-24   0.011
2009-07-27   0.005
2009-08-25   0.003
2009-09-24   0.001
2010-12-27   0.005
2011-07-01   0.005
2011-08-01   0.018
2011-09-01   0.024
2011-10-03   0.022
2011-11-01   0.025
2011-12-01   0.024
2011-12-28   0.039
2012-02-01   0.010
2012-03-01   0.005
2012-04-02   0.014
2012-05-01   0.017
2012-06-01   0.018
2012-07-02   0.019
2012-08-01   0.019
2012-09-04   0.020
2012-10-01   0.026
2012-11-01   0.038
2012-12-03   0.055
2012-12-27   0.117
2013-02-01   0.042
2013-03-01   0.056
2013-04-01   0.051
2013-05-01   0.055
2013-06-03   0.047
2013-07-01   0.039
2013-08-01   0.042
2013-09-03   0.038
2013-10-01   0.037
2013-11-01   0.042
2013-12-02   0.039
2013-12-27   0.091
2014-02-03   0.032
2014-03-03   0.033
2014-04-01   0.041
2014-05-01   0.036
2014-06-02   0.046
2014-07-01   0.047
2014-08-01   0.048
2014-09-02   0.044
2014-10-01   0.044
2023-02-21   0.141
> dput(GSY.dividends)
structure(c(0.135, 0.085, 0.078, 0.081, 0.077, 0.073, 0.081, 
0.08, 0.048, 0.168, 0.031, 0.023, 0.017, 0.017, 0.014, 0.011, 
0.005, 0.003, 0.001, 0.005, 0.005, 0.018, 0.024, 0.022, 0.025, 
0.024, 0.039, 0.01, 0.005, 0.014, 0.017, 0.018, 0.019, 0.019, 
0.02, 0.026, 0.038, 0.055, 0.117, 0.042, 0.056, 0.051, 0.055, 
0.047, 0.039, 0.042, 0.038, 0.037, 0.042, 0.039, 0.091, 0.032, 
0.033, 0.041, 0.036, 0.046, 0.047, 0.048, 0.044, 0.044, 0.141
), class = c("xts", "zoo"), dim = c(61L, 1L), index = structure(c(1206403200, 
1208995200, 1211500800, 1214265600, 1216944000, 1219622400, 1222214400, 
1225065600, 1227225600, 1230076800, 1232928000, 1235347200, 1237939200, 
1240531200, 1242950400, 1245801600, 1248652800, 1251158400, 1253750400, 
1293408000, 1309478400, 1312156800, 1314835200, 1317600000, 1320105600, 
1322697600, 1325030400, 1328054400, 1330560000, 1333324800, 1335830400, 
1338508800, 1341187200, 1343779200, 1346716800, 1349049600, 1351728000, 
1354492800, 1356566400, 1359676800, 1362096000, 1364774400, 1367366400, 
1370217600, 1372636800, 1375315200, 1378166400, 1380585600, 1383264000, 
1385942400, 1388102400, 1391385600, 1393804800, 1396310400, 1398902400, 
1401667200, 1404172800, 1406851200, 1409616000, 1412121600, 1676937600
), tzone = "UTC", tclass = "Date"), dimnames = list(NULL, "GSY.div"))
> GSY.dividends <- getDividends("GSY", from="2022-01-01")
> print(GSY.dividends)
           GSY.div
2022-01-24   0.020
2022-02-22   0.020
2022-03-21   0.023
2022-04-18   0.029
2023-02-21   0.141
> dput(GSY.dividends)
structure(c(0.02, 0.02, 0.023, 0.029, 0.141), class = c("xts", 
"zoo"), dim = c(5L, 1L), index = structure(c(1642982400, 1645488000, 
1647820800, 1650240000, 1676937600), tzone = "UTC", tclass = "Date"), dimnames = list(
    NULL, "GSY.div"))

Session Info

> sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 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/liblapack.so.3

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

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

other attached packages:
[1] quantmod_0.4.20.2 TTR_0.24.3        xts_0.13.0        zoo_1.8-11       

loaded via a namespace (and not attached):
[1] compiler_4.2.2  tools_4.2.2     rstudioapi_0.14 curl_5.0.0      grid_4.2.2      jsonlite_1.8.4 
[7] lattice_0.20-45
@joshuaulrich
Copy link
Owner

Thanks for the report! Looks like this is because the interval parameter in the request is set to "3mo" (3 months) and this security has dividends monthly.

I get all the values when I set the interval parameter to "1mo", "5d", or "1d". I hesitate to use "1d" or even "5d" because the response contains all the OHLCV data even though we only want dividends.

@joshuaulrich joshuaulrich self-assigned this Feb 27, 2023
@joshuaulrich joshuaulrich added this to the 0.4.21 milestone Mar 27, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 12, 2023
### Changes in 0.4.22 (2023-04-05)

1. Move jsonlite from Suggests to Imports so it doesn't cause a problem
    when a package that doesn't also Suggest jsonlite uses getSymbols().
    Thanks to Kurt Hornik for the report and fix!
    [#380](joshuaulrich/quantmod#380)

### Changes in 0.4.21 (2023-03-29)

1. Fix S3 method issues. R-devel (83995-ish) added a check for possible S3
    method issues. Register methods it found that were not registered:
    `str.replot()`, `seriesHi.timeSeries()`, and `seriesLo.timeSeries()`.

    It was also confused by `range.bars()` and `unique.formula.names()`. Remove
    `unique.formula.names()` because it wasn't exported or used internally.
    Rename `range.bars()` to `rangeBars()`, which isn't exported.

    Thanks to Kurt Hornik for the report!
    [#375](joshuaulrich/quantmod#375)

1. Remove "^" prefix from `getSymbols()` return value. When the 'Symbols'
    argument has a "^" prefix and `auto.assign = TRUE`:

    * `getSymbols()` removes the "^" from the object it creates, but
    * returns the 'Symbols' argument unchanged, and
    * removes the "^" from the column names of the object it creates.

    The example below will create an object named `IXIC` but the value of
    `sym` will be "^IXIC".

        sym <- getSymbols("^IXIC")

    That means `x <- get(sym)` will not work because an object named `^IXIC`
    doesn't exist.
    [#371](joshuaulrich/quantmod#371)

1. Add 'from' and 'to' arguments to `getSymbols.FRED()`. Users expect to be
    able to set the 'from' and 'to' arguments for FRED data like they can for
    Yahoo data. Those values were ignored and the entire series was always
    returned.
    [#368](joshuaulrich/quantmod#368)

1. Change interval to 1d for `getDividends()` and `getSplits()`. The "3mo"
    setting caused some dividends to be missing for companies that issued monthly
    dividends. Note that the response to this request also includes all the OHLCV
    data. But it's small (less than 1MB for 60+ years of daily data).
    [#372](joshuaulrich/quantmod#372)

1. Handle errors in `getSplits()` and `getDividends()`. `getDividends()` didn't
    handle cases where the download failed, or when dividends needed to be
    split-adjusted but there were no splits. It also tried to set colnames
    on the empty xts object that's returned when there are no dividends.
    `getSplits()` had the same colnames issue. Check for no splits by testing
    for `NULL` because that's more explicit. Thanks to Chris Cheung for the
    report!
    [#366](joshuaulrich/quantmod#366)

1. Export `HL()`, `is.HL()`, and `has.HL()` functions and add documentation.
    These were added in 0.4.18 but not exported or included in the documentation.

1. Use Yahoo Finance v8 JSON endpoint and remove the v7 CSV endpoint. There
    seems to be a rate limit for the number of tickers you can request via the CSV
    endpoint. The [yfinance python library](https://github.com/ranaroussi/yfinance)
    uses the JSON endpoint and doesn't seem to have rate limit issues.
    [#360](joshuaulrich/quantmod#360)
    [#362](joshuaulrich/quantmod#362)
    [#364](joshuaulrich/quantmod#364)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants