示例#1
0
    def _compute_states(self):
        start = self.current_idx - self.lookback
        end = self.current_idx
        df = self._data.iloc[start:end, :]
        states = {}

        states['roc1'] = ta.ROC(df.close, timeperiod=5).iloc[-1]
        states['roc2'] = ta.ROC(df.close, timeperiod=20).iloc[-1]
        states['rsi1'] = ta.RSI(df.close, timeperiod=14).iloc[-1]
        states['rsi2'] = ta.RSI(df.close, timeperiod=28).iloc[-1]
        states['cci1'] = ta.CCI(df.high, df.low, df.close,
                                timeperiod=14).iloc[-1]
        states['cci2'] = ta.CCI(df.high, df.low, df.close,
                                timeperiod=28).iloc[-1]
        states['adx1'] = ta.ADX(df.high, df.low, df.close,
                                timeperiod=14).iloc[-1]
        states['adx2'] = ta.ADX(df.high, df.low, df.close,
                                timeperiod=28).iloc[-1]
        states['atr'] = ta.ATR(df.high, df.low, df.close,
                               timeperiod=14).iloc[-1]
        states['aroon1'] = ta.AROONOSC(df.high, df.low, timeperiod=14).iloc[-1]
        states['aroon2'] = ta.AROONOSC(df.high, df.low, timeperiod=28).iloc[-1]
        states['bop'] = ta.BOP(df.open, df.high, df.low, df.close).iloc[-1]
        states['cmo'] = ta.CMO(df.close, timeperiod=14).iloc[-1]
        states['close'] = df.close.iloc[-1]
        states['date'] = df.index[-1]
        states['position'] = self.position
        states['entry_price'] = self.entry_price
        states['entry_date'] = self.entry_date

        return states
示例#2
0
def aroonosc(high, low, timeperiod=None):
    """
	AROONOSC = Aroon Oscillator (Momentum Indicators)
	:param high:
	:param low:
	:param timeperiod:
	:return float:
	"""
    if timeperiod is None:
        timeperiod = 14
    # nejdříve vyřízneme potřebnou délku,
    # ke které přidáme jedno místo navíc,
    # protože výsledek je počítán z plné délky
    # 'timepepriod' a hodnotu navrací až v první
    # následující iteraci.
    high = high[-(timeperiod + 1):]
    low = low[-(timeperiod + 1):]
    # Převedeme na desetinná čísla s dvojitou přesností.
    high = [float(x) for x in high]
    low = [float(x) for x in low]
    # Převedeme na pole dat.
    high = numpy.asarray(high)
    low = numpy.asarray(low)
    # Výsledek
    result = talib.AROONOSC(high, low, timeperiod)
    # Převedeme z datového pole na posloupnost.
    overall = []
    for i in result:
        part = i.tolist()
        overall.append(part)
    # Z datového pole vyřízneme poslední výsledek
    # a navracíme jako desetinné číslo.
    cutedresult = float(overall[-1])
    # Vrátí desetinné číslo.
    return cutedresult
