def get_next_earning_release() -> list: date_from = datetime.datetime.today() date_to = get_next_working_day() yec = YahooEarningsCalendar() all_ticker = list() today_earnings = yec.earnings_on(date_from) tomorrow_earnings = yec.earnings_on(date_to) for stock1, stock2 in zip(today_earnings, tomorrow_earnings): if stock1['startdatetimetype'] == 'AMC': all_ticker.append(stock1['ticker']) if stock2['startdatetimetype'] == 'BMO': all_ticker.append(stock2['ticker']) return all_ticker
def update_data(): latest_date = get_latest_data() on_date = latest_date + timedelta(days=1) on_date = datetime(on_date.year, on_date.month, on_date.day) yec = YahooEarningsCalendar(delay=1) while on_date <= datetime.utcnow() - timedelta(days=1): logger.info(f"[Earnings] Add data on {on_date}") data = yec.earnings_on(on_date) df = pd.DataFrame(data) df.to_csv(CRUDE_EARNINGS_DATA_PATH, mode='a', header=False) on_date += timedelta(days=1) time.sleep(1)
class EarningCalendar(abc.ABC): def __init__(self): super().__init__() self.yec = YahooEarningsCalendar() constituents_df = pd.read_csv("../data/constituents.csv") self.constituents = set(constituents_df.Symbol.values) def earning_events_on(self, date): ''' :param date: date of interest :return: tuple (number of earnings reported after the market closes, number of all other earning events) ''' earnings = self.yec.earnings_on(date) # filter only S&P tickers earnings = list( filter(lambda x: x['ticker'] in self.constituents, earnings)) # after market close earnings - will be added to the next market day after_market_close = len( list(filter(lambda x: x['startdatetimetype'] == 'AMC', earnings))) others = len(earnings) - after_market_close s_and_p_matches = (after_market_close, others) return s_and_p_matches
import pandas as pd from datetime import datetime from datetime import timedelta from yahoo_earnings_calendar import YahooEarningsCalendar import dateutil.parser pd.set_option('display.max_columns', None) # Downloading the earnings for a specific date report_date = datetime.now().date() yec = YahooEarningsCalendar() earnings_list = yec.earnings_on(report_date) earnings_df = pd.DataFrame(earnings_list) earnings_df = earnings_df.drop(columns = ['gmtOffsetMilliSeconds', 'quoteType', 'timeZoneShortName']) earnings_df.columns = ['Ticker', 'Company Name', 'DateTime', 'Type', 'EPS Estimate', 'EPS Actual', 'EPS Surprise PCT'] earnings_df = earnings_df[['Ticker', 'Company Name', 'DateTime', 'Type', 'EPS Estimate', 'EPS Actual', 'EPS Surprise PCT']] earnings_df['DateTime'] = pd.to_datetime(earnings_df['DateTime']).dt.tz_localize(None) print(earnings_df) # Downloading the earnings for a range of dates DAYS_AHEAD = 7 start_date = datetime.now().date() end_date = (datetime.now().date() + timedelta(days=DAYS_AHEAD)) yec = YahooEarningsCalendar() earnings_list = yec.earnings_between(start_date, end_date) earnings_df = pd.DataFrame(earnings_list) earnings_df = earnings_df.drop(columns = ['gmtOffsetMilliSeconds', 'quoteType', 'timeZoneShortName']) earnings_df.columns = ['Ticker', 'Company Name', 'DateTime', 'Type', 'EPS Estimate', 'EPS Actual', 'EPS Surprise PCT']
import datetime from yahoo_earnings_calendar import YahooEarningsCalendar date_from = datetime.datetime.strptime('May 5 2017 10:00AM', '%b %d %Y %I:%M%p') date_to = datetime.datetime.strptime('May 8 2017 1:00PM', '%b %d %Y %I:%M%p') yec = YahooEarningsCalendar() print(yec.earnings_on(date_from)) print(yec.earnings_between(date_from, date_to))
!pip install yfinance !pip install yahoo_earnings_calendar # Import required library modules import yfinance as yf from yahoo_earnings_calendar import YahooEarningsCalendar import pandas as pd import numpy as np # Try to get tickers from earnings report # You may enter your prefered stock ticker manually. yec= YahooEarningsCalendar() from datetime import datetime day1 = datetime.strptime('10/30/2020', '%m/%d/%Y') er = yec.earnings_on(day1) # Use this dropdown widget to select a ticker for retrieving the stock data. from ipywidgets import Dropdown option_list =[] for i in range(len(er)): option_list.append([er[i]['companyshortname']+'-'+er[i]['ticker'], er[i]['ticker']]) dropdown = Dropdown(description = 'Select one company', options = option_list) display(dropdown) ticker = dropdown.value # Get the stock data from Yahoo finance. # If your stock sticker is not found in the dropdown menu, just enter it here to replace 'ticker' variable. data = yf.download(ticker,'2019-01-01','2020-05-22') # Take a look at the data
(SELECT COUNT()+1 FROM ( SELECT DISTINCT date FROM close_cur AS t WHERE date < close_yst2.date)) as rank, close as close_before FROM close_yst2) yst3 ON cur.rank = yst3.rank+1 ''' df = pd.read_sql_query(qry, conn, parse_dates=["date"]) # print(df.head(1104)) date_from = datetime.datetime.strptime('Aug 5 2016', '%b %d %Y').date() date_to = datetime.date.today() yec = YahooEarningsCalendar() list_result = yec.earnings_on(date_from) df_table = pd.DataFrame(yec.earnings_between(date_from, date_to)) df_table = df_table[[ 'companyshortname', 'startdatetime', 'startdatetimetype', 'ticker' ]] print(df_table) #print(yec.earnings_on(date_from)[]) #print(yec.earnings_between(date_from, date_to)) # data['4. close'].plot() # plt.title('Intraday Times Series for the MSFT stock (1 min)') # plt.show()
start = date(2019, 3, 19) yec = YahooEarningsCalendar() with f: writer = csv.writer(f) writer.writerow( ("Report Date", "Ticker", "Report Time", "Earnings", "Earnings Surprise (%)", "Close Before Earnings", "Open After Earnings", "Close After Earnings", "High After Earnings", "Low After Earnings", "Volume Before Earnings")) while start < date.today(): print(start) time.sleep(2) for stock in yec.earnings_on(start): ticker = stock['ticker'] earningsTime = stock['startdatetimetype'] if earningsTime == 'TAS': et = datetime.strptime(stock['startdatetime'], "%Y-%m-%dT%H:%M:%S.%fZ") earningsOpen = et.replace(hour=9, minute=30, second=0) earningsClose = et.replace(hour=16, minute=00, second=0) if et < earningsOpen: earningsTime = 'BMO' elif et > earningsClose: earningsTime = 'AMC' else: continue