Example #1
0
	def momentum(self):
		adx = talib.ADX(self.high,self.low,self.close,self.period)
		adxr = talib.ADXR(self.high,self.low,self.close,self.period)
		apo = talib.APO(self.high,self.low,self.close,self.period)
		aroondown, aroonup = talib.AROON(self.high, self.low, period)
		aroonosc = talib.AROONOSC(self.high,self.low,self.period)
		bop  = talib.BOP(self.opens,self.high,self.low,self.close)
		cci = talib.CCI(self.high,self.low,self.close,self.period)
		cmo = talib.CMO(self.close,self.period)
		dx = talib.DX(self.high,self.low,self.close,self.period)
		macd, macdsignal, macdhist = talib.MACD(self.close, fastperiod=period, slowperiod=period*5, signalperiod=period*2)
		macd1, macdsignal1, macdhist1 = talib.MACDEXT(self.close, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0)
		macd2, macdsignal2, macdhist2 = talib.MACDFIX(self.close, signalperiod=9)
		mfi = talib.MFI(self.high, self.low, self.close, self.volume, timeperiod=14)
		minus_di = talib.MINUS_DI(self.high, self.low, self.close, timeperiod=14)
		minus_dm = talib.MINUS_DM(self.high, self.low, timeperiod=14)
		mom = talib.MOM(self.close, timeperiod=10)
		plus_di = talib.PLUS_DI(self.high, self.low, self.close, timeperiod=14)
		plus_dm = talib.PLUS_DM(self.high, self.low, timeperiod=14)
		ppo  = talib.PPO(self.close, fastperiod=12, slowperiod=26, matype=0)
		roc  = talib.ROC(self.close, timeperiod=10)
		rocp = talib.ROCP(self.close, timeperiod=10)
		rocr = talib.ROCR(self.close, timeperiod=10)
		rocr100 = talib.ROCR100(self.close, timeperiod=10)
		rsi =  talib.RSI(self.close, timeperiod=14)
		slowk, slowd = talib.STOCH(self.high, self.low, self.close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0)
		fastk, fastd = talib.STOCHF(self.high, self.low, self.close, fastk_period=5, fastd_period=3, fastd_matype=0)
		fastk1, fastd1 = talib.STOCHRSI(self.close, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0)
		trix = talib.TRIX(self.close, timeperiod=30)
		ultosc = talib.ULTOSC(self.high, self.low, self.close, timeperiod1=7, timeperiod2=14, timeperiod3=28)
		willr = talib.WILLR(self.high, self.low, self.close, timeperiod=14)
Example #2
0
def trix(source, periods):
    price = source['close']

    for p in periods:
        trix_name = 'TRIX_' + str(p)
        rsi = talib.TRIX(price, p)
        source = source.join(pd.Series(rsi, name=trix_name))

    # Trends
    for p in periods:
        trix_name = 'TRIX_' + str(p)
        source = do_uptrend(source, trix_name)

    # Over
    for i in range(len(periods)):
        for j in range(i + 1, len(periods)):
            trix_name1 = 'TRIX_' + str(periods[i])
            trix_name2 = 'TRIX_' + str(periods[j])
            source = do_over(source, trix_name1, trix_name2)

    # Above
    for p in periods:
        trix_name = 'TRIX_' + str(p)
        source = do_above(source, trix_name, 0)

    # Drop
    for p in periods:
        trix_name = 'TRIX_' + str(p)
        source = source.drop(columns=[trix_name])

    return source
Example #3
0
def test_trix():
    '''test TA.TRIX'''

    ma = TA.TRIX(ohlc, 20)
    talib_ma = talib.TRIX(ohlc['close'], timeperiod=20)

    assert round(talib_ma[-1], 2) == round(ma.values[-1], 2)
Example #4
0
 def compTRIX(self):
     tx = talib.TRIX(self.close,timeperiod=self.lookback)
     self.removeNullID(tx)
     self.rawFeatures['TRIX'] = tx
     
     FEATURE_SIZE_DICT['TRIX'] = 1
     return
def trix(close_ts, timeperiod=30):
    import talib
    close_np = close_ts.cpu().detach().numpy()
    close_df = pd.DataFrame(close_np)
    trix = close_df.apply(lambda x: talib.TRIX(x, timeperiod=30))
    trix_ts = torch.tensor(trix.values, dtype=close_ts.dtype, device=close_ts.device)
    return trix_ts