示例#3
0
def generate_feature(data):
    high = data.High.values
    low = data.Low.values
    close = data.Close.values

    feature_df = pd.DataFrame(index=data.index)
    feature_df["ADX"] = ADX = talib.ADX(high, low, close, timeperiod=14)
    feature_df["ADXR"] = ADXR = talib.ADXR(high, low, close, timeperiod=14)
    feature_df["APO"] = APO = talib.APO(close, fastperiod=12, slowperiod=26, matype=0)
    feature_df["AROONOSC"] = AROONOSC = talib.AROONOSC(high, low, timeperiod=14)
    feature_df["CCI"] = CCI = talib.CCI(high, low, close, timeperiod=14)
    feature_df["CMO"] = CMO = talib.CMO(close, timeperiod=14)
    feature_df["DX"] = DX = talib.DX(high, low, close, timeperiod=14)
    feature_df["MINUS_DI"] = MINUS_DI = talib.MINUS_DI(high, low, close, timeperiod=14)
    feature_df["MINUS_DM"] = MINUS_DM = talib.MINUS_DM(high, low, timeperiod=14)
    feature_df["MOM"] = MOM = talib.MOM(close, timeperiod=10)
    feature_df["PLUS_DI"] = PLUS_DI = talib.PLUS_DI(high, low, close, timeperiod=14)
    feature_df["PLUS_DM"] = PLUS_DM = talib.PLUS_DM(high, low, timeperiod=14)
    feature_df["PPO"] = PPO = talib.PPO(close, fastperiod=12, slowperiod=26, matype=0)
    feature_df["ROC"] = ROC = talib.ROC(close, timeperiod=10)
    feature_df["ROCP"] = ROCP = talib.ROCP(close, timeperiod=10)
    feature_df["ROCR100"] = ROCR100 = talib.ROCR100(close, timeperiod=10)
    feature_df["RSI"] = RSI = talib.RSI(close, timeperiod=14)
    feature_df["ULTOSC"] = ULTOSC = talib.ULTOSC(high, low, close, timeperiod1=7, timeperiod2=14, timeperiod3=28)
    feature_df["WILLR"] = WILLR = talib.WILLR(high, low, close, timeperiod=14)
    feature_df = feature_df.fillna(0.0)

    matrix = np.stack((
        ADX, ADXR, APO, AROONOSC, CCI, CMO, DX, MINUS_DI, ROCR100, ROC,
        MINUS_DM, MOM, PLUS_DI, PLUS_DM, PPO, ROCP, WILLR, ULTOSC, RSI))
    matrix = np.nan_to_num(matrix)
    matrix = matrix.transpose()

    return feature_df, matrix
示例#4
0
def aroonosc(client,
             symbol,
             timeframe="6m",
             highcol="high",
             lowcol="low",
             period=14):
    """This will return a dataframe of
    Aroon Oscillator
    for the given symbol across the given timeframe

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

    Returns:
        DataFrame: result
    """
    df = client.chartDF(symbol, timeframe)
    x = t.AROONOSC(df[highcol].values.astype(float),
                   df[lowcol].values.astype(float), period)
    return pd.DataFrame({
        highcol: df[highcol].values,
        lowcol: df[lowcol].values,
        "aroonosc": x
    })
示例#5
0
def calculate(data):
    timestamp = data[len(data)-1][0]
    nopen = [] 
    nhigh = []
    nlow = [] 
    nclose = []
    nvolume = []
    for entry in data:
        nopen.append(entry[1])
        nhigh.append(entry[2])
        nlow.append(entry[3])
        nclose.append(entry[4])
        nvolume.append(entry[5])
    nc = np.array(nclose)
    hc = np.array(nhigh)
    lc = np.array(nlow)
    cc = np.array(nclose)
    vc = np.array(nvolume)

    rsi = talib.RSI(nc, timeperiod=14)
    macdsignal = talib.MACD(nc, fastperiod=12, slowperiod=26, signalperiod=9)
    sar = talib.SAR(hc, lc, acceleration=0, maximum=0)
    adosc = talib.ADOSC(hc, lc, cc, vc, fastperiod=3, slowperiod=10)
    aroon = talib.AROONOSC(hc, lc, timeperiod=14)
    ult = talib.ULTOSC(hc, lc, cc, timeperiod1=7, timeperiod2=14, timeperiod3=28)
    obj, sent = twitter_api.get_sentiment()

    database.insert_predictions(timestamp, rsi[-1], macdsignal[0][-1], sar[-1], adosc[-1], aroon[-1], ult[-1], sent, obj)
    return timestamp, rsi[-1], macdsignal[0][-1], sar[-1], adosc[-1], aroon[-1], ult[-1], sent, obj
示例#6
0
 def compAROONOSC(self):
     ac = talib.AROONOSC(self.high,self.low,timeperiod=self.lookback)
     self.removeNullID(ac)
     self.rawFeatures['AROONOSC'] = ac
     
     FEATURE_SIZE_DICT['AROONOSC'] = 1
     return
