Possible to get earnings for a specific date from https://finance.yahoo.com/calendar/earnings
This function is currently available in yahoo_fin but that project is abandoned and broken due to recent changes in yahoo's encryption. Looking to switch to from yahoo_fin to yfinance since this project is actively fixing bugs and keeping up with yahoo's changes.
Here's the function from yahoo_fin (https://github.com/atreadw1492/yahoo_fin), which is currently broken due to Yahoo's encryption changes:
def get_earnings_for_date(date, offset = 0, count = 1):
'''Inputs: @date
Returns a dictionary of stock tickers with earnings expected on the
input date. The dictionary contains the expected EPS values for each
stock if available.'''
base_earnings_url = 'https://finance.yahoo.com/calendar/earnings'
if offset >= count:
return []
temp = pd.Timestamp(date)
date = temp.strftime("%Y-%m-%d")
dated_url = '{0}?day={1}&offset={2}&size={3}'.format(
base_earnings_url, date, offset, 100)
result = _parse_earnings_json(dated_url)
stores = result['context']['dispatcher']['stores']
earnings_count = stores['ScreenerCriteriaStore']['meta']['total']
new_offset = offset + 100
more_earnings = get_earnings_for_date(date, new_offset, earnings_count)
current_earnings = stores['ScreenerResultsStore']['results']['rows']
total_earnings = current_earnings + more_earnings
return total_earnings
Start with Ticker.earnings_dates. Uses same Yahoo API but doesn't set the day argument. If you think day would improve then feel free to submit a pull request.
I see how I could use Ticker.earnings_dates to get earnings dates for a specific ticker but what I'm looking for is to get a list of all tickers that have upcoming earnings dates.
Ah, that's not implemented.
get a list of all tickers that have upcoming earnings dates.
Yes! this is what I'm looking for too. Is there a simple way to do this? Thanks.
e.g.
https://finance.yahoo.com/calendar/earnings?from=2023-11-05&to=2023-11-11&day=2023-11-10
@mw66 Good suggestion. This works:
url = "https://finance.yahoo.com/calendar/earnings?day=2023-11-10"
d = dat._data.cache_get(url)
df = pd.read_html(d.text)[0]