def get_call_IVs(call_options, call_prices): return list( map( lambda option, option_price: get_implied_volatility( option, option_price), call_options, call_prices)) tuples = pd.concat([call_options, call_prices], axis=1).loc[:, [0, 1]].apply(tuple, axis=1) IV_Map = lambda tup: get_implied_volatility(tup[0], tup[1]) call_IVs = tuples.apply(IV_Map) #df = pd.concat([call_options, call_prices, call_IVs], axis=1).round(3) return call_IVs
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 get_vol_surface_from_mc_distribution(mc_distribution, expiry=None, strikes=None): if strikes is None: strikes = np.arange(.5, 1.5, .01) #strikes = np.arange(.5, 1.5, .005) 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)) option_sheet_info = list(call_IVs) index_r = pd.Index(strikes, name='Strike') iterables_c = [[expiry], ['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(.5, 2, .005) 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 get_call_IVs(call_options, call_prices): """For a list of call options and call prices, calculate implied volatility for each option""" return [ get_implied_volatility(call_option, call_price) for call_option, call_price in zip(call_options, call_prices) ]