示例#7
0
    def _set_df(self, df):
        for c in AssetColumns:
            if str(c) not in df.columns:
                raise RuntimeError(
                    f"{c} column doesn't exist in the dataframe")

        df['datetime'] = pd.to_datetime(df['timestamp'], unit='s')
        df['month'] = df['datetime'].dt.month
        df['weekday'] = df['datetime'].dt.weekday
        df['hour'] = df['datetime'].dt.hour
        df = df.drop(['datetime', 'timestamp', 'index'], 1)
        df['sma'] = talib.SMA(df['close'], self.window)
        df['rsi'] = talib.RSI(df['close'], self.window)
        df['mom'] = talib.MOM(df['close'], self.window)
        df['bop'] = talib.BOP(df['open'], df['high'], df['low'], df['close'])
        df['aroonosc'] = talib.AROONOSC(df['high'], df['low'], self.window)

        self.min = df.min()
        self.max = df.max()

        self.df = df

        self.row_count = len(self.df.index)
        if self.row_count < EP_LEN:
            raise RuntimeError(f"not enought rows")

        # add balance, asset_held, net_worth at each timestamp
        n_features = (len(df.columns) * self.window) + 3

        self.observation_space = spaces.Box(-np.inf,
                                            np.inf,
                                            shape=((n_features, )),
                                            dtype=np.float32)
示例#8
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
示例#9
0
文件: tech.py 项目: le0l1/ML4T
def get_features(data):
    tech_data = pd.DataFrame(index=data.index);

    for t in periods_list:
        tech_data[f'SMA_{t}'] = talib.SMA(data.close,timeperiod=t)
        tech_data[f'MOM_{t}'] = talib.MOM(data.close, timeperiod=t)
        tech_data[f'RSI_{t}'] = talib.RSI(data.close, timeperiod=t)
        tech_data[f'MA_{t}'] = talib.MA(data.close, timeperiod=t)
        tech_data[f'DX_{t}'] = talib.DX(data.high, data.low, data.close, timeperiod=t)
        tech_data[f'volume_change_{t}'] = data.volume.pct_change(periods=t)
        tech_data[f'volatility_{t}'] = data.close.pct_change(periods=t).std()
        tech_data[f'ADX_{t}'] = talib.ADX(data.high, data.low, data.close, timeperiod=t)
        tech_data[f'ADXR_{t}'] = talib.ADXR(data.high, data.low, data.close, timeperiod=t)
        tech_data[f'AROONOSC_{t}'] = talib.AROONOSC(data.high, data.low, timeperiod=t)
        tech_data[f'ROC_{t}'] = talib.ROC(data.close, timeperiod=t)
        tech_data[f'BIAS_{t}'] = (data['close'] - data['close'].rolling(t, min_periods=1).mean())/ data['close'].rolling(t, min_periods=1).mean()*100
        tech_data[f'BOLL_upper_{t}'], tech_data[f'BOLL_middle_{t}'], tech_data[f'BOLL_lower_{t}'] = talib.BBANDS(
                data.close,
                timeperiod=t,
                nbdevup=2,
                nbdevdn=2,
                matype=0)

    tech_data['SAR'] = talib.SAR(data.high, data.low)
    tech_data['AD'] = talib.AD(data.high, data.low, data.close, data.volume)
    tech_data['OBV'] = talib.OBV(data.close, data.volume)
    tech_data['target'] = data.close.pct_change().shift(-1).apply(lambda x: 1 if x > 0 else -1).fillna(0)
    tech_data['time'] = data.time
    tech_data = tech_data.set_index('time')

    reduce(lambda x, y: cross_over(x, y, tech_data), periods_list)
    
    features = list(set(tech_data.columns) - set(data.columns) - set(['target'])) 
    return tech_data.dropna(), features
