yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

Possible to get earnings for a specific date from https://finance.yahoo.com/calendar/earnings

Open sonso-1 opened this issue 2 years ago • 6 comments

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

sonso-1 avatar Jan 13 '23 20:01 sonso-1

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.

ValueRaider avatar Jan 14 '23 23:01 ValueRaider

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.

sonso-1 avatar Jan 16 '23 14:01 sonso-1

Ah, that's not implemented.

ValueRaider avatar Jan 16 '23 15:01 ValueRaider

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.

mw66 avatar Nov 09 '23 23:11 mw66

e.g.

https://finance.yahoo.com/calendar/earnings?from=2023-11-05&to=2023-11-11&day=2023-11-10

mw66 avatar Nov 09 '23 23:11 mw66

@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]

ValueRaider avatar Nov 10 '23 22:11 ValueRaider