def upper_bollinger_feature(eq, period=20, stds=2): upper_bol_vec, _ = eq.bollinger_bands(period, stds) upper_bol_vec = np.array(upper_bol_vec) upper_bol_vec = upper_bol_vec.T return [Indicator(upper_bol_vec)]
def macd_signal(eq, slow_period, fast_period): macd_sig = np.array( Indicators.ema( np.array(Indicators.macd(eq.closes, slow_period, fast_period)), 9)) macd_sig = macd_sig.T return [Indicator(macd_sig)]
def lower_bollinger_feature(eq, period=20, stds=2): _, lower_bol_vec = eq.bollinger_bands(period, stds) lower_bol_vec = np.array(lower_bol_vec) lower_bol_vec = lower_bol_vec.T return [Indicator(lower_bol_vec)]
def oil_feature(): wti_file = os.path.join('../', 'commodities', 'OIL') wti = Equity(wti_file) wti_closes = np.array(wti.closes) wti_closes = wti_closes.T return [Indicator(wti_closes)]
def snp_feature(): snp_file = os.path.join('../', 'indexes', 'SNP') snp_eq = Equity(snp_file) snp_closes = np.array(snp_eq.closes) snp_closes = snp_closes.T return [Indicator(snp_closes)]
def reit_feature(): reit_file = os.path.join('../', 'indexes', 'RE') reit_eq = Equity(reit_file) reit_closes = np.array(reit_eq.closes) reit_closes = reit_closes.T return [Indicator(reit_closes)]
def macd_raw_feature(eq, slow_period, fast_period): """ Generates a feature vector of macd_raw for the last num_days """ macd_raw_vec = np.array( Indicators.macd(eq.closes, slow_period, fast_period)) macd_raw_vec = macd_raw_vec.T return [Indicator(macd_raw_vec)]
def olhc_feature(eq): ohlc_vec = eq.ohlc() return [Indicator(ohlc_vec)]
def prings_feature(eq): prings_vec = np.array(Indicators.prings_know_sure_thing(eq.closes)) prings_vec = prings_vec.T return [Indicator(prings_vec)]
def rsi_feature(eq, period=20, type='sma'): rsi_vec = np.array(Indicators.rsi(eq.closes, period, type)) rsi_vec = rsi_vec.T return [Indicator(rsi_vec)]
def trix_vec_feature(eq): trix_vec = np.array(Indicators.trix_indicator(eq.closes)) trix_vec = trix_vec.T return [Indicator(trix_vec)]
def kst_trix_vec_feature(eq): kst_trix_vec = np.array(Indicators.kst_trix_indicator(eq.closes)) kst_trix_vec = kst_trix_vec.T return [Indicator(kst_trix_vec)]
def bop_feature(eq): bop_vec = np.array(eq.balance_of_power()) bop_vec = bop_vec.T return [Indicator(bop_vec)]
def atr_feature(eq, period): atr_vec = np.array(Indicators.average_true_range(eq, period)) atr_vec = atr_vec.T return [Indicator(atr_vec)]
def gop_feature(eq, period): gop_vec = np.array(eq.gop_range_index(period)) gop_vec = gop_vec.T return [Indicator(gop_vec)]
def volume_feature(eq): vol_vec = np.array(eq.volumes) vol_vec = vol_vec.T return [Indicator(vol_vec)]
def wilder_feature(eq, period): wilder_vec = np.array(Indicators.ema(eq.closes, period, 'wilder')) wilder_vec = wilder_vec.T return [Indicator(wilder_vec)]
def ema_feature(eq, period): ema_vec = np.array(Indicators.ema(eq.closes, period)) ema_vec = ema_vec.T return [Indicator(ema_vec)]
def sma_feature(eq, period): sma_vec = np.array(Indicators.sma(eq.closes, period)) sma_vec = sma_vec.T return [Indicator(sma_vec)]
def close_feature(eq): close_vec = np.array(eq.closes) close_vec = close_vec.T return [Indicator(close_vec)]
def accum_swing_feature(eq): accum_swing_vec = np.array(eq.accumulative_swing_index()) accum_swing_vec = accum_swing_vec.T return [Indicator(accum_swing_vec)]
def rainbow_ma(prices, periods=(1, 3, 5, 7, 9)): return [ Indicator(Indicators.sma(prices, period).T) for period in periods ]