Esempio n. 1
0
def spread_pricing(options: 'list of options', quantities: 'list of quantities', events, events_bid, events_ask, mc_iterations=10**6):
    mc_distribution = get_total_mc_distribution(events, options[0].Expiry, mc_iterations=mc_iterations)
    mc_distribution_bid = get_total_mc_distribution(events_bid, options[0].Expiry, mc_iterations=mc_iterations)
    mc_distribution_ask = get_total_mc_distribution(events_ask, options[0].Expiry, mc_iterations=mc_iterations)
     
    option_prices = []
    for i in range(len(options)):
        #mc_distribution = get_total_mc_distribution(events, option.Expiry, mc_iterations=mc_iterations)
        if quantities[i] > 0:
            option_price = OptionPriceMC(options[i], mc_distribution_bid)
            side = 'Bid'
        else:
            option_price = OptionPriceMC(options[i], mc_distribution_ask)
            side = 'Ask'
        print("Strike: {:.3f}, {} Price: {:.3f}".format(options[i].Strike, side, option_price))
        """
        try:
            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
    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
Esempio n. 4
0
def spread_pricing(options: 'list of options',
                   quantities: 'list of quantities',
                   events,
                   mc_iterations=10**6):
    mc_distribution = get_total_mc_distribution(events,
                                                options[0].Expiry,
                                                mc_iterations=mc_iterations)

    option_prices = []
    for option in options:
        #mc_distribution = get_total_mc_distribution(events, option.Expiry, mc_iterations=mc_iterations)
        option_price = OptionPriceMC(option, mc_distribution)
        print("Strike: {:.3f}, Price: {:.3f}".format(option.Strike,
                                                     option_price))
        """
        try:
            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
Esempio n. 5
0
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(.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 spread_pricing(options: 'list of options', quantities: 'list of quantities', events, description = None, mc_iterations=10**6):
    mc_distribution = get_total_mc_distribution(events, options[0].Expiry, mc_iterations=mc_iterations)
     
    option_prices = []
    for i in range(len(options)):
        option_price = OptionPriceMC(options[i], mc_distribution)
        option_prices.append(option_price)
        logger.info("Strike: {:.3f}, {} Price: {:.3f}".format(options[i].Strike, description, option_price))
    
    spread_price = sum([option_price*quantity for option_price, quantity in zip(option_prices, quantities)])
    logger.info("Spread Price: {:.3f}".format(spread_price))
    return spread_price
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))
 def get_call_prices(call_options, mc_distribution):
     return list(
         map(lambda option: OptionPriceMC(option, mc_distribution),
             call_options))
     OptionPriceMC_Map = lambda option: OptionPriceMC(
         option, mc_distribution)
Esempio n. 11
0
def get_call_prices(call_options, mc_distribution):
    """For a list of call options (same expiry) and a MC Distribution, calculate the call prices"""
    return [
        OptionPriceMC(call_option, mc_distribution)
        for call_option in call_options
    ]