示例#10
0
 def calculations(self):
     '''calculations'''
     self.df['rsi'] = ta.RSI(self.df['close'], timeperiod=5)
     self.df['apo'] = ta.APO(self.df['close'],
                             fastperiod=10,
                             slowperiod=5,
                             matype=0)
     self.df['upperband'], self.df['middleband'], self.df[
         'lowerband'] = ta.BBANDS(self.df['close'],
                                  timeperiod=5,
                                  nbdevup=2,
                                  nbdevdn=2,
                                  matype=0)
     self.df['ema'] = ta.EMA(self.df['close'], timeperiod=5)
     self.df['ma'] = ta.MA(self.df['close'], timeperiod=5, matype=0)
     self.df['sma'] = ta.MA(self.df['close'], timeperiod=5)
     self.df['t3'] = ta.T3(self.df['close'], timeperiod=5, vfactor=0)
     self.df['wma'] = ta.WMA(self.df['close'], timeperiod=5)
     self.df['aroonosc'] = ta.AROONOSC(self.df['high'],
                                       self.df['low'],
                                       timeperiod=5)
     self.df['cci'] = ta.CCI(self.df['high'],
                             self.df['low'],
                             self.df['close'],
                             timeperiod=5)
     self.df['cmo'] = ta.CMO(self.df['close'], timeperiod=14)
     self.df['macd'], self.df['macdsignal'], self.df[
         'macdhist'] = ta.MACDEXT(self.df['close'],
                                  fastperiod=12,
                                  fastmatype=0,
                                  slowperiod=26,
                                  slowmatype=0,
                                  signalperiod=9,
                                  signalmatype=0)
     self.df['slowk'], self.df['slowd'] = ta.STOCH(self.df['high'],
                                                   self.df['low'],
                                                   self.df['close'],
                                                   fastk_period=5,
                                                   slowk_period=3,
                                                   slowk_matype=0,
                                                   slowd_period=3,
                                                   slowd_matype=0)
     self.df['fastk'], self.df['fastd'] = ta.STOCHRSI(self.df['close'],
                                                      timeperiod=5,
                                                      fastk_period=5,
                                                      fastd_period=3,
                                                      fastd_matype=0)
     self.df['ultosc'] = ta.ULTOSC(self.df['high'],
                                   self.df['low'],
                                   self.df['close'],
                                   timeperiod1=7,
                                   timeperiod2=14,
                                   timeperiod3=28)
     self.df['adosc'] = ta.ADOSC(self.df['high'],
                                 self.df['low'],
                                 self.df['close'],
                                 self.df['volume'],
                                 fastperiod=3,
                                 slowperiod=10)
     return self.df
示例#11
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)
示例#12
0
 def AROONOSC_talib(self, ndays):
     """
     :param ndays:
     :return:
     """
     real = ta.AROONOSC(self.high, self.low, timeperiod=ndays)
     return real
示例#13
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)
示例#14
0
def applyAROONOSC(nsedailyquoteDF):

    arronoscdf = pd.Series(talib.AROONOSC(nsedailyquoteDF['HIGH'].values,
                                          nsedailyquoteDF['LOW'].values,
                                          timeperiod=14),
                           index=nsedailyquoteDF.TIMESTAMP,
                           name='AROONOSC')
    return arronoscdf
示例#15
0
 def test_aroon(self):
     """
     Test Aroon oscillator.
     """
     periods = 200
     q = qufilab.aroon(self.high, self.low, periods)
     t = talib.AROONOSC(self.high, self.low, periods)
     np.testing.assert_allclose(q, t, rtol=self.tolerance)
示例#16
0
def getAROONOSC(period):
    stocks = getStocks()
    for count, ticker in enumerate(stocks):
        df = data.get(ticker)
        df['AROON'] = talib.AROONOSC(df['High'].values, df['Low'].values, period)

        # You cannot concatenate a string with an int. You would need to convert your int to a string
        aroonMap[ticker + "_" + str(period)] = df['AROON']
示例#17
0
def extract_aroon(data):
    period = long_period
    data['aroon_down'], data['aroon_up'] = ta.AROON(data['high'].values,
                                                    data['low'].values,
                                                    timeperiod=period)
    data['aroon_osc'] = ta.AROONOSC(data['high'].values,
                                    data['low'].values,
                                    timeperiod=period)
    return data
示例#18
0
    def evaluate(self, kite_fetcher, instrument):
        period = int(self.period)
        df = self.get_small_data(kite_fetcher=kite_fetcher,
                                 instrument=instrument)

        result = talib.AROONOSC(high=df['high'],
                                low=df['low'].values,
                                timeperiod=period)
        return np.round(result.iloc[-1], 2)
