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)
print(crbp.earnings_events)
print(TakeoutParams)
print(crbp.takeout_event)
print(crbp.events)
Ejemplo n.º 2
0
        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(events, key=lambda evt: Timing(evt.timing_descriptor).center_date)
pprint(sorted_events)

timing_descriptors = [evt.timing_descriptor for evt in events]
pprint(timing_descriptors)
center_dates = [Timing(timing_descriptor).center_date for timing_descriptor in timing_descriptors]
pprint(center_dates)
Ejemplo n.º 3
0
from All_Events import sorted_events
from Event_Module import IdiosyncraticVol, TakeoutEvent, Earnings
from Timing_Module import Timing
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import datetime as dt
from datetime import timedelta

events = [
    evt for evt in sorted_events
    if not isinstance(evt, (IdiosyncraticVol, TakeoutEvent))
]
dates = [Timing(evt.timing_descriptor).center_date for evt in events]
event_mean_moves = [evt.get_distribution().mean_move for evt in events]

color_scheme = {'Earnings': 1, 'Other': 2}

event_types = []
for evt in events:
    if isinstance(evt, Earnings):
        event_types.append('Earnings')
    else:
        event_types.append('Other')

scatter_colors = [color_scheme[event_type] for event_type in event_types]
scatter_sizes = [(mean_move * 100) * 50 for mean_move in event_mean_moves]
print(events, dates, event_mean_moves, event_types, sep='\n')

#X = pd.to_datetime(dates)
bar_heights = event_mean_moves
Ejemplo n.º 4
0
def get_event_timeline(events: 'list of events', symbol: 'str' = ''):
    events = [evt for evt in events if not isinstance(evt, (IdiosyncraticVol, TakeoutEvent))]
    dates = [Timing(evt.timing_descriptor).center_date for evt in events]
    event_mean_moves = [evt.get_distribution().mean_move for evt in events]

    color_scheme = {'Earnings': 1, 'Other': 2}
    event_classes = set([type(evt) for evt in events])

    color_scheme = {}
    i = 1
    for cls in event_classes:
        color_scheme[cls] = i
        i += 1
        
    event_types = []
    for evt in events:
        event_types.append(type(evt))

    scatter_colors = [color_scheme[event_type] for event_type in event_types]
    scatter_sizes = [(mean_move*100)*50 for mean_move in event_mean_moves] 

    print(events, dates, event_mean_moves, event_types, sep='\n')

    bar_heights = event_mean_moves
    fig, ax1 = plt.subplots(1)
    ax1.scatter(dates,
                bar_heights,
                c = scatter_colors,
                marker = 's',
                s = scatter_sizes)


    # Set Error Bars
    x_error_bars = [timedelta(5) for i in range(len(dates))]
    y_error_bars = [0 for i in range(len(dates))]
    x_error_bars = [Timing(evt.timing_descriptor).timing_duration*.475 for evt in events]
    #y_error_bars = [evt.event_width*.475 for evt in events]

    ax1.errorbar(dates,
                 bar_heights,
                 xerr = x_error_bars,
                 yerr = y_error_bars,
                 ls='none')

    bar_width = .5

    ax1.bar(dates,
               bar_heights,
               width = bar_width,
               label = 'Event Mean Move',
               color = 'black'
               #marker='s',
               #s = 250
               )

    for i in range(len(events)):
        ax1.annotate(s = repr(events[i]),
                     xy = (dates[i], event_mean_moves[i]),
                     xytext = (dates[i], event_mean_moves[i]+.00875 + scatter_sizes[i]*.01*.01*.025),
                     ha='center',
                     fontsize=10.0)

    #fig.autofmt_xdate()
    # everything after this is turning off stuff that's plotted by default
    """
    ax1.yaxis.set_visible(False)
    ax1.spines['right'].set_visible(False)
    ax1.spines['left'].set_visible(False)
    ax1.spines['top'].set_visible(False)
    """
    #xticks = [dt.date.today(), dt.date(2018, 7, 1), dt.date(2018, 10, 1), dt.date(2019, 1, 1)]
    #xticks = dates
    xticks = [dt.date(2018, m, 1) for m in [4, 5, 6, 6, 7, 8, 9, 10, 11, 12]]
    ax1.set_xticks(xticks)
    ax1.set_yticks(np.arange(0, .20, .05))
    ax1.set_xticklabels([t.strftime('%-m/%-d/%y') for t in xticks])
    ax1.set_yticklabels(["{:.1f}%".format(y*100) for y in ax1.get_yticks()])
    ax1.xaxis.label.set_color('darkblue')
    ax1.yaxis.label.set_color('darkblue')
    ax1.title.set_color('saddlebrown')

    axes_fontsize = 10.0
    plt.xticks(rotation=45, fontsize = axes_fontsize)
    plt.yticks(fontsize = axes_fontsize)
    ax1.xaxis.set_ticks_position('bottom')
    #ax1.tick_params(axis ='y', direction = 'in', pad = -35)
    ax1.yaxis.tick_right()
    #ax1.get_yaxis().set_ticklabels([])

    min_date = min([Timing(evt.timing_descriptor).event_start_date for evt in events])
    max_date = max([Timing(evt.timing_descriptor).event_end_date for evt in events])
    timeD = timedelta(20)
    plt.xlim(min_date - timeD, max_date + timeD)


    label_fontsize = 12
    plt.xlabel('Date', fontsize = label_fontsize, fontweight = 'bold')
    plt.ylabel('Event Magnitude', fontsize = label_fontsize, fontweight = 'bold')
    #plt.yticks(np.arange(0, .3, .025))
    plt.title('{} Event Calendar'.format(symbol), fontsize = label_fontsize*1.5, fontweight = 'bold' )

    ax1.title.set_position([.525, 1.025])
    #ax1.grid(True)
    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()
    plt.show()
Ejemplo n.º 5
0
 def sorted_events(self):
     return sorted(
         self.events,
         key=lambda evt: Timing(evt.timing_descriptor).center_date)
Ejemplo n.º 6
0
from All_Events import sorted_events
from Event_Module import IdiosyncraticVol, TakeoutEvent, Earnings
from Timing_Module import Timing
import matplotlib.pyplot as plt
#plt.style.use('bmh')
import pandas as pd
import numpy as np
import datetime as dt
from datetime import timedelta

events = [
    evt for evt in sorted_events
    if not isinstance(evt, (IdiosyncraticVol, TakeoutEvent))
]
dates = [Timing(evt.timing_descriptor).center_date for evt in events]
event_mean_moves = [evt.get_distribution().mean_move for evt in events]

color_scheme = {'Earnings': 1, 'Other': 2}
event_classes = set([type(evt) for evt in events])

color_scheme = {}
i = 1
for cls in event_classes:
    color_scheme[cls] = i
    i += 1

event_types = []
for evt in events:
    event_types.append(type(evt))

scatter_colors = [color_scheme[event_type] for event_type in event_types]