Example #6
0
def trix(close, n):
    try:
        trix_data = talib.TRIX(close, timeperiod=n)

        return trix_data
    except Exception as e:
        raise (e)
Example #7
0
def extract_features(data):
    high = data['High']
    low = data['Low']
    close = data['Close']
    volume = data['Volume']
    open_ = data['Open']
    
    data['ADX'] = ta.ADX(high, low, close, timeperiod=19)
    data['CCI'] = ta.CCI(high, low, close, timeperiod=19)  
    data['CMO'] = ta.CMO(close, timeperiod=14)
    data['MACD'], X, Y = ta.MACD(close, fastperiod=10, slowperiod=30, signalperiod=9)
    data['MFI'] = ta.MFI(high, low, close, volume, timeperiod=19)
    data['MOM'] = ta.MOM(close, timeperiod=9)
    data['ROCR'] = ta.ROCR(close, timeperiod=12) 
    data['RSI'] = ta.RSI(close, timeperiod=19)  
    data['STOCHSLOWK'], data['STOCHSLOWD'] = ta.STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0)
    data['TRIX'] = ta.TRIX(close, timeperiod=30)
    data['WILLR'] = ta.WILLR(high, low, close, timeperiod=14)
    data['OBV'] = ta.OBV(close, volume)
    data['TSF'] = ta.TSF(close, timeperiod=14)
    data['NATR'] = ta.NATR(high, low, close)#, timeperiod=14)
    data['ULTOSC'] = ta.ULTOSC(high, low, close)
    data['AROONOSC'] = ta.AROONOSC(high, low, timeperiod=14)
    data['BOP'] = ta.BOP(open_, high, low, close)
    data['LINEARREG'] = ta.LINEARREG(close)
    data['AP0'] = ta.APO(close, fastperiod=9, slowperiod=23, matype=1)
    data['TEMA'] = ta.TRIMA(close, 29)
    
    return data
Example #8
0
def getMomentumIndicators(df):

    high = df['High']
    low = df['Low']
    close = df['Close']
    open = df['Open']
    volume = df['Volume']
    df['ADX'] = ta.ADX(high, low, close, timeperiod=14)
    df['SMA'] = ta.ADXR(high, low, close, timeperiod=14)
    df['APO'] = ta.APO(close, fastperiod=12, slowperiod=26, matype=0)
    df['AROONDOWN'], df['AROOONUP'] = ta.AROON(high, low, timeperiod=14)
    df['AROONOSC'] = ta.AROONOSC(high, low, timeperiod=14)
    df['BOP'] = ta.BOP(open, high, low, close)
    df['CCI'] = ta.CCI(high, low, close, timeperiod=14)
    df['CMO'] = ta.CMO(close, timeperiod=14)
    df['DX'] = ta.DX(high, low, close, timeperiod=14)
    df['MACD'], df['MACDSIGNAL'], df['MACDHIST'] = ta.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
    df['MFI'] = ta.MFI(high, low, close, volume, timeperiod=14)
    df['MINUS_DI'] = ta.MINUS_DI(high, low, close, timeperiod=14)
    df['MINUS_DM']= ta.MINUS_DM(high, low, timeperiod=14)
    df['MOM'] = ta.MOM(close, timeperiod=10)
    df['PLUS_DM'] =ta.PLUS_DM(high, low, timeperiod=14)
    df['PPO'] = ta.PPO(close, fastperiod=12, slowperiod=26, matype=0)
    df['ROC'] = ta.ROC(close, timeperiod=10)
    df['ROCP'] = ta.ROCP(close, timeperiod=10)
    df['ROCR'] = ta.ROCR(close, timeperiod=10)
    df['ROCR100'] = ta.ROCR100(close, timeperiod=10)
    df['RSI'] = ta.RSI(close, timeperiod=14)
    df['SLOWK'], df['SLOWD'] = ta.STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0)
    df['FASTK'], df['FASTD'] = ta.STOCHF(high, low, close, fastk_period=5, fastd_period=3, fastd_matype=0)
    df['FASTK2'], df['FASTD2'] = ta.STOCHRSI(close, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0)
    df['TRIX'] = ta.TRIX(close, timeperiod=30)
    df['ULTOSC'] = ta.ULTOSC(high, low, close, timeperiod1=7, timeperiod2=14, timeperiod3=28)
    df['WILLR'] = ta.WILLR(high, low, close, timeperiod=14)
Example #9
0
 def trix(self, n, array=False):
     """
     TRIX.
     """
     result = talib.TRIX(self.close, n)
     if array:
         return result
     return result[-1]