示例#19
0
    def aroonosc(self, n, array=False):
        """
        Aroon Oscillator.
        """
        result = talib.AROONOSC(self.high, self.low, n)

        if array:
            return result
        return result[-1]
 def AROONOSC(self, timeperiod=14):
     real_data = np.array([self.df.high, self.df.low], dtype='f8')
     aroonosc = talib.AROONOSC(real_data[0], real_data[1], timeperiod=timeperiod)
     # return go.Scatter(
     #     x=self.df.index,
     #     y=aroonosc,
     #     name='AROONOSC'
     # )
     return aroonosc
示例#21
0
文件: utility.py 项目: yzbjack/vnpy
    def aroonosc(self, n: int, array: bool = False) -> Union[float, np.ndarray]:
        """
        Aroon Oscillator.
        """
        result = talib.AROONOSC(self.high, self.low, n)

        if array:
            return result
        return result[-1]
示例#22
0
def aroon(high, low, n):
    try:
        aroondown, aroonup = talib.AROON(high, low, timeperiod=n)
        df = pd.DataFrame()
        df['aroondown'] = aroondown
        df['aroonup'] = aroonup
        df['aroon_oscillator'] = talib.AROONOSC(high, low, timeperiod=n)
        return df
    except Exception as e:
        raise (e)
示例#23
0
    def aroonosc(self, sym, frequency, *args, **kwargs):
        if not self.kbars_ready(sym, frequency):
            return []

        highs = self.high(sym, frequency)
        lows = self.low(sym, frequency)

        v = ta.AROONOSC(highs, lows, *args, **kwargs)

        return v
示例#24
0
def AROONOSC(high, low, timeperiod=14):
    ''' Aroon Oscillator 阿隆振荡

    分组: Momentum Indicator 动量指标

    简介:

    real = AROONOSC(high, low, timeperiod=14)
    '''
    return talib.AROONOSC(high, low, timeperiod=14)
    def _assemble_state(self):
        '''Here we can add other things such as indicators and times'''
        self._get_last_N_timebars()
        bars = [self.last5m, self.last1h, self.last1d]
        state = []
        candles = {
            j: {k: np.array([])
                for k in ['open', 'high', 'low', 'close']}
            for j in range(len(bars))
        }
        for j, bar in enumerate(bars):
            for col in ['open', 'high', 'low', 'close']:
                candles[j][col] = np.asarray(bar[col])
                state += (list(np.asarray(bar[col]))[-10:])

        self.state = np.array([])
        self.state = np.append(self.state, state)
        self.state = np.append(self.state, self.position)
        np.append(self.state, np.sign(self.pnl_sum))
        self.state = np.append(self.state, self._time_of_day)
        self.state = np.append(self.state, self._day_of_week)

        for c in candles:
            try:
                sma1 = talib.SMA(candles[c]['close'], self.lkbk - 1)[-1]
                sma2 = talib.SMA(candles[c]['close'], self.lkbk - 8)[-1]
                self.state = np.append(self.state, (sma1 - sma2) / sma2)
                self.state = np.append(self.state, sma1)
                self.state = np.append(
                    self.state,
                    talib.RSI(candles[c]['close'], self.lkbk - 1)[-1])
                self.state = np.append(
                    self.state,
                    talib.MOM(candles[c]['close'], self.lkbk - 1)[-1])
                #self.state = np.append(self.state,talib.MACD(candles[c]['close'],fastperiod=11, slowperiod=22, signalperiod=9)[0][0])
                self.state = np.append(
                    self.state,
                    talib.BOP(candles[c]['open'], candles[c]['high'],
                              candles[c]['low'], candles[c]['close'])[-1])
                #self.state = np.append(self.state,talib.ADXR(candles[c]['high'],
                #                               candles[c]['low'],
                #                               candles[c]['close'],
                #                               self.lkbk-3)[-1])
                #self.state = np.append(self.state,talib.STOCH(candles[c]['high'],
                #                               candles[c]['low'],
                #                               candles[c]['close'],5,3,0,3,0)[-1][0])
                self.state = np.append(
                    self.state,
                    talib.AROONOSC(candles[c]['high'], candles[c]['low'],
                                   self.lkbk - 3)[-1])
            except:
                print(traceback.format_exc())
        #print('-->',self.state)
        self.state = (np.array(self.state) - np.mean(self.state)) / np.std(
            self.state)
