def run(): if __name__ == "__main__": #-------------------PresElection Setup-----------------# PresElectionParams = pd.read_csv( "/Users/paulwainer/Environments/finance_env/PresElectionParams.csv" ) PresElectionParams.set_index('Stock', inplace=True) # Create PresElection Events Dict PresElection_Evts = {} for stock, move_input in PresElectionParams.itertuples(): PresElection_Evts[stock] = SysEvt_PresElection(stock, move_input) #-------------------Takeout Setup-----------------# TakeoutParams = pd.read_csv("TakeoutParams.csv") TakeoutParams.set_index('Stock', inplace=True) # Create Takeout Events Dict Takeout_Evts = {} for stock, bucket in TakeoutParams.itertuples(): Takeout_Evts[stock] = TakeoutEvent(stock, bucket) takeout_dict = {} for stock, event in Takeout_Evts.items(): takeout_dict[stock] = (event.takeout_prob, event.takeout_premium) takeout_df = pd.DataFrame(takeout_dict).T.round(3) takeout_df.rename(columns={0: 'Prob', 1: 'Premium'}, inplace=True) takeout_df.rename_axis('Stock', inplace=True) evt = SystematicEvent('ZFGN', .20) evt2 = Event() evt3 = SysEvt_PresElection('GM', .05) evt4 = TakeoutEvent('NBIX', 1) print("\n\n\nAll Events---\n", Event.instances, "\n") print("Systematic Event---\n", SystematicEvent.instances, "\n") print("Presidential Election---\n", SysEvt_PresElection.instances, "\n") print("Takeout Event---\n", TakeoutEvent.instances, "\n") print(takeout_df.sort_values('Premium', ascending=False))
def mc_simulation(): expiry = dt.date(2018, 12, 1) mc_iterations = 10**5 # Define Events event1 = TakeoutEvent('CLVS', 1) event2 = SysEvt_PresElection('CLVS', .015) event3 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Ph3_Data') event4 = Event('CLVS', .025, 'Investor_Day') event5 = Event('CLVS', .15, 'FDA_Approval') event6 = Event('CLVS', .15, 'Q1_Earnings') event7 = Event('CLVS', .05, 'Q2_Earnings') events1 = [event6] events2 = [event6, event7] events3 = [event5, event6, event7] events4 = [event1, event5, event6, event7] events5 = [event1, event3, event5, event6, event7] event_groupings = [events1, events2, events3, events4, events5] @my_time_decorator def get_total_distribution(events): mc_simulation = np.zeros(mc_iterations) for event in events: distribution = event.get_distribution(expiry) mc_simulation += distribution.mc_simulation(mc_iterations) return mc_simulation @my_time_decorator def get_option_prices(name, mc_distribution): strikes = np.arange(.5, 1.55, .05) prices = [] for strike in strikes: if strike >= 1.0: option_type = 'Call' else: option_type = 'Put' option = Option(option_type, strike, expiry) prices.append(OptionPriceMC(option, mc_distribution)) prices_info = {'Strikes': strikes, 'Prices': prices} prices_df = pd.DataFrame(prices_info).round(3) prices_df.set_index('Strikes', inplace=True) #prices_df.rename_axis(name, inplace=True) return prices_df @my_time_decorator def event_groupings_df(event_groupings): i = 0 for grouping in event_groupings: mc_distribution = get_total_distribution(grouping) prices = get_option_prices('Prices', mc_distribution) if event_groupings.index(grouping) == 0: prices_df = prices else: #prices_df.join(prices.loc[:, 'Prices']) prices_df = pd.merge(prices_df, prices, left_index=True, right_index=True) #graph_MC_distribution(mc_distribution) i += 1 return prices_df event_df = event_groupings_df(event_groupings) print(event_df)