def run():
    if __name__ == "__main__":
        #-------------------PresElection Setup-----------------#
        PresElectionParams = pd.read_csv(
            "/Users/paulwainer/Environments/finance_env/PresElectionParams.csv"
        )
        PresElectionParams.set_index('Stock', inplace=True)

        # Create PresElection Events Dict
        PresElection_Evts = {}
        for stock, move_input in PresElectionParams.itertuples():
            PresElection_Evts[stock] = SysEvt_PresElection(stock, move_input)

        #-------------------Takeout Setup-----------------#
        TakeoutParams = pd.read_csv("TakeoutParams.csv")
        TakeoutParams.set_index('Stock', inplace=True)

        # Create Takeout Events Dict
        Takeout_Evts = {}
        for stock, bucket in TakeoutParams.itertuples():
            Takeout_Evts[stock] = TakeoutEvent(stock, bucket)

        takeout_dict = {}
        for stock, event in Takeout_Evts.items():
            takeout_dict[stock] = (event.takeout_prob, event.takeout_premium)

        takeout_df = pd.DataFrame(takeout_dict).T.round(3)
        takeout_df.rename(columns={0: 'Prob', 1: 'Premium'}, inplace=True)
        takeout_df.rename_axis('Stock', inplace=True)

        evt = SystematicEvent('ZFGN', .20)
        evt2 = Event()
        evt3 = SysEvt_PresElection('GM', .05)
        evt4 = TakeoutEvent('NBIX', 1)

        print("\n\n\nAll Events---\n", Event.instances, "\n")
        print("Systematic Event---\n", SystematicEvent.instances, "\n")
        print("Presidential Election---\n", SysEvt_PresElection.instances,
              "\n")
        print("Takeout Event---\n", TakeoutEvent.instances, "\n")
        print(takeout_df.sort_values('Premium', ascending=False))
예제 #2
0
from functools import reduce
from biotech_class_run_9 import get_total_mc_distribution, get_option_sheet_from_mc_distribution
from option_model.Event_Module import IdiosyncraticVol, SysEvt_PresElection, Event, TakeoutEvent
from option_model.Distribution_Module import Distribution, Distribution_MultiIndex
from paul_resources import show_mc_distributions_as_line_chart
from option_model.Option_Module import Option, OptionPriceMC
# Define Events

event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx',
                            header=[0],
                            index_col=[0, 1],
                            sheet_name='Sub_States')

event0 = IdiosyncraticVol('CLVS', .05)
event1 = SysEvt_PresElection('CLVS', .02, 'Q2_2018')
event2 = Event('CLVS', .05, 'Q2_2018', 'Q2_Earnings')
event3 = Event('CLVS', .05, 'Q3_2018', 'Q3_Earnings')
event4 = Event('CLVS', .075, 'Q3_2018', 'Investor_Day')
event5 = Event('CLVS', .1, 'Q2_2018', 'FDA_Approval')
event6 = TakeoutEvent('CLVS', 1)
event7 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018',
               'Ph3_Data')
event8 = Event('CLVS', Distribution_MultiIndex(event8_info), 'Q3_2018',
               'Elagolix_Approval')