Example #10
0
def trix(source, p):
    price = source['Close']

    trix_name = 'TRIX_' + str(p)
    rsi = talib.TRIX(price, p)
    source = source.join(pd.Series(rsi, name=trix_name))

    return source
Example #11
0
 def trix(self, n: int, array: bool = False) -> Union[float, np.ndarray]:
     """
     TRIX.
     """
     result = talib.TRIX(self.close, n)
     if array:
         return result
     return result[-1]
 def TRIX(self, timeperiod=30):
     real_data = np.array([self.df.close], dtype='f8')
     trix = talib.TRIX(real_data[0], timeperiod=timeperiod)
     # return go.Scatter(
     #     x=self.df.index,
     #     y=trix,
     #     name='TRIX'
     # )
     return trix
Example #13
0
def TRIX(close, timeperiod=30):
    ''' 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA

    分组: Momentum Indicator 动量指标

    简介:

    real = TRIX(close, timeperiod=30)
    '''
    return talib.TRIX(close, timeperiod)
Example #14
0
 def TRIX(self, stockhist):
     trix = stockhist.copy()
     trix['trix'] = tal.TRIX(trix['close'], timeperiod=15)  # 计算TRIX
     trix['matrix'] = tal.MA(trix['trix'], 45, 0)
     trix['signal'] = 0
     trix.loc[trix['trix'] > trix['matrix'], 'signal'] = 1
     trix.loc[trix['trix'] <= trix['matrix'], 'signal'] = 0
     trix['signal'] = trix['signal'].fillna(method='ffill')
     trix = trix[['date', 'dailyreturn', 'signal']].copy()
     return (trix)
