def run_takeout_by_expiry(): event = TakeoutEvent('NBIX', 1) option_type = 'Call' option_type_2 = 'Put' strike = 1.0 expiries = [ dt.date(2018, 4, 20), dt.date(2018, 7, 20), dt.date(2018, 10, 20), dt.date(2019, 1, 20), dt.date(2019, 4, 20) ] # Preliminary Print Statements print("Ann. Takeout Prob: {:.1f}%, Premium: {:.1f}%".format( event.takeout_prob * 100, event.takeout_premium * 100)) for expiry in expiries: option = Option(option_type, strike, expiry) option2 = Option(option_type_2, strike, expiry) distribution = event.get_distribution(expiry) price = OptionPrice(distribution, option) price2 = OptionPrice(distribution, option2) straddle = price + price2 print( "T.O. by {:%m/%d/%Y}: {:.1f}%".format( expiry, distribution.distribution_df.loc["Takeout", "Prob"] * 100), "\n" * 0) print("Mean Move: {:.1f}%".format(distribution.mean_move * 100)) print("Straddle: {:.1f}%".format(straddle * 100), "\n" * 1)
def get_option_prices_from_mc_distribution(mc_distribution, strikes=None): if strikes is None: 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) option_prices.append(option_price) implied_vol = get_implied_volatility(option, 1.0, 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) return prices_df
def option_pricing(): option_type = 'Call' strike = 1.0 expiry = dt.date(2018, 10, 10) option = Option(option_type, strike, expiry) mc_distribution = get_total_mc_distribution(events, expiry, mc_iterations=10**6) option_price = OptionPriceMC(option, mc_distribution) print("Expiry: {}, Price: {}".format(expiry, option_price))
def get_option_sheet_from_mc_distribution(mc_distribution, expiry=None, strikes=None): if strikes is None: strikes = np.arange(.75, 1.25, .05) call_options = [Option('Call', strike, expiry) for strike in strikes] call_prices = list( map(lambda option: OptionPriceMC(option, mc_distribution), call_options)) call_IVs = list( map( lambda option, option_price: get_implied_volatility( option, option_price), call_options, call_prices)) put_options = [Option('Put', strike, expiry) for strike in strikes] put_prices = list( map(lambda option: OptionPriceMC(option, mc_distribution), put_options)) put_IVs = list( map( lambda option, option_price: get_implied_volatility( option, option_price), put_options, put_prices)) option_premiums = [ min(call_price, put_price) for call_price, put_price in zip(call_prices, put_prices) ] """ option_sheet_info = {'Strike': strikes, 'Price': option_premiums, 'IV': call_IVs} option_sheet = pd.DataFrame(option_sheet_info).set_index('Strike').loc[:, ['Price', 'IV']].round(2) """ option_sheet_info = list(zip(option_premiums, call_IVs)) index_r = pd.Index(strikes, name='Strike') iterables_c = [[expiry], ['Premium', 'IV']] index_c = pd.MultiIndex.from_product(iterables_c, names=['Expiry', 'Option_Info']) option_sheet = pd.DataFrame(option_sheet_info, index=index_r, columns=index_c) return option_sheet
def get_option_sheet_from_mc_distribution(mc_distribution, expiry=None, strikes=None): if strikes is None: strikes = np.arange(.75, 1.25, .05) call_options = [Option('Call', strike, expiry) for strike in strikes] call_prices = list( map(lambda option: OptionPriceMC(option, mc_distribution), call_options)) call_IVs = list( map( lambda option, option_price: get_implied_volatility( option, option_price), call_options, call_prices)) put_options = [Option('Put', strike, expiry) for strike in strikes] put_prices = list( map(lambda option: OptionPriceMC(option, mc_distribution), put_options)) put_IVs = list( map( lambda option, option_price: get_implied_volatility( option, option_price), put_options, put_prices)) option_premiums = [ min(call_price, put_price) for call_price, put_price in zip(call_prices, put_prices) ] option_sheet_info = { 'Strike': strikes, 'Price': option_premiums, 'IV': call_IVs } option_sheet = pd.DataFrame(option_sheet_info).set_index( 'Strike').loc[:, ['Price', 'IV']].round(2) #iterables = [['Price', 'IV'], ['Group 1']] #index = pd.MultiIndex.from_product(iterables, names=['Option Info', 'Event Grouping']) #option_sheet.rename(columns=index) #print(index) return option_sheet
def individual_option_pricing(): option_type = 'Call' strike = 1.0 expiry = dt.date(2018, 5, 10) expiries = pd.date_range(pd.datetime.today(), periods=100).tolist() expiries = [expiry]*100 print(isinstance(expiries[0], dt.datetime)) for expiry in expiries: option = Option(option_type, strike, expiry) mc_distribution = get_total_mc_distribution(events, expiry, mc_iterations=10**6) option_price = OptionPriceMC(option, mc_distribution) print((expiry, option_price))
spread_prices = [] for i in range(len(event_groupings)): spread_price = spread_pricing(options, quantities, event_groupings[i], event_grouping_names[i], mc_iterations) spread_prices.append(spread_price) info = {'Level': event_grouping_names, 'Spread': spread_prices} info = pd.DataFrame(info).set_index('Level') return info option_type = 'Put' expiry = dt.date(2018, 8, 1) option1 = Option(option_type, .975, expiry) option2 = Option(option_type, .925, expiry) option3 = Option(option_type, .95, expiry) options = [option1, option2, option3] quantities = [1, -1, 0] spread_prices = spread_pricing_bid_ask(options, quantities, event_groupings, event_grouping_names, mc_iterations=10**6) print(spread_prices.round(3)) print(events_bid, events, events_ask, end="\n") sorted_events = sorted(
spread_prices = [] for i in range(len(event_groupings)): spread_price = spread_pricing(options, quantities, event_groupings[i], event_grouping_names[i], mc_iterations) spread_prices.append(spread_price) info = {'Level': event_grouping_names, 'Spread': spread_prices} info = pd.DataFrame(info).set_index('Level') return info option_type = 'Call' expiry = dt.date(2018, 6, 1) option1 = Option(option_type, 1.00, expiry) option2 = Option('Call', 1.10, expiry) option3 = Option('Put', .9, expiry) option4 = Option(option_type, 1.10, expiry) option5 = Option(option_type, 1.10, expiry) option6 = Option(option_type, 1.10, expiry) options = [option1, option2, option3, option4, option5, option6] quantities = [1, 1, 1, 1, 1, 1] options = [option1, option2, option3] quantities = [1, 1, 1] event_groupings = [events_bid, events, events_ask] event_grouping_names = ['Bid', 'Mid', 'Ask'] spread_prices = spread_pricing_bid_ask(options,
call_spread = option_prices[-1] - option_price print("Call Spread: {:2f}".format(call_spread)) except Exception: pass """ option_prices.append(option_price) spread_price = sum([ option_price * quantity for option_price, quantity in zip(option_prices, quantities) ]) print("Spread Price: {:.3f}".format(spread_price)) return spread_price option1 = Option('Call', 1.00, dt.date(2018, 10, 1)) option2 = Option('Call', 1.05, dt.date(2018, 10, 1)) option3 = Option('Call', 1.02, dt.date(2018, 10, 1)) option4 = Option('Call', 1.03, dt.date(2018, 10, 1)) option5 = Option('Call', 1.04, dt.date(2018, 10, 1)) option6 = Option('Call', 1.05, dt.date(2018, 10, 1)) options = [option1, option2, option3, option4, option5, option6] quantities = [1, 1, 1, 1, 1, 1] options = [option1, option2] quantities = [-1, 1] spread_price = spread_pricing(options, quantities, events, events_bid, events_ask) print(spread_price)
spread_prices = [] for i in range(len(event_groupings)): spread_price = spread_pricing(options, quantities, event_groupings[i], event_grouping_names[i], mc_iterations) spread_prices.append(spread_price) info = {'Level': event_grouping_names, 'Spread': spread_prices} info = pd.DataFrame(info).set_index('Level') return info option_type = 'Call' expiry = dt.date(2018, 8, 1) option1 = Option(option_type, 1.10, expiry) option2 = Option(option_type, 1.10, expiry) option3 = Option(option_type, 1.10, expiry) options = [option1, option2, option3] quantities = [1, 1, 1] event_groupings = [events_bid, events, events_ask] event_grouping_names = ['Bid', 'Mid', 'Ask'] spread_prices = spread_pricing_bid_ask(options, quantities, event_groupings, event_grouping_names, mc_iterations=10**6) print(spread_prices.round(3))