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

Dividend Ex-Date returns Dividend Pay Date #287

Closed
matiasandina opened this issue Nov 10, 2019 · 4 comments
Closed

Dividend Ex-Date returns Dividend Pay Date #287

matiasandina opened this issue Nov 10, 2019 · 4 comments
Assignees
Labels

Comments

@matiasandina
Copy link

matiasandina commented Nov 10, 2019

Description

I'm trying to get the dividends dates (I see "Dividend Pay Date" is commented out in getQuote() source code). So I should probably not get the "Dividend Pay Date" but I should be getting the "Ex-Dividend Date".

library(quantmod)
library(dplyr)

what_metrics <- yahooQF(
  c("Dividend Yield", "Dividend/Share",
    "Ex-Dividend Date",
    "dividendDate",
    "Dividend Pay Date",
    "Earnings Timestamp")
)

df <- getQuote("MSFT", what=what_metrics) %>% as.data.frame()
yahoo_time <- function(x){
  as.POSIXct(x,
             origin = "1970-01-01 00:00:00.000 UTC")
}
df %>%
  mutate(`Ex-Dividend Date` = yahoo_time(`Ex-Dividend Date`),
         `Earnings Timestamp` = yahoo_time(`Earnings Timestamp`))

Produces

           Trade Time Dividend Yield Dividend/Share    Ex-Dividend Date  Earnings Timestamp
1 2019-11-08 16:00:01     0.01310135           1.89 2019-12-11 19:00:00 2019-10-23 12:08:39

Expected behavior

  • Ex Dividend Date >> Nov 20, 2019
  • Dividend Pay Date >> Dec 12, 2019

https://finance.yahoo.com/quote/MSFT?p=MSFT
https://www.nasdaq.com/market-activity/stocks/msft


Somewhat separate issue, the Earnings timestamp shows the past timestamp (not sure if this is correct behavior, given yahoo shows an estimate future earnings report)

@joshuaulrich
Copy link
Owner

joshuaulrich commented Nov 10, 2019

I don't think anything's wrong with getQuote. Yahoo returns the POSIX timestamp in UTC, so your transformation works if you specify the timezone.

yahoo_time <- function(x) { .POSIXct(x, tz = "UTC") }
msft <- getQuote("MSFT", what = what_metrics)
# don't have dplyr installed in my dev environment
within(msft, {
  `Ex-Dividend Date` <- from_utc(`Ex-Dividend Date`)
  `Earnings Timestamp` <- from_utc(`Earnings Timestamp`)
})

Regarding the Earnings Timestamp column, I can't fix that. getQuote returns the data returned by the Yahoo Finance server.

@matiasandina
Copy link
Author

I'm sorry, I might have not been clear, I don't think this is a problem of date calculation.

Ex Dividend Date >> Nov 20, 2019 and Dividend Pay Date >> Dec 12, 2019

Your code is also returning the Dividend Pay Date instead of the Ex-Dividend Date

I would also expect to be able to have access to both dates (I understand if yahoo API might not give that but the naming of the variable is confusing).

@joshuaulrich
Copy link
Owner

joshuaulrich commented Nov 11, 2019

I didn't read your initial post carefully enough. Thanks for clarifying!

So getQuote is returning the dividend pay date labelled as the ex-dividend date. I probably messed up that mapping when they switched from a CSV-based API to the JSON version. The JSON has dividendDate = 1576108800, so I assumed that was the ex-dividend date.

I'll fix. Thanks for the report!

@joshuaulrich
Copy link
Owner

Thanks again for the report! This should be fixed now. Please let me know if I missed something.

@joshuaulrich joshuaulrich added this to the Release 0.4-16 milestone Feb 23, 2020
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