コード例 #1
0
 def get_distribution(self, expiry):
     time_to_expiry = get_time_to_expiry(expiry)
     distribution_df = copy.deepcopy(self.event_input_distribution_df)
     distribution_df.loc[:,
                         'Pct_Move'] *= self.mult * self.idio_mult * math.sqrt(
                             time_to_expiry)
     distribution_df.loc[:,
                         'Relative_Price'] = distribution_df.loc[:,
                                                                 'Pct_Move'] + 1
     return Distribution(distribution_df)
コード例 #2
0
class Stock(object):
    event8_info = pd.read_excel('CLVS_RiskScenarios.xlsx',
                                header=[0],
                                index_col=[0, 1],
                                sheet_name='Sub_States')

    fda_meeting = Event('CLVS', .1, 'Q2_2018', 'FDA Meeting')
    data = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018',
                 'Ph3_Data')
    elagolix = ComplexEvent('CLVS', Distribution_MultiIndex(event8_info),
                            dt.date(2018, 6, 1), 'Elagolix Approval')
    all_other_events = [data, fda_meeting, elagolix]

    def __init__(self, stock):
        self.stock = stock

    @property
    def idio_vol(self):
        return IdiosyncraticVol(self.stock, .05)

    @property
    def earnings_events(self):
        return get_earnings_events(self.stock)

    @property
    def takeout_event(self):
        return TakeoutEvent(self.stock, TakeoutParams.loc[self.stock,
                                                          'Bucket'])

    @property
    def other_events(self):
        if self.stock == 'CLVS':
            return self.all_other_events
        else:
            return []

    @property
    def events(self):
        return self.earnings_events + [self.takeout_event
                                       ] + [self.idio_vol] + self.other_events

    @property
    def sorted_events(self):
        return sorted(
            self.events,
            key=lambda evt: Timing(evt.timing_descriptor).center_date)

    def get_event_timeline(self):
        get_event_timeline(self.events, self.stock)
コード例 #3
0
    def get_distribution(self, expiry: 'dt.date', *args, **kwargs):
        time_to_expiry = get_time_to_expiry(expiry)
        prob_takeout_by_expiry = time_to_expiry * self.takeout_prob
        prob_no_takeout_by_expiry = 1 - prob_takeout_by_expiry

        relative_price_takeout = (1 + self.takeout_premium)
        relative_price_no_takeout = 1 - (prob_takeout_by_expiry *
                                         self.takeout_premium) / (
                                             prob_no_takeout_by_expiry)

        distribution_info = {
            'States': ['Takeout', 'No Takeout'],
            'Prob': [prob_takeout_by_expiry, prob_no_takeout_by_expiry],
            'Relative_Price':
            [relative_price_takeout, relative_price_no_takeout],
            'Pct_Move': [self.takeout_premium, relative_price_no_takeout - 1]
        }

        distribution_df = pd.DataFrame(distribution_info).set_index(
            'States').loc[:, ['Prob', 'Pct_Move', 'Relative_Price']]
        return Distribution(distribution_df)
コード例 #4
0
    def get_distribution(self, expiry=None, *args, **kwargs):
        event_by_expiry = event_prob_by_expiry(self.timing_descriptor, expiry)
        event_not_by_expiry = 1 - event_by_expiry

        distribution_df = copy.deepcopy(self.event_input_distribution_df)
        distribution_df.loc[:, 'Pct_Move'] *= self.mult * self.idio_mult
        distribution_df.loc[:,
                            'Relative_Price'] = distribution_df.loc[:,
                                                                    'Pct_Move'] + 1
        distribution_df.loc[:, 'Prob'] *= event_by_expiry

        no_event_scenario = {
            'State': ['No_Event'],
            'Prob': [event_not_by_expiry],
            'Pct_Move': [0],
            'Relative_Price': [1.0]
        }

        no_event_scenario = pd.DataFrame(no_event_scenario).set_index(
            'State').loc[:, ['Prob', 'Pct_Move', 'Relative_Price']]

        distribution_df = distribution_df.append(no_event_scenario)
        return Distribution(distribution_df)
コード例 #5
0
        return self.earnings_events + [self.takeout_event]


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, dt.date(2018, 5, 15), 'Q2_2018')
earns_q3 = Earnings('CLVS', .05, dt.date(2018, 8, 15), 'Q3_2018')
earns_q4 = Earnings('CLVS', .05, dt.date(2018, 11, 15), 'Q4_2018')
fda_meeting = Event('CLVS', .1, 'Q2_2018', 'FDA Meeting')
data = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018',
             'Ph3_Data')
elagolix = ComplexEvent('CLVS', Distribution_MultiIndex(event8_info),
                        dt.date(2018, 6, 1), 'Elagolix Approval')
events = [
    idio, takeout, pres_elec, earns_q2, earns_q3, earns_q4, fda_meeting,
    elagolix
]
earnings = get_earnings_events('CLVS')
sorted_events = sorted(
    events, key=lambda evt: Timing(evt.timing_descriptor).center_date)
print(earnings)

crbp = Stock('CRBP')
print(crbp)
print(crbp.stock)
コード例 #6
0
expiries = [expiry3]

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

event0 = IdiosyncraticVol('CLVS', .15)
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', 2)
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]
#events = [event0, event6]

event0_bid = IdiosyncraticVol('CLVS', .125)
event1_bid = SysEvt_PresElection('CLVS', .01, 'Q2_2018')
event2_bid = Event('CLVS', .03, 'Q2_2018', 'Q2_Earnings')
event3_bid = Event('CLVS', .03, 'Q3_2018', 'Q3_Earnings')
event4_bid = Event('CLVS', .05, 'Q3_2018', 'Investor_Day')
event5_bid = Event('CLVS', .075, 'Q2_2018', 'FDA_Approval')
event6_bid = TakeoutEvent('CLVS', 3)
event7_bid = Event('CLVS', Distribution(pd.read_csv('CLVS.csv')), 'Q2_2018',
                   'Ph3_Data')
コード例 #7
0
from Event_Module import IdiosyncraticVol
import datetime as dt
from Distribution_Module import Distribution, float_to_bs_distribution
import numpy as np
import pandas as pd

event = IdiosyncraticVol('CLVS', .1)
distribution = event.get_distribution(dt.date(2018,5,10))
print(distribution.mean_move, distribution.average_move, distribution.straddle)
distribution.get_histogram()

event_input_distribution = Distribution(event.event_input_distribution_df)
print(event_input_distribution.mean_move, event_input_distribution.average_move, event_input_distribution.straddle)

event_input_dist = event.event_input
print(event_input_dist.mean_move, event_input_dist.average_move, event_input_dist.straddle)

dist = float_to_bs_distribution(.5)
print("HERE",dist.mean_move, dist.average_move, dist.straddle)
コード例 #8
0
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)