# Declare Events event = Stock.elagolix 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]
return np.array([random.normalvariate(0, 1) for i in range(iterations)]) #run simulation using a previously cretaed array of random numbers as the input @my_time_decorator def bs_simulation(rand_nums: 'np_array') -> 'np_array': stock, r, t, vol = 100, 0, 1.0, .10 stock_futures = stock * np.e**(r * t - (vol**2) * (t / 2) + rand_nums * vol * np.sqrt(t)) return stock_futures rand_nums = create_rand_nums(10**7) stock_futures = bs_simulation(rand_nums) distribution = mc_distribution_to_distribution( stock_futures, 10**3 + 1, to_csv=True, csv_file_name='BlackScholes.csv') print("Black Scholes Dist.:", distribution.mean_move, distribution.average_move, distribution.straddle) #get_histogram_from_array(distribution.mc_simulation(10**7)) distribution.get_histogram(iterations=10**7, bins=10**3 + 1) ############################# Graph Component ##########################3 stock = 100 bins = 100 plt.hist(stock_futures, bins, histtype='bar', rwidth=0.8, color='purple') plt.xlabel('St. Dev. Moves') plt.ylabel('Relative Frequency') plt.title( 'Pauls Beautiful Probabilitiy Distribution\nSmooth and Pretty!\n{:,d} Iterations' .format(len(stock_futures))) plt.legend()
#run simulation using a previously cretaed array of random numbers as the input @my_time_decorator def bs_simulation(rand_nums: 'np_array') -> 'np_array': stock, r, t, vol = 100, 0, 1.0, .10 stock_futures = stock * np.e**(r * t - (vol**2) * (t / 2) + rand_nums * vol * np.sqrt(t)) return stock_futures rand_nums = create_rand_nums(10**7) stock_futures = bs_simulation(rand_nums) print("HELLO SUSAN", [list_average(l) for l in [rand_nums, stock_futures]]) distribution = mc_distribution_to_distribution( stock_futures, 10**4 + 1, to_csv=True, csv_file_name='BlackScholes.csv') print("HELLO JANE", distribution.mean_move, distribution.average_move) get_mc_histogram(distribution.mc_simulation(10**6)) ############################# Graph Component ##########################3 stock = 100 bins = [float(i) for i in np.arange(stock * -.1, stock * 3, stock * .02)] plt.hist(stock_futures, bins, histtype='bar', rwidth=0.8, color='purple') plt.xlabel('St. Dev. Moves') plt.ylabel('Relative Frequency') plt.title( 'Beautiful Probabilitiy Distribution\nSmooth and Pretty!\n{:,d} Iterations' .format(len(stock_futures))) plt.legend() plt.show()