Open mukalaaa opened 6 months ago
It appears that the scraper doesn't even try to provide the earnings: (yfinance.scrapers.fundamentals; lines 11-35)
class Fundamentals:
def __init__(self, data: YfData, symbol: str, proxy=None):
self._data = data
self._symbol = symbol
self.proxy = proxy
# Earnings are never set - which is what's causing the error.
self._earnings = None
self._financials = None
self._shares = None
self._financials_data = None
self._fin_data_quote = None
self._basics_already_scraped = False
self._financials = Financials(data, symbol)
@property
def financials(self) -> "Financials":
return self._financials
@property
def earnings(self) -> dict:
# And then this if statement is true, which throws the error.
if self._earnings is None:
raise YFNotImplementedError('earnings')
return self._earnings
...
Which means that yfinance doesn’t support getting fundamentals at all.
If you're looking for alternatives; I know that the alpha_vantage library supports getting fundamental data. You are limited to 25 api requests/day, though.
Keep in mind that Alpha Vantage has incorrect data for revenue, income, and debt
Which means that yfinance doesn’t support getting fundamentals at all.
Not fair. yfinance gets income, cashflow and balance sheet. Earnings in one of those.
Describe bug
I cannot get any earning data at all, I tried AAPL and other companies, I always get an error that is not implemented in yfinance. I appreciate any help about this
Simple code that reproduces your problem
import yfinance as yf
Define the ticker
ticker = '7010.SR'
Fetch the stock data
stock = yf.Ticker(ticker)
Get earnings data
earnings = stock.get_earnings()
Print earnings data
print(earnings)
Debug log
Traceback (most recent call last): File "/Users/alan/Desktop/Investments Website Project/youtube channels ideas/earnings.py", line 10, in
earnings = stock.get_earnings()
^^^^^^^^^^^^^^^^^^^^
File "/Users/alan/Desktop/Investments Website Project/.venv/lib/python3.12/site-packages/yfinance/base.py", line 292, in get_earnings
data = self._fundamentals.earnings[freq]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/alan/Desktop/Investments Website Project/.venv/lib/python3.12/site-packages/yfinance/scrapers/fundamentals.py", line 34, in earnings
raise YFNotImplementedError('earnings')
yfinance.exceptions.YFNotImplementedError: Have not implemented fetching 'earnings' from Yahoo API
Bad data proof
No response
yfinance
versionyfinance-0.2.40
Python version
No response
Operating system
MacOS