events = [
    event0, event1, event2, event3, event4, event5, event6, event7, event8
]
#events = [event0,  event8]
events = [
    event0, event1, event2, event3, event4, event5, event6, event7, event8
]
예제 #3
0
        expiries = [date for date in xticks if date > dt.date.today()]
        term_struc = term_structure(events, expiries, metric = 'IV', mc_iterations = 10**5)
        vols = term_struc.iloc[[term_struc.index.get_loc(1.00, method='nearest')], :].values.tolist()[0]
        print(zip(expiries, vols))
        ax1.plot(expiries,
                 vols,
                 #label = 'Term_Structure',
                 #color = 'black'
                 #marker='s',
                 #s = 250
                 )
        
        ax1.set_yticks(np.arange(0, max(vols)+.05, .05))
    """

    # Set High-Level Graph Parameters; Show Graph
    #ax1.grid(True)
    ax1.title.set_position([.525, 1.025])
    fig.patch.set_facecolor('xkcd:off white')
    ax1.patch.set_facecolor('xkcd:pale grey')
    fig.tight_layout()
    fig.set_size_inches(8, 5)
    plt.legend(loc='best')
    plt.show()
    return fig, ax1


if __name__ == '__main__':
    events = [Event('CRBP', .05, 'Q3_2018'), Earnings('CRBP', .075, 'Q3_2018')]
    get_event_timeline(events)
def mc_simulation(expiry=None, mc_iterations=10**5):

    # Define Events
    event1 = TakeoutEvent('CLVS', 1)
    event2 = SysEvt_PresElection('CLVS', .015)
    event3 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Ph3_Data')
    event4 = Event('CLVS', .025, 'Investor_Day')
    event5 = Event('CLVS', .15, 'FDA_Approval')
    event6 = Event('CLVS', .15, 'Q1_Earnings')
    event7 = Event('CLVS', .05, 'Q2_Earnings')

    events1 = [event6]
    events2 = [event6, event7]
    events3 = [event5, event6, event7]
    events4 = [event1, event5, event6, event7]
    events5 = [event1, event3, event5, event6, event7]

    event_groupings = [events1, events2, events3, events4, events5]

    @my_time_decorator
    def get_total_mc_distribution(events,
                                  expiry=None,
                                  symbol=None,
                                  mc_iterations=10**4):
        """Add together the MC Distributions of individual events. Return the Total MC Distribution."""
        total_mc_distribution = np.zeros(mc_iterations)

        for event in events:
            distribution = event.get_distribution(expiry)
            total_mc_distribution += distribution.mc_simulation(mc_iterations)

        return total_mc_distribution

    @my_time_decorator
    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

    @my_time_decorator
    def event_groupings_df(event_groupings):
        i = 0
        for grouping in event_groupings:
            mc_distribution = get_total_mc_distribution(grouping,
                                                        expiry=expiry)
            prices = get_option_prices_from_mc_distribution(
                mc_distribution,
                strikes=np.arange(.5, 1.55, .05)).loc[:, ['Prices', 'IVs']]

            if event_groupings.index(grouping) == 0:
                prices_df = prices
            else:
                prices_df = pd.merge(prices_df,
                                     prices,
                                     left_index=True,
                                     right_index=True)

            get_mc_histogram(mc_distribution)

            i += 1
        return prices_df

    event_df = event_groupings_df(event_groupings)
    print(event_df)
def mc_simulation():
    expiry = dt.date(2018, 12, 1)
    mc_iterations = 10**5

    # Define Events
    event1 = TakeoutEvent('CLVS', 1)
    event2 = SysEvt_PresElection('CLVS', .015)
    event3 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Ph3_Data')
    event4 = Event('CLVS', .025, 'Investor_Day')
    event5 = Event('CLVS', .15, 'FDA_Approval')
    event6 = Event('CLVS', .15, 'Q1_Earnings')
    event7 = Event('CLVS', .05, 'Q2_Earnings')

    events1 = [event6]
    events2 = [event6, event7]
    events3 = [event5, event6, event7]
    events4 = [event1, event5, event6, event7]
    events5 = [event1, event3, event5, event6, event7]

    event_groupings = [events1, events2, events3, events4, events5]

    @my_time_decorator
    def get_total_distribution(events):
        mc_simulation = np.zeros(mc_iterations)
        for event in events:
            distribution = event.get_distribution(expiry)
            mc_simulation += distribution.mc_simulation(mc_iterations)
        return mc_simulation

    @my_time_decorator
    def get_option_prices(mc_distribution):
        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)
            implied_vol = get_implied_volatility(option, 1.0, option_price)

            option_prices.append(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)
        #prices_df.rename_axis(name, inplace=True)
        return prices_df

    @my_time_decorator
    def event_groupings_df(event_groupings):
        i = 0
        for grouping in event_groupings:
            mc_distribution = get_total_distribution(grouping)
            prices = get_option_prices(mc_distribution).loc[:, ['IVs']]

            if event_groupings.index(grouping) == 0:
                prices_df = prices
            else:
                prices_df = pd.merge(prices_df,
                                     prices,
                                     left_index=True,
                                     right_index=True)

            graph_MC_distribution(mc_distribution)

            i += 1
        return prices_df

    event_df = event_groupings_df(event_groupings)
    print(event_df)
예제 #6
0
expiries = [expiry1, expiry3, expiry5]
expiries = [expiry3]

# Define Events
event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx',
                         header = [0],
                         index_col = [0,1],
                         sheet_name = 'Sub_States')

idio = IdiosyncraticVol('CLVS', .05)
takeout = TakeoutEvent('CLVS', 2)
pres_elec = SysEvt_PresElection('CLVS', .02)
earns_q2 = Earnings('CLVS', .05, 'Q2_2018', 'Q2_Earnings')
earns_q3 = Earnings('CLVS', .05, 'Q3_2018', 'Q3_Earnings')
earns_q4 = Earnings('CLVS', .05, 'Q4_2018', 'Q4_Earnings')
event5 = Event('CLVS', .1, 'Q2_2018', 'FDA_Approval')
data = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018', 'Ph3_Data')
elagolix = ComplexEvent('CLVS', Distribution_MultiIndex(event8_info), 'Q2_2018', 'Elagolix_Approval')
events = [idio, takeout,  earns_q2, earns_q3, earns_q4, elagolix]
#events = [takeout]
#events = [idio, elagolix]

events_bid = [event.event_bid for event in events]
events_ask = [event.event_ask for event in events]
events_high_POS = [idio, elagolix.event_high_prob_success]
events_low_POS = [idio, elagolix.event_low_prob_success]
events_max_optionality = [idio, elagolix.event_max_optionality]

# Define Event Groupings
event_groupings = {}
for i in range(len(events)):
예제 #7
0
import pandas as pd
import datetime as dt

# Paul Modules
from option_model.Event_Module import Event, ComplexEvent
from option_model.Distribution_Module import Distribution, Distribution_MultiIndex

analyst_day = Event('NBIX', .075, dt.date(2018, 12, 1), 'Analyst Day')

ingrezza_info = pd.read_csv(
    '/Users/paulwainer/Paulthon/Events/Parameters/CLVS.csv')
ingrezza_data = Event('NBIX', Distribution(ingrezza_info), 'Q4_2018',
                      'Ingrezza Data')

elagolix_info = pd.read_excel(
    '/Users/paulwainer/Paulthon/Events/Parameters/CLVS_RiskScenarios2.xlsx',
    header=[0],
    index_col=[0, 1],
    sheet_name='Sub_States')

elagolix_approval = ComplexEvent('NBIX',
                                 Distribution_MultiIndex(elagolix_info),
                                 dt.date(2018, 11, 15), 'Elagolix Approval')

all_other_events = [analyst_day, ingrezza_data, elagolix_approval]
예제 #8
0
expiries = [expiry1, expiry2, expiry3, expiry4, expiry5, expiry6]
expiries = [expiry1, expiry3, expiry5]
expiries = [expiry3]

# Define Events
event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx',
                            header=[0],
                            index_col=[0, 1],
                            sheet_name='Sub_States')

idio = IdiosyncraticVol('CLVS', .15)
earns_q2 = SysEvt_PresElection('CLVS', .02, 'Q2_2018')
earns_q3 = Earnings('CLVS', .05, 'Q2_2018', 'Q2_Earnings')
earns_q4 = Earnings('CLVS', .05, 'Q3_2018', 'Q3_Earnings')
event4 = Earnings('CLVS', .05, 'Q4_2018', 'Q4_Earnings')
event5 = Event('CLVS', .1, 'Q2_2018', 'FDA_Approval')
takeout = TakeoutEvent('CLVS', 2)
event7 = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018',
               'Ph3_Data')
event8 = Event('CLVS', Distribution_MultiIndex(event8_info), 'Q2_2018',
               'Elagolix_Approval')
events = [idio, earns_q2, earns_q3, earns_q4, takeout, event8]
events = [takeout]

events_bid = [event.event_bid for event in events]
events_ask = [event.event_ask for event in events]

# Define Event Groupings
event_groupings = {}
for i in range(len(events)):
    event_groupings[i] = [events[i] for i in range(i + 1)]