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 optimally_get_mc_distribution_for_IdiosyncraticVol(event, expiry): default_vol = .10 magnitude_mult = event.at_the_money_vol / default_vol time_mult = math.sqrt(get_time_to_expiry(expiry)) #print('Time Mult:', time_mult) mc_distribution = (IdiosyncraticVolDist - 1) * magnitude_mult * time_mult + 1 #print('Mean MC Dist:', np.mean(mc_distribution)) logger.info('IdioVol: {}'.format(np.average(mc_distribution))) print('MC Dist HERE', mc_distribution) return mc_distribution
def get_distribution(self, expiry: 'dt.date', *args, **kwargs): ref_date = dt.date.today() 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_df = pd.DataFrame({'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.set_index('States', inplace=True) distribution_df = distribution_df.loc[:, ['Prob', 'Pct_Move', 'Relative_Price']] distribution_df = Distribution(distribution_df) return 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)
def new_methodology(events, expiry, mc_iterations=10**4): events = establish_events(events, expiry) if not events: return np.ones(mc_iterations) mc_distributions = [] for evt in events: if isinstance(evt, IdiosyncraticVol): mc_distribution = (IdiosyncraticVolDist - 1) * ( evt.at_the_money_vol / .10) * math.sqrt( get_time_to_expiry(expiry)) + 1 #print('IdioVol: {}'.format(np.average(mc_distribution))) elif isinstance(evt, Earnings): mc_distribution = (EarningsDist - 1) * (evt.mean_move / 1.0504) + 1 #print('Earnings: {}'.format(np.average(mc_distribution))) else: mc_distribution = evt.get_distribution(expiry).mc_simulation( mc_iterations) #print('Other: {}'.format(np.average(mc_distribution))) mc_distributions.append(mc_distribution) return get_tot_mc_distribution(mc_distributions)
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-------------------------------# capital_allocation = 100 * 10**6 portfolio_max_drawdown_percent = .05 portfolio_max_drawdown = portfolio_max_drawdown_percent * capital_allocation time_to_expiry = get_time_to_expiry(expiry) Xguess = min(max(.1, 4 - 4 * 5 * time_to_expiry), .9) Xguess = .5 increment = .05 print('Xguess: {:.2f}'.format(Xguess)) optimal_size = find_maximum(f=kelly_criterion, Xguess=Xguess, increment=increment, print_guesses=True, probs=probs, pct_moves=pct_moves) #capital_deployed = maximum*(1/-max_loss) capital_deployed = optimal_size max_drawdown = max_loss * capital_deployed max_drawdown_event_only = max_loss_event_only * capital_deployed