Exemple #1
0
def find_events(ls_symbols, d_data):
    ''' Finding the event dataframe '''
    df_close = d_data['actual_close']
    ts_market = df_close['SPY']

    print "Finding Events"

    # Creating an empty dataframe
    df_events = copy.deepcopy(df_close)
    df_events = df_events * np.NAN

    # Time stamps for the event range
    ldt_timestamps = df_close.index
    print len(ldt_timestamps)
    lookback = 20
    bol_vals = bollinger.get_bollinger_values(ls_symbols, d_data, lookback)
    spy_bol_val = bol_vals['SPY']

    for s_sym in ls_symbols:
        sym_bol_val = bol_vals[s_sym]
        print len(sym_bol_val)
        for i in range(0, len(ldt_timestamps) - 1):
            # Get the bollinger values needed
            sym_bol_today = sym_bol_val[i]
            sym_bol_yest = sym_bol_val[i - 1]
            spy_bol_today = spy_bol_val[i]

            if sym_bol_today <= -2.0 and sym_bol_yest >= -2.0 and spy_bol_today >= 1.0:
                df_events[s_sym].ix[ldt_timestamps[i]] = 1

    return df_events
Exemple #2
0
def find_events(ls_symbols, d_data):
    ''' Finding the event dataframe '''
    df_close = d_data['actual_close']
    ts_market = df_close['SPY']

    print "Finding Events"

    # Creating an empty dataframe
    df_events = copy.deepcopy(df_close)
    df_events = df_events * np.NAN

    # Time stamps for the event range
    ldt_timestamps = df_close.index
    print len(ldt_timestamps)
    lookback = 20
    bol_vals = bollinger.get_bollinger_values(ls_symbols, d_data, lookback)
    spy_bol_val = bol_vals['SPY']

    for s_sym in ls_symbols:
        sym_bol_val = bol_vals[s_sym]
        print len(sym_bol_val)
        for i in range(0, len(ldt_timestamps)-1):
            # Get the bollinger values needed
            sym_bol_today = sym_bol_val[i]
            sym_bol_yest = sym_bol_val[i-1]
            spy_bol_today = spy_bol_val[i]

            if sym_bol_today <= -2.0 and sym_bol_yest >= -2.0 and spy_bol_today >= 1.0:
                df_events[s_sym].ix[ldt_timestamps[i]] = 1


    return df_events
Exemple #3
0
def find_events(ls_symbols, d_data):
    ''' Finding the event dataframe '''
    df_close = d_data['actual_close']
    ts_market = df_close['SPY']
    trades = []

    # Creating an empty dataframe
    df_events = copy.deepcopy(df_close)
    df_events = df_events * np.NAN

    # Time stamps for the event range
    ldt_timestamps = df_close.index
    lookback = 20
    bol_vals = bollinger.get_bollinger_values(ls_symbols, d_data, lookback)
    spy_bol_val = bol_vals['SPY']

    for s_sym in ls_symbols:
        sym_bol_val = bol_vals[s_sym]
        for i in range(1, len(ldt_timestamps)):
            # Get the bollinger values needed
            sym_bol_today = sym_bol_val[i]
            sym_bol_yest = sym_bol_val[i-1]
            spy_bol_today = spy_bol_val[i]

            if sym_bol_today <= -1.0 and sym_bol_yest >= -1.0 and spy_bol_today >= 1.0:
                buy_date = return_dt(str(ldt_timestamps[i]))
                if i+5 >= len(ldt_timestamps):
                    sell_date = return_dt(str(ldt_timestamps[-1]))
                else:
                    sell_date = return_dt(str(ldt_timestamps[i+5]))
                buy_trade = Trade(buy_date.group(1), buy_date.group(2), buy_date.group(3), s_sym, "Buy", 100)
                sell_trade = Trade(sell_date.group(1), sell_date.group(2), sell_date.group(3), s_sym, "Sell", 100)
                trades.append(buy_trade)
                trades.append(sell_trade)



    return trades
Exemple #4
0
def find_events(ls_symbols, d_data):
    """ Finding the event dataframe """
    df_close = d_data["actual_close"]
    ts_market = df_close["SPY"]
    trades = []

    # Creating an empty dataframe
    df_events = copy.deepcopy(df_close)
    df_events = df_events * np.NAN

    # Time stamps for the event range
    ldt_timestamps = df_close.index
    lookback = 20
    bol_vals = bollinger.get_bollinger_values(ls_symbols, d_data, lookback)
    spy_bol_val = bol_vals["SPY"]

    for s_sym in ls_symbols:
        sym_bol_val = bol_vals[s_sym]
        for i in range(1, len(ldt_timestamps)):
            # Get the bollinger values needed
            sym_bol_today = sym_bol_val[i]
            sym_bol_yest = sym_bol_val[i - 1]
            spy_bol_today = spy_bol_val[i]

            if sym_bol_today <= -1.0 and sym_bol_yest >= -1.0 and spy_bol_today >= 1.0:
                buy_date = return_dt(str(ldt_timestamps[i]))
                if i + 5 >= len(ldt_timestamps):
                    sell_date = return_dt(str(ldt_timestamps[-1]))
                else:
                    sell_date = return_dt(str(ldt_timestamps[i + 5]))
                buy_trade = Trade(buy_date.group(1), buy_date.group(2), buy_date.group(3), s_sym, "Buy", 100)
                sell_trade = Trade(sell_date.group(1), sell_date.group(2), sell_date.group(3), s_sym, "Sell", 100)
                trades.append(buy_trade)
                trades.append(sell_trade)

    return trades