Ejemplo n.º 1
0
 def __init__(self, stock_period, feature_desc = False, default_periods = [20,10,5,80,40]):
     self.feat_lookup = {"SMA": ft.featMA,
                         "RSI": ft.featRSI,
                         "AROON": ft.featAroon,
                         "BOLL": ft.featBollinger,
                         "MOM": ft.featMomentum,
                         "EMA": ft.featEMA,
                         "MKTCORR": lambda data, lLookback = 20: { stock_period.symbol: self.feat_market_corr(lLookback) }
                         }
     self.stock_period = stock_period
     self.relative_data = ftu.getMarketRel(stock_period.as_hash(), sRel= stock_period.market_symbol)
     self.default_periods = default_periods
     if feature_desc == False:
         self.feature_desc = {"SMA": self.default_periods, 
                              "RSI": self.default_periods,
                              "AROON": self.default_periods,
                              "BOLL": self.default_periods,
                              "MOM": self.default_periods,
                              "EMA": self.default_periods,
                              "MKTCORR": self.default_periods
                              }
     else:
         self.feature_desc = feature_desc
     self.feature_data = np.array([])
     self.init_data()
Ejemplo n.º 2
0
def get_features_for_period(symbol, period_start, period_end, threshold=0.00001, pad_days = 100):
    # we are adding pad days for technical indicators to reach back to
    extra_pad_days = int(pad_days * 1.45) # account for weekends and holidays when market isn't open
    close_data = get_data([symbol,'$SPX'], period_start - dt.timedelta(days=extra_pad_days), period_end)
    #close_data = get_data([symbol,'$SPX'], period_start, period_end)
    data_relative = ftu.getMarketRel({'close':  close_data})

    dfX = get_relative_features(data_relative, symbol)
    five_day_return = five_day_returns(data_relative)

    #five_day_pos_neg = map(lambda x: 0 if x < 0 else 1, train_five_day[symbol])
    five_day_simple_class = map(classifier_func(threshold), five_day_return[symbol])
    five_day_validation_class = map(classifier_func(0.00001), five_day_return[symbol])
    #XXX need to dump the pad days here
    start_index = index_of_date(dfX.index, period_start)
    #print dfX[:][:130]
    dfX = dfX[:][start_index:]
    #print dfX[:][:50]
    five_day_simple_class = five_day_simple_class[start_index:]
    five_day_validation_class = five_day_validation_class[start_index:]
    close_data = close_data[:][start_index:]
    return dfX, five_day_simple_class, close_data, five_day_validation_class