def generate_feature(data):
    high = data.High.values
    low = data.Low.values
    close = data.Close.values

    # feature_df = pd.DataFrame(index=data.index)
    feature_df = data.copy()
    feature_df["ADX"] = ADX = talib.ADX(high, low, close, timeperiod=14)
    feature_df["ADXR"] = ADXR = talib.ADXR(high, low, close, timeperiod=14)
    feature_df["APO"] = APO = talib.APO(close,
                                        fastperiod=12,
                                        slowperiod=26,
                                        matype=0)
    feature_df["AROONOSC"] = AROONOSC = talib.AROONOSC(high,
                                                       low,
                                                       timeperiod=14)
    feature_df["CCI"] = CCI = talib.CCI(high, low, close, timeperiod=14)
    feature_df["CMO"] = CMO = talib.CMO(close, timeperiod=14)
    feature_df["DX"] = DX = talib.DX(high, low, close, timeperiod=14)
    feature_df["MINUS_DI"] = MINUS_DI = talib.MINUS_DI(high,
                                                       low,
                                                       close,
                                                       timeperiod=14)
    feature_df["MINUS_DM"] = MINUS_DM = talib.MINUS_DM(high,
                                                       low,
                                                       timeperiod=14)
    feature_df["MOM"] = MOM = talib.MOM(close, timeperiod=10)
    feature_df["PLUS_DI"] = PLUS_DI = talib.PLUS_DI(high,
                                                    low,
                                                    close,
                                                    timeperiod=14)
    feature_df["PLUS_DM"] = PLUS_DM = talib.PLUS_DM(high, low, timeperiod=14)
    feature_df["PPO"] = PPO = talib.PPO(close,
                                        fastperiod=12,
                                        slowperiod=26,
                                        matype=0)
    feature_df["ROC"] = ROC = talib.ROC(close, timeperiod=10)
    feature_df["ROCP"] = ROCP = talib.ROCP(close, timeperiod=10)
    feature_df["ROCR100"] = ROCR100 = talib.ROCR100(close, timeperiod=10)
    feature_df["RSI"] = RSI = talib.RSI(close, timeperiod=14)
    feature_df["ULTOSC"] = ULTOSC = talib.ULTOSC(high,
                                                 low,
                                                 close,
                                                 timeperiod1=7,
                                                 timeperiod2=14,
                                                 timeperiod3=28)
    feature_df["WILLR"] = WILLR = talib.WILLR(high, low, close, timeperiod=14)
    feature_df = feature_df.fillna(0.0)

    # Exclude columns you don't want
    feature_df = feature_df[feature_df.columns[
        ~feature_df.columns.isin(['Open', 'High', 'Low', 'Close'])]]
    matrix = feature_df.values

    return feature_df, matrix
示例#27
0
def add_aroon_s(dataset,param, first_header):
    field_name_up = 'aroon_s' + str(param)
    df = dataset[first_header].copy()
    high = df['High'].values
    low = df['Low'].values

    aroon = talib.AROONOSC(high, low, timeperiod=14)/100

    col = pd.DataFrame(aroon, index=df.index)
    dataset[first_header, field_name_up] = col
    return dataset
示例#28
0
def aroon_oscillator(df, n):
    """ 
    Calculates Aroon oscillator using Ta-Lib library's built-in function.
    
    :param df: pandas.DataFrame
    :return: pandas.DataFrame
    """
    AOSC = talib.AROONOSC(df['High'], df['Low'], timeperiod=n)
    AOSC_series = pd.Series(AOSC, name='AO_' + str(n))
    df = df.join(AOSC_series)
    return df
示例#29
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)
示例#30
0
    def test_aroon_osc(self):
        result = pandas_ta.aroon(self.high, self.low)

        try:
            expected = tal.AROONOSC(self.high, self.low)
            pdt.assert_series_equal(result.iloc[:, 2], expected)
        except AssertionError as ae:
            try:
                aroond_corr = pandas_ta.utils.df_error_analysis(
                    result.iloc[:, 2], expected, col=CORRELATION)
                self.assertGreater(aroond_corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                error_analysis(result.iloc[:, 0], CORRELATION, ex)