Example #15
0
 def _get_indicators(security, open_name, close_name, high_name, low_name,
                     volume_name):
     """
     expand the features of the data through technical analysis across 26 different signals
     :param security: data which features are going to be expanded
     :param open_name: open price column name
     :param close_name: close price column name
     :param high_name: high price column name
     :param low_name: low price column name
     :param volume_name: traded volumn column name
     :return: expanded and extracted data
     """
     open_price = security[open_name].values
     close_price = security[close_name].values
     low_price = security[low_name].values
     high_price = security[high_name].values
     volume = security[volume_name].values if volume_name else None
     security['MOM'] = talib.MOM(close_price)
     security['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
     security['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
     security['SINE'], security['LEADSINE'] = talib.HT_SINE(close_price)
     security['INPHASE'], security['QUADRATURE'] = talib.HT_PHASOR(
         close_price)
     security['ADXR'] = talib.ADXR(high_price, low_price, close_price)
     security['APO'] = talib.APO(close_price)
     security['AROON_UP'], _ = talib.AROON(high_price, low_price)
     security['CCI'] = talib.CCI(high_price, low_price, close_price)
     security['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price)
     security['PPO'] = talib.PPO(close_price)
     security['MACD'], security['MACD_SIG'], security[
         'MACD_HIST'] = talib.MACD(close_price)
     security['CMO'] = talib.CMO(close_price)
     security['ROCP'] = talib.ROCP(close_price)
     security['FASTK'], security['FASTD'] = talib.STOCHF(
         high_price, low_price, close_price)
     security['TRIX'] = talib.TRIX(close_price)
     security['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price)
     security['WILLR'] = talib.WILLR(high_price, low_price, close_price)
     security['NATR'] = talib.NATR(high_price, low_price, close_price)
     security['RSI'] = talib.RSI(close_price)
     security['EMA'] = talib.EMA(close_price)
     security['SAREXT'] = talib.SAREXT(high_price, low_price)
     # security['TEMA'] = talib.EMA(close_price)
     security['RR'] = security[close_name] / security[close_name].shift(
         1).fillna(1)
     security['LOG_RR'] = np.log(security['RR'])
     if volume_name:
         security['MFI'] = talib.MFI(high_price, low_price, close_price,
                                     volume)
         # security['AD'] = talib.AD(high_price, low_price, close_price, volume)
         # security['OBV'] = talib.OBV(close_price, volume)
         security[volume_name] = np.log(security[volume_name])
     security.drop([open_name, close_name, high_name, low_name], axis=1)
     security = security.dropna().astype(np.float32)
     return security
Example #16
0
    def add_tech_ind(self, price_map):
        # Visit for technical indicator documentation: http://mrjbq7.github.io/ta-lib/funcs.html

        new_price_map = {}

        for symbol in price_map:
            symbol_data = price_map[symbol]
            symbol_data['ts_ema_30'] = ta.TRIX(symbol_data['open'], timeperiod=30)
            new_price_map[symbol] = symbol_data

        return new_price_map
Example #17
0
 def TRIX(self, length):
     records = self.platform.get_kline(self.time_frame)
     records.reverse()
     kline_length = len(records)
     close_array = np.zeros(kline_length)
     t = 0
     for item in records:
         close_array[t] = item[4]
         t += 1
     result = (talib.TRIX(close_array, timeperiod=length))
     return result
Example #18
0
    def TRIX(self, window=14):
        temp = self.origin
        # .sort_index(ascending=False)
        simple_trix = ta.TRIX(temp.close.values, timeperiod=window)

        # Reverse before placing in

        trix_name = "TRIX_{}".format(window)
        aroon_down_name = "TRIX_{}".format(window)
        self.info['main'].loc[:, trix_name] = list(simple_trix)
        # self.info['main'].loc[:, aroon_down_name] = list(aroondown)
        return self
Example #19
0
 def get_momentum_studies(open, low, high, close, volume, df):
     # Momentum studies
     # https://mrjbq7.github.io/ta-lib/func_groups/momentum_indicators.html
     df['MACD'], df['MACD_SIGN'], df['MACD_HIST'] = talib.MACD(
         close, fastperiod=12, slowperiod=26, signalperiod=9)
     df['STOCH-SLOW-K'], df['STOCH-SLOW-D'] = talib.STOCH(high,
                                                          low,
                                                          close,
                                                          fastk_period=5,
                                                          slowk_period=3,
                                                          slowk_matype=0,
                                                          slowd_period=3,
                                                          slowd_matype=0)
     df['STOCH-FAST-K'], df['STOCH-FAST-D'] = talib.STOCHF(high,
                                                           low,
                                                           close,
                                                           fastk_period=5,
                                                           fastd_period=3,
                                                           fastd_matype=0)
     df['STOCH-RSI-K'], df['STOCH-RSI-D'] = talib.STOCHRSI(close,
                                                           timeperiod=14,
                                                           fastk_period=5,
                                                           fastd_period=3,
                                                           fastd_matype=0)
     df['AROON-DOWN'], df['AROON-UP'] = talib.AROON(high,
                                                    low,
                                                    timeperiod=14)
     df["MINUS_DI"] = talib.MINUS_DI(high, low, close, timeperiod=14)
     df["MINUS_DM"] = talib.MINUS_DM(high, low, timeperiod=14)
     df["PLUS_DI"] = talib.PLUS_DI(high, low, close, timeperiod=14)
     df["PLUS_DM"] = talib.PLUS_DM(high, low, timeperiod=14)
     df["MOM"] = talib.MOM(close, timeperiod=10)
     df["MFI"] = talib.MFI(high, low, close, volume, timeperiod=14)
     df["ADX"] = talib.ADX(high, low, close, timeperiod=14)
     df["ADXR"] = talib.ADXR(high, low, close, timeperiod=14)
     df["APO"] = talib.APO(close, fastperiod=12, slowperiod=26, matype=0)
     df["AROONOSC"] = talib.AROONOSC(high, low, timeperiod=14)
     df["BOP"] = talib.BOP(open, high, low, close)
     df["CCI"] = talib.CCI(high, low, close, timeperiod=14)
     df["CMO"] = talib.CMO(close, timeperiod=14)
     df["DX"] = talib.DX(high, low, close, timeperiod=14)
     df["PPO"] = talib.PPO(close, fastperiod=12, slowperiod=26, matype=0)
     df["ROC"] = talib.ROC(close, timeperiod=10)
     df["RSI"] = talib.RSI(close, timeperiod=14)
     df["TRIX"] = talib.TRIX(close, timeperiod=30)
     df["ULT"] = talib.ULTOSC(high,
                              low,
                              close,
                              timeperiod1=7,
                              timeperiod2=14,
                              timeperiod3=28)
     df["WILLR"] = talib.WILLR(high, low, close, timeperiod=14)
Example #20
0
def add_TRIX(self, timeperiod=15, type='area', color='secondary', **kwargs):
    """1-day Rate of Change of Triple Smooth EMA."""

    if not self.has_close:
        raise Exception()

    utils.kwargs_check(kwargs, VALID_TA_KWARGS)
    if 'kind' in kwargs:
        type = kwargs['kind']

    name = 'TRIX({})'.format(str(timeperiod))
    self.sec[name] = dict(type=type, color=color)
    self.ind[name] = talib.TRIX(self.df[self.cl].values, timeperiod)
Example #21
0
    def test_trix(self):
        name = "trix"
        print_test_title(name)
        period = 30

        kls =self.klines
        ti_key = ti.TRIX(kls, self.closekey, period)
        tas = talib.TRIX(self.klines_df[self.closekey], timeperiod=period)
        print("    ti  %ss:  %s" % (name, [round(kl[ti_key], self.digits) for kl in kls[-self.display_count:]]))
        print("TA-Lib  %ss:  %s" % (name, [round(a, self.digits) for a in tas][-self.display_count:]))

        for i in range(-self.display_count, 0):
            self.assertTrue(abs(kls[i][ti_key] - tas.values[i]) < 0.01)
Example #22
0
 def OnBar(self, bar):
     if self.bar_count >= 201:
         close = np.array(self.array.close)
         signal = ta.TRIX(close, timeperiod=30)
         if signal[-1] > 0 and self.pos == 0:
             self.buy(99999,5000)
         elif signal[-1] < 0 and self.pos >0:
             self.sell(1,self.pos)
         elif signal[-1] > 0 and self.pos<0:
             self.buy_to_cover(99999,-self.pos)
         elif signal[-1] < 0 and self.pos == 0:
             self.sell_short(1,5000)
         
     self.strategy_output(self.pos)
Example #23
0
def TRIX(security_list, timeperiod=30):
    # 修复传入为单只股票的情况
    if isinstance(security_list, str):
        security_list = [security_list]
    # 计算 TRIX
    security_data = history(timeperiod * 2,
                            '1d',
                            'close',
                            security_list,
                            df=False,
                            skip_paused=True)
    trix = {}
    for stock in security_list:
        trix[stock] = talib.TRIX(security_data[stock], timeperiod)
    return trix
    def add_ta_features(self):
        obv = talib.OBV(self.close, self.volume)
        obv_mv_avg = talib.MA(obv, timeperiod=10)
        obv_mv_avg[np.isnan(obv_mv_avg)] = obv[np.isnan(obv_mv_avg)]
        difference = obv - obv_mv_avg

        self.df['obv'] = obv
        self.df['obv_signal'] = difference
        self.df['obv_cheat'] = np.gradient(difference)

        upper, middle, lower = talib.BBANDS(self.close, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)

        self.df['dn'] = lower
        self.df['mavg'] = middle
        self.df['up'] = upper
        self.df['pctB'] = (self.close - self.df.dn) / (self.df.up - self.df.dn)
        rsi14 = talib.RSI(self.close, 14)
        self.df['rsi14'] = rsi14

        macd, macdsignal, macdhist = talib.MACD(self.close, 12, 26, 9)
        self.df['macd'] = macd
        self.df['signal'] = macdsignal

        ## addtional info
        self.df['adx'] = talib.ADX(self.high, self.low, self.close, timeperiod=14)
        self.df['cci'] = talib.CCI(self.high, self.low, self.close, timeperiod=14)

        ## maximum profit
        self.df['plus_di'] = talib.PLUS_DI(self.high, self.low, self.close, timeperiod=14)

        ## lower_bound
        self.df['lower_bound'] = self.df['open'] - self.df['low'] + 1

        ## ATR
        self.df['atr'] = talib.ATR(self.high, self.low, self.close, timeperiod=14)

        ## STOCH momentum
        self.df = ta.stochastic_oscillator_k(self.df)
        self.df = ta.stochastic_oscillator_d(self.df, n=10)

        ## TRIX
        self.df['trix'] = talib.TRIX(self.close, timeperiod=5)
        self.df['trix_signal'] = ta.moving_average(self.df['trix'], n=3)
        self.df['trix_hist'] = self.df['trix'] - self.df['trix_signal']

        ## MFI

        self.df['mfi14'] = money_flow_index(self.df, 14)
Example #25
0
def TRIX(length, kline):
    """
    三重指数平滑平均线
    :param length:长度参数
    :param kline:传入指定k线数据
    :return:返回一个一维数组
    """
    records = kline
    kline_length = len(records)
    close_array = np.zeros(kline_length)
    t = 0
    for item in records:
        close_array[t] = item[4]
        t += 1
    result = (talib.TRIX(close_array, timeperiod=length))
    return result
Example #26
0
def signal_TRIX(close):
    trix = tl.TRIX(close,timeperiod=12) 
    trima = tl.MA(trix,timeperiod=20) 
    # 画出上一时间DIFF和DEA曲线
    #record(TRIX=trix[-1], TRIMA=trima[-1])
    record(TRIX_DELTA=trix[-1]-trima[-1])
    # 经过3天确认的金叉
    if trix[-1] > trima[-1] and trix[-2] > trima[-2] \
      and trix[-3] > trima[-3] and trix[-4] < trima[-4]:
        return 1
    # 经过3天确认的死叉
    if trix[-1] < trima[-1] and trix[-2] < trima[-2] \
      and trix[-3] < trima[-3] and trix[-4] > trima[-4]:
        return -1
    # 中间状态
    return 0
Example #27
0
def generate_tech_data_default(stock,
                               open_name,
                               close_name,
                               high_name,
                               low_name,
                               volume_name='vol'):
    open_price = stock[open_name].values
    close_price = stock[close_name].values
    low_price = stock[low_name].values
    high_price = stock[high_name].values
    volume = stock[volume_name].values
    data = stock.copy()
    data['MOM'] = talib.MOM(close_price)
    data['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
    data['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
    data['sine'], data['leadsine'] = talib.HT_SINE(close_price)
    data['inphase'], data['quadrature'] = talib.HT_PHASOR(close_price)
    data['ADXR'] = talib.ADXR(high_price, low_price, close_price)
    data['APO'] = talib.APO(close_price)
    data['AROON_UP'], _ = talib.AROON(high_price, low_price)
    data['CCI'] = talib.CCI(high_price, low_price, close_price)
    data['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price)
    data['PPO'] = talib.PPO(close_price)
    data['macd'], data['macd_sig'], data['macd_hist'] = talib.MACD(close_price)
    data['CMO'] = talib.CMO(close_price)
    data['ROCP'] = talib.ROCP(close_price)
    data['fastk'], data['fastd'] = talib.STOCHF(high_price, low_price,
                                                close_price)
    data['TRIX'] = talib.TRIX(close_price)
    data['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price)
    data['WILLR'] = talib.WILLR(high_price, low_price, close_price)
    data['NATR'] = talib.NATR(high_price, low_price, close_price)
    data['MFI'] = talib.MFI(high_price, low_price, close_price, volume)
    data['RSI'] = talib.RSI(close_price)
    data['AD'] = talib.AD(high_price, low_price, close_price, volume)
    data['OBV'] = talib.OBV(close_price, volume)
    data['EMA'] = talib.EMA(close_price)
    data['SAREXT'] = talib.SAREXT(high_price, low_price)
    data['TEMA'] = talib.EMA(close_price)
    #data = data.drop([open_name, close_name, high_name, low_name, volume_name, 'amount', 'count'], axis=1)
    data = drop_columns(data, [
        open_name, close_name, high_name, low_name, volume_name, 'amount',
        'count'
    ])
    data = data.dropna().astype(np.float32)
    return data
Example #28
0
def trix(client, symbol, timeframe="6m", col="close", period=14):
    """This will return a dataframe of
    1-day Rate-Of-Change(ROC) of a Triple Smooth EMA
    for the given symbol across the given timeframe

    Args:
        client (pyEX.Client): Client
        symbol (string): Ticker
        timeframe (string): timeframe to use, for pyEX.chart
        col (string): column to use to calculate
        period (int): period to calculate across

    Returns:
        DataFrame: result
    """
    df = client.chartDF(symbol, timeframe)
    return pd.DataFrame({col: df[col].values, "trix": t.TRIX(df[col].values, period)})
Example #29
0
def trix(candles: np.ndarray,
         period=18,
         sequential=False) -> Union[float, np.ndarray]:
    """
    TRIX - 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA

    :param candles: np.ndarray
    :param period: int - default: 18
    :param sequential: bool - default=False

    :return: float | np.ndarray
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    r = talib.TRIX(candles[:, 2], timeperiod=period) * 100

    return r if sequential else r[-1]
Example #30
0
 def TRIX(self, length, kline=None):
     """
     三重指数平滑平均线
     :param length:长度参数
     :param kline:回测时传入指定k线数据
     :return:返回一个一维数组
     """
     if kline:
         records = kline
     else:
         records = self.__platform.get_kline(self.__time_frame)
     kline_length = len(records)
     close_array = np.zeros(kline_length)
     t = 0
     for item in records:
         close_array[t] = item[4]
         t += 1
     result = (talib.TRIX(close_array, timeperiod=length))
     return result