-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Cannot retrieve price from downloaded data if at least one symbol is invalid #1743
Comments
Using foo = yf.download(["AAPL", "INTC"], start='2023-11-16', end='2023-11-17') # <-- Both AAPL and INTC being valid symbols
bar = yf.download(["AAPL", "ATVI"], start='2023-11-16', end='2023-11-17') # <-- ATVI being an invalid symbol (delisted)
print(foo['Close']['AAPL']['2023-11-16']) # <-- Outputs "189.7100067138672"
print(bar['Close']['AAPL']['2023-11-16']) # <-- KeyError: '2023-11-16'
print(bar['Close']['AAPL'][Timestamp('2023-11-16')]) # <-- Outputs "189.7100067138672" |
I have seen this happen with pre-market data for GS. As a work around, put a try/except around the yf.download call. |
@chotaGit my previous comment shows that it's still possible to retrieve the price value of symbol at a certain date ("AAPL" in my example) when another symbol is missing ("ATVI" in my example). However the date required key to access the price value needs to be specified explicitly using pandas.Timestamp. Catching the exception wouldn't help getting the price value. |
FYI this is a simple one-line fix, so I'll leave this as an example for #1084 |
Describe bug
When using
yf.download
with multiple symbols, it appears that if at least one symbol in the list is delisted/not available, the date isn't accessible anymoreSimple code that reproduces your problem
Debug log
Bad data proof
No response
yfinance
version0.2.31
Python version
3.10.5
Operating system
Windows 11 Pro (22H2) 22621.2715
The text was updated successfully, but these errors were encountered: