joshuaulrich / quantmod

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

getSymbols yahoo missing most recent data #417

Open joshuaulrich opened 3 weeks ago

joshuaulrich commented 3 weeks ago

Likely a timezone issue in the request and/or response.

library(quantmod)
tail(yspy <- getSymbols("SPY", auto.assign = FALSE, src = "yahoo"))
## 
##            SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
## 2024-06-04   526.46   529.15  524.96    528.39   34632700       528.39
## 2024-06-05   530.77   534.69  528.73    534.67   47610400       534.67
## 2024-06-06   534.98   535.42  532.68    534.66   30808500       534.66
## 2024-06-07   533.66   536.89  532.54    534.01   43224500       534.01
## 2024-06-10   533.18   535.99  532.57    535.66   35729300       535.66
## 2024-06-11       NA       NA      NA        NA         NA           NA

tail(tspy <- getSymbols("SPY", auto.assign = FALSE, src = "tiingo"))

##            SPY.Open SPY.High  SPY.Low SPY.Close SPY.Volume SPY.Adjusted
## 2024-06-05   530.77   534.69 528.7254    534.67   47610365       534.67
## 2024-06-06   534.98   535.42 532.6800    534.66   30808530       534.66
## 2024-06-07   533.66   536.89 532.5350    534.01   43224525       534.01
## 2024-06-10   533.18   535.99 532.5700    535.66   35729252       535.66
## 2024-06-11   534.07   537.01 532.0500    536.95   36383411       536.95
## 2024-06-12   541.63   544.12 540.3000    541.36   63251305       541.36
joshuaulrich commented 3 weeks ago

Hmm, looks like this may be an issue on Yahoo's end. The returned timestamps are for the day's open, there's no data for yesterday, and today's timestamp is the close. Perfect.

debugonce(quantmod::getSymbols.yahoo)
spy <- getSymbols("SPY", to = Sys.Date()+3, auto.assign = FALSE, src = "yahoo")
## ...
## ...
Browse[1]$
debug: idx <- .POSIXct(y$timestamp[[1]], tz = tz)
Browse[1]$
debug: if (!is.intraday) {
    idx <- as.Date(idx)
}
Browse[1]$ tail(xts(OHLCV(do.call(cbind, ohlcv)), .POSIXct(y$timestamp[[1]], tz = tz)))
                      open   high    low  close   volume
2024-06-05 09:30:00 530.77 534.69 528.73 534.67 47610400
2024-06-06 09:30:00 534.98 535.42 532.68 534.66 30808500
2024-06-07 09:30:00 533.66 536.89 532.54 534.01 43224500
2024-06-10 09:30:00 533.18 535.99 532.57 535.66 35729300
2024-06-11 09:30:00     NA     NA     NA     NA       NA
2024-06-12 16:00:00 541.63 544.12 540.30 541.36 60222457
ethanbsmith commented 3 weeks ago

yep, yahoo straight up not returning data for 6/11 for any tickers. caveat emptor

joshuaulrich commented 3 weeks ago

I ran this again right now (the following morning) and the data is there, but the timestamps are still the beginning of the day.

Browse[1]$ tail(xts(OHLCV(do.call(cbind, ohlcv)), .POSIXct(y$timestamp[[1]], tz = tz)))
                      open   high    low  close   volume
2024-06-05 09:30:00 530.77 534.69 528.73 534.67 47610400
2024-06-06 09:30:00 534.98 535.42 532.68 534.66 30808500
2024-06-07 09:30:00 533.66 536.89 532.54 534.01 43224500
2024-06-10 09:30:00 533.18 535.99 532.57 535.66 35729300
2024-06-11 09:30:00 534.07 537.01 532.05 536.95 36383400
2024-06-12 09:30:00 541.63 544.12 540.30 541.36 63129800