def create_earnings_events(stocks: 'list of stocks'): """Create Earnings Events for a List of Stocks""" event_names = ['Q1_2018', 'Q2_2018', 'Q3_2018', 'Q4_2018'] q1_date_range = list( pd.date_range(dt.date(2018, 1, 1), dt.date(2018, 3, 30))) earnings_events = [] for stock in stocks: # Set Event Input event_input = random.uniform(.03, .07) # Set Earnings Dates q1_date = random.choice(q1_date_range) timing_descriptors = [ q1_date, q1_date + timedelta(90), q1_date + timedelta(180), q1_date + timedelta(270) ] # Instantiate Earnings Events and append to main list for i in range(4): earnings_evt = Earnings(stock, event_input, timing_descriptors[i], event_names[i]) earnings_events.append(earnings_evt) return earnings_events
def get_earnings_events(symbol=None): if symbol is None: c.execute("SELECT * FROM earnings") else: c.execute("SELECT * FROM earnings WHERE stock=:stock", {'stock': symbol}) return [Earnings(*params) for params in c.fetchall()]
def get_earnings_events(): earns_evts = [] for earns in get_earnings_table().itertuples(): earns_evt = Earnings( earns.stock, earns.event_input, dt.datetime.strptime(earns.timing_descriptor, '%Y-%m-%d').date(), earns.event_name) earns_evts.append(earns_evt) return earns_evts
def get_earnings_events(symbol=None): if symbol is None: earns_evts = [] for earns in get_earnings_table().itertuples(): earns_evt = Earnings( earns.stock, earns.event_input, dt.datetime.strptime(earns.timing_descriptor, '%Y-%m-%d').date(), earns.event_name) earns_evts.append(earns_evt) return earns_evts else: c.execute("SELECT * FROM earnings WHERE stock=:stock", {'stock': symbol}) return [instantiate_earnings_event(params) for params in c.fetchall()]
'Bucket']) @property def events(self): return self.earnings_events + [self.takeout_event] event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx', header=[0], index_col=[0, 1], sheet_name='Sub_States') idio = IdiosyncraticVol('CLVS', .05) takeout = TakeoutEvent('CLVS', 2) pres_elec = SysEvt_PresElection('CLVS', .02) earns_q2 = Earnings('CLVS', .05, dt.date(2018, 5, 15), 'Q2_2018') earns_q3 = Earnings('CLVS', .05, dt.date(2018, 8, 15), 'Q3_2018') earns_q4 = Earnings('CLVS', .05, dt.date(2018, 11, 15), 'Q4_2018') fda_meeting = Event('CLVS', .1, 'Q2_2018', 'FDA Meeting') data = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018', 'Ph3_Data') elagolix = ComplexEvent('CLVS', Distribution_MultiIndex(event8_info), dt.date(2018, 6, 1), 'Elagolix Approval') events = [ idio, takeout, pres_elec, earns_q2, earns_q3, earns_q4, fda_meeting, elagolix ] earnings = get_earnings_events('CLVS') sorted_events = sorted( events, key=lambda evt: Timing(evt.timing_descriptor).center_date) print(earnings)
def instantiate_earnings_event(params: 'tuple of Earnings params'): evt = Earnings(params[0], params[1], dt.datetime.strptime(params[2], '%Y-%m-%d').date(), params[3]) return evt
def instantiate_earnings_event_2(params): return Earnings(*params)
def instantiate(n=1): for i in range(n): evt = Earnings(*params)
def instantiate_earnings_event( params: 'tuple of Earnings params from sqlite db'): return Earnings(*params)
expiry7 = dt.date(2018, 11, 21) expiry8 = dt.date(2018, 12, 21) expiries = [expiry1, expiry2, expiry3, expiry4, expiry5, expiry6] expiries = [expiry1, expiry3, expiry5] expiries = [expiry3] # Define Events event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx', header = [0], index_col = [0,1], sheet_name = 'Sub_States') idio = IdiosyncraticVol('CLVS', .05) takeout = TakeoutEvent('CLVS', 2) pres_elec = SysEvt_PresElection('CLVS', .02) earns_q2 = Earnings('CLVS', .05, 'Q2_2018', 'Q2_Earnings') earns_q3 = Earnings('CLVS', .05, 'Q3_2018', 'Q3_Earnings') earns_q4 = Earnings('CLVS', .05, 'Q4_2018', 'Q4_Earnings') event5 = Event('CLVS', .1, 'Q2_2018', 'FDA_Approval') data = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018', 'Ph3_Data') elagolix = ComplexEvent('CLVS', Distribution_MultiIndex(event8_info), 'Q2_2018', 'Elagolix_Approval') events = [idio, takeout, earns_q2, earns_q3, earns_q4, elagolix] #events = [takeout] #events = [idio, elagolix] events_bid = [event.event_bid for event in events] events_ask = [event.event_ask for event in events] events_high_POS = [idio, elagolix.event_high_prob_success] events_low_POS = [idio, elagolix.event_low_prob_success] events_max_optionality = [idio, elagolix.event_max_optionality]
def earnings_params_to_earnings_event(params): evt = Earnings(params[0], params[1], dt.datetime.strptime(params[2], '%Y-%m-%d').date(), params[3]) return evt