1 Failed download: ['AAPL']: Exception('%ticker%: No price data found, symbol may be delisted (1d 2019-01-01 -> 2024-01-01)')
aSushiLegend opened this issue · comments
Describe bug
When I run my code to download data from yfinance, no matter what ticker it is I get an error show in the title
Simple code that reproduces your problem
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
def get_historical_data(symbol, start_date, end_date):
# Download historical data from Yahoo Finance
stock_data = yf.download(symbol, start=start_date, end=end_date)
return stock_data
def calculate_pe_ratio(stock_data):
# Calculate P/E ratio
pe_ratio = stock_data['Close'] / stock_data['Earnings']
return pe_ratio
def plot_pe_ratio(pe_ratio):
# Plot the P/E ratio over time
plt.figure(figsize=(12, 6))
plt.plot(pe_ratio.index, pe_ratio, label='P/E Ratio')
plt.title('Historical P/E Ratio Over 5 Years')
plt.xlabel('Date')
plt.ylabel('P/E Ratio')
plt.legend()
plt.grid(True)
plt.show()
if __name__ == "__main__":
# Replace 'AAPL' with the stock symbol of the desired company
symbol = 'AAPL'
# Set the date range for the past 5 years
start_date = '2019-01-01'
end_date = '2024-01-01'
# Fetch historical data
stock_data = get_historical_data(symbol, start_date, end_date)
# Assuming earnings are the same as closing prices for simplicity
stock_data['Earnings'] = stock_data['Close']
# Calculate P/E ratio
pe_ratio = calculate_pe_ratio(stock_data)
# Plot the P/E ratio
plot_pe_ratio(pe_ratio)
Debug log
DEBUG Entering download()
DEBUG Disabling multithreading because DEBUG logging enabled
DEBUG Entering history()
DEBUG AAPL: Yahoo GET parameters: {'period1': '2019-01-01 00:00:00-05:00', 'period2': '2024-01-01 00:00:00-05:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG Entering get()
DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/AAPL
DEBUG params=frozendict.frozendict({'period1': 1546318800, 'period2': 1704085200, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'})
DEBUG Entering _get_cookie_and_crumb()
DEBUG cookie_mode = 'basic'
DEBUG Entering _get_cookie_and_crumb_basic()
ERROR
1 Failed download:
ERROR ['AAPL']: Exception('%ticker%: No price data found, symbol may be delisted (1d 2019-01-01 -> 2024-01-01)')
DEBUG ['AAPL']: Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yfinance/multi.py", line 279, in _download_one
data = Ticker(ticker).history(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yfinance/utils.py", line 108, in wrapper
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yfinance/base.py", line 267, in history
raise Exception(f'{self.ticker}: {err_msg}')
Exception: %ticker%: No price data found, symbol may be delisted (1d 2019-01-01 -> 2024-01-01)
DEBUG Exiting download()
Bad data proof
No response
yfinance
version
0.2.33
Python version
3.11.5
Operating system
macOS Ventura
Not latest version