def get_distribution(self, expiry): time_to_expiry = get_time_to_expiry(expiry) distribution_df = copy.deepcopy(self.event_input_distribution_df) distribution_df.loc[:, 'Pct_Move'] *= self.mult * self.idio_mult * math.sqrt( time_to_expiry) distribution_df.loc[:, 'Relative_Price'] = distribution_df.loc[:, 'Pct_Move'] + 1 return Distribution(distribution_df)
def get_distribution(self, expiry=None, *args, **kwargs): event_by_expiry = event_prob_by_expiry(self.timing_descriptor, expiry) event_not_by_expiry = 1 - event_by_expiry if event_by_expiry == 0: return get_no_event_distribution() elif event_by_expiry == 1: distribution_df = copy.deepcopy(self.event_input_distribution_df) distribution_df.loc[:, 'Pct_Move'] *= self.mult * self.idio_mult distribution_df.loc[:, 'Relative_Price'] = distribution_df.loc[:, 'Pct_Move'] + 1 return Distribution(distribution_df) else: no_event_scenario_info = { 'State': ['No_Event'], 'Prob': [event_not_by_expiry], 'Pct_Move': [0], 'Relative_Price': [1.0] } no_event_scenario_df = pd.DataFrame( no_event_scenario_info).set_index( 'State').loc[:, ['Prob', 'Pct_Move', 'Relative_Price']] distribution_df = copy.deepcopy(self.event_input_distribution_df) distribution_df.loc[:, 'Pct_Move'] *= self.mult * self.idio_mult distribution_df.loc[:, 'Relative_Price'] = distribution_df.loc[:, 'Pct_Move'] + 1 distribution_df.loc[:, 'Prob'] *= event_by_expiry distribution_df = distribution_df.append(no_event_scenario_df) return Distribution(distribution_df)
def get_distribution(self, expiry: 'dt.date', *args, **kwargs): time_to_expiry = get_time_to_expiry(expiry) prob_takeout_by_expiry = time_to_expiry * self.takeout_prob prob_no_takeout_by_expiry = 1 - prob_takeout_by_expiry relative_price_takeout = (1 + self.takeout_premium) relative_price_no_takeout = 1 - (prob_takeout_by_expiry * self.takeout_premium) / ( prob_no_takeout_by_expiry) distribution_info = { 'States': ['Takeout', 'No Takeout'], 'Prob': [prob_takeout_by_expiry, prob_no_takeout_by_expiry], 'Relative_Price': [relative_price_takeout, relative_price_no_takeout], 'Pct_Move': [self.takeout_premium, relative_price_no_takeout - 1] } distribution_df = pd.DataFrame(distribution_info).set_index( 'States').loc[:, ['Prob', 'Pct_Move', 'Relative_Price']] return Distribution(distribution_df)
from option_model.Option_Module import Option, OptionPriceMC # Define Events event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx', header=[0], index_col=[0, 1], sheet_name='Sub_States') event0 = IdiosyncraticVol('CLVS', .05) event1 = SysEvt_PresElection('CLVS', .02, 'Q2_2018') event2 = Event('CLVS', .05, 'Q2_2018', 'Q2_Earnings') event3 = Event('CLVS', .05, 'Q3_2018', 'Q3_Earnings') event4 = Event('CLVS', .075, 'Q3_2018', 'Investor_Day') event5 = Event('CLVS', .1, 'Q2_2018', 'FDA_Approval') event6 = TakeoutEvent('CLVS', 1) event7 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018', 'Ph3_Data') event8 = Event('CLVS', Distribution_MultiIndex(event8_info), 'Q3_2018', 'Elagolix_Approval') events = [ event0, event1, event2, event3, event4, event5, event6, event7, event8 ] #events = [event0, event8] events = [ event0, event1, event2, event3, event4, event5, event6, event7, event8 ] events = [event0, event6] events = [event0, event2, event3, event7] # Define Expiries expiry1 = dt.date(2018, 5, 21)
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(mc_distribution): strikes = np.arange(.5, 1.55, .05) option_prices = [] implied_vols = [] for strike in strikes: if strike >= 1.0: option_type = 'Call' else: option_type = 'Put' option = Option(option_type, strike, expiry) option_price = OptionPriceMC(option, mc_distribution) implied_vol = get_implied_volatility(option, 1.0, option_price) option_prices.append(option_price) implied_vols.append(implied_vol) prices_info = { 'Strikes': strikes, 'Prices': option_prices, 'IVs': implied_vols } 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(mc_distribution).loc[:, ['IVs']] if event_groupings.index(grouping) == 0: prices_df = prices else: 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)
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] # Define Event Groupings event_groupings = {} for i in range(len(events)): event_groupings[i] = [events[i] for i in range(i+1)]
import pandas as pd import datetime as dt # Paul Modules from option_model.Event_Module import Event, ComplexEvent from option_model.Distribution_Module import Distribution, Distribution_MultiIndex analyst_day = Event('NBIX', .075, dt.date(2018, 12, 1), 'Analyst Day') ingrezza_info = pd.read_csv( '/Users/paulwainer/Paulthon/Events/Parameters/CLVS.csv') ingrezza_data = Event('NBIX', Distribution(ingrezza_info), 'Q4_2018', 'Ingrezza Data') elagolix_info = pd.read_excel( '/Users/paulwainer/Paulthon/Events/Parameters/CLVS_RiskScenarios2.xlsx', header=[0], index_col=[0, 1], sheet_name='Sub_States') elagolix_approval = ComplexEvent('NBIX', Distribution_MultiIndex(elagolix_info), dt.date(2018, 11, 15), 'Elagolix Approval') all_other_events = [analyst_day, ingrezza_data, elagolix_approval]
from option_model.Event_Module import IdiosyncraticVol import datetime as dt from option_model.Distribution_Module import Distribution, float_to_bs_distribution event = IdiosyncraticVol('CLVS', .1) distribution = event.get_distribution(dt.date(2018, 5, 10)) print(distribution.mean_move, distribution.average_move, distribution.straddle) distribution.get_histogram() event_input_distribution = Distribution(event.event_input_distribution_df) print(event_input_distribution.mean_move, event_input_distribution.average_move, event_input_distribution.straddle) event_input_dist = event.event_input print(event_input_dist.mean_move, event_input_dist.average_move, event_input_dist.straddle) dist = float_to_bs_distribution(.5) print("HERE", dist.mean_move, dist.average_move, dist.straddle)
expiries = [expiry3] # Define Events event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx', header = [0], index_col = [0,1], sheet_name = 'Sub_States') event0 = IdiosyncraticVol('CLVS', .15) event1 = SysEvt_PresElection('CLVS', .02, 'Q2_2018') event2 = Event('CLVS', .05, 'Q2_2018', 'Q2_Earnings') event3 = Event('CLVS', .05, 'Q3_2018', 'Q3_Earnings') event4 = Event('CLVS', .075, 'Q3_2018', 'Investor_Day') event5 = Event('CLVS', .1, 'Q2_2018', 'FDA_Approval') event6 = TakeoutEvent('CLVS', 2) event7 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018', 'Ph3_Data') event8 = Event('CLVS', Distribution_MultiIndex(event8_info), 'Q2_2018', 'Elagolix_Approval') events = [event0, event1, event2, event3, event4, event5] events = [event8] event0_bid = IdiosyncraticVol('CLVS', .125) event1_bid = SysEvt_PresElection('CLVS', .01, 'Q2_2018') event2_bid = Event('CLVS', .03, 'Q2_2018', 'Q2_Earnings') event3_bid = Event('CLVS', .03, 'Q3_2018', 'Q3_Earnings') event4_bid = Event('CLVS', .05, 'Q3_2018', 'Investor_Day') event5_bid = Event('CLVS', .075, 'Q2_2018', 'FDA_Approval') event6_bid = TakeoutEvent('CLVS', 3) event7_bid = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018', 'Ph3_Data') event8_bid = Event('CLVS', Distribution_MultiIndex(event8_info), 'Q3_2018', 'Elagolix_Approval') #events_bid = [event0_bid, event1_bid, event2_bid, event3_bid, event4_bid, event5_bid, event6_bid] #events_bid = [event0_bid]
vol = IdiosyncraticVol('NBIX', .20) # Create MC_Distribution and distribution_df for the Combined Event df = event.event_input_distribution_df mc_dist = get_total_mc_distribution_from_events_vanilla([event, vol], expiry=expiry, mc_iterations=10**5) get_histogram_from_array(mc_dist, bins=2 * 10**1 + 1, title='Expected GE Distribution') mc_distribution_to_distribution(mc_dist, bins=5 * 10**1 + 1, to_file=True, file_name='Elagolix_Dist') combined_dist = Distribution(pd.read_csv('Elagolix_Dist.csv')) df = combined_dist.distribution_df #print(df.to_string()) # Source Probs, Pct_Moves, Max_Loss for the Combined Event probs = df.loc[:, 'Prob'].tolist() pct_moves = df.loc[:, 'Pct_Move'].tolist() max_loss = min(pct_moves) event_pct_moves = event.event_input_distribution_df.loc[:, 'Pct_Move'].tolist() print(event_pct_moves) max_loss_event_only = min(event_pct_moves) #max_loss = -1 #pct_moves = [pct_move/-max_loss for pct_move in pct_moves] #-----------------------------Portfolio Parameters-------------------------------#