Exemple #1
0
def technical_indicators_df(daily_data):
    """
    Assemble a dataframe of technical indicator series for a single stock
    """
    o = daily_data['Open'].values
    c = daily_data['Close'].values
    h = daily_data['High'].values
    l = daily_data['Low'].values
    v = daily_data['Vol'].astype(float).values
    # define the technical analysis matrix

    # Most data series are normalized by their series' mean
    ta = pd.DataFrame()
    ta['MA5'] = tb.SMA(c,timeperiod=5)
    
    ta['BBANDS_U'],ta['BBANDS_M'],ta['BBANDS_L']= tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
    # ta['BBANDS_M'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1] / \
    #                     tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1].mean()
    # ta['BBANDS_L'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2] / \
    #                     tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2].mean()
    ta['AD'] = tb.AD(h, l, c, v) / tb.AD(h, l, c, v).mean()
    ta['ATR'] = tb.ATR(h, l, c, timeperiod=14) / tb.ATR(h, l, c, timeperiod=14).mean()
    ta['HT_DC'] = tb.HT_DCPERIOD(c) / tb.HT_DCPERIOD(c).mean()
    ta["High/Open"] = h / o
    ta["Low/Open"] = l / o
    ta["Close/Open"] = c / o
    return ta
Exemple #2
0
def add_volume_indicators(data_list):
    # (volume) Indicators common for all Time-frames
    for data in data_list:

        # 1) AD - Chaikin A / D Line
        real = talib.AD(data.High, data.Low, data.Close, data.Volume)
        data['AD'] = real

        # 2) ADOSC - Chaikin A/D Oscillator
        real = talib.ADOSC(data.High,
                           data.Low,
                           data.Close,
                           data.Volume,
                           fastperiod=3,
                           slowperiod=10)
        data['ADOSC'] = real

        # 3) OBV - On Balance Volume
        real = talib.OBV(data.Close, data.Volume)
        data['OBV'] = real

    data_weekly = data_list[6]
    data_monthly = data_list[7]
    data_15min = data_list[2]
    data_daily = data_list[5]
    data_60min = data_list[4]
    data_1min = data_list[0]
    data_5min = data_list[1]
    data_30min = data_list[3]

    # Create (volume) indicators for a only to a particular timeframe here..

    return data_list
Exemple #3
0
 def __call__(self, data, **args):
     c, h, l, v = data
     c = data[c]
     h = data[h]
     l = data[l]
     v = data[v]
     return tb.AD(h, l, c, v)
def handle_volume_indicators(args, axes, i, klines_df, close_times,
                             display_count):
    # talib
    if args.AD:  # AD
        name = 'AD'
        real = talib.AD(klines_df["high"], klines_df["low"],
                        klines_df["close"], klines_df["volume"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)

    if args.ADOSC:  # ADOSC
        name = 'ADOSC'
        real = talib.ADOSC(klines_df["high"],
                           klines_df["low"],
                           klines_df["close"],
                           klines_df["volume"],
                           fastperiod=3,
                           slowperiod=10)
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)

    if args.OBV:  # OBV
        name = 'OBV'
        real = talib.OBV(klines_df["close"], klines_df["volume"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)
def Feature_Extraction_Volume(df):
    df['A/D'] = tas.AD(df['high'], df['low'], df['close'], df['volume'])
    df = Williams_AD(df)
    df['OBV'] = tas.OBV(df['close'], df['volume'])
    df['ADOSC'] = tas.ADOSC(df['high'], df['low'], df['close'], df['volume'])
    df = df.fillna(0)
    return df
    def technical_indicators_df(self):
        o = self.daily_data['Open'].values
        c = self.daily_data['Close'].values
        h = self.daily_data['High'].values
        l = self.daily_data['Low'].values
        v = self.daily_data['Volume'].astype(float).values
        # define the technical analysis matrix

        ta = pd.DataFrame()
        ta['MA5'] = tb.MA(c, timeperiod=5)
        ta['MA10'] = tb.MA(c, timeperiod=10)
        ta['MA20'] = tb.MA(c, timeperiod=20)
        ta['MA60'] = tb.MA(c, timeperiod=60)
        ta['MA120'] = tb.MA(c, timeperiod=120)
        ta['MA5'] = tb.MA(v, timeperiod=5)
        ta['MA10'] = tb.MA(v, timeperiod=10)
        ta['MA20'] = tb.MA(v, timeperiod=20)
        ta['ADX'] = tb.ADX(h, l, c, timeperiod=14)
        ta['ADXR'] = tb.ADXR(h, l, c, timeperiod=14)
        ta['MACD'] = tb.MACD(c, fastperiod=12, slowperiod=26, signalperiod=9)[0]
        ta['RSI'] = tb.RSI(c, timeperiod=14)
        ta['BBANDS_U'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[0]
        ta['BBANDS_M'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1]
        ta['BBANDS_L'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2]
        ta['AD'] = tb.AD(h, l, c, v)
        ta['ATR'] = tb.ATR(h, l, c, timeperiod=14)
        ta['HT_DC'] = tb.HT_DCPERIOD(c)

        self.ta = ta
Exemple #7
0
def ad(
    client,
    symbol,
    timeframe="6m",
    highcol="high",
    lowcol="low",
    closecol="close",
    volumecol="volume",
):
    """This will return a dataframe of Chaikin A/D Line 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
        closecol (string): column to use to calculate
        volumecol (string): column to use to calculate

    Returns:
        DataFrame: result
    """
    df = client.chartDF(symbol, timeframe)
    ad = t.AD(df[highcol].values, df[lowcol].values, df[closecol].values,
              df[volumecol].values)
    return pd.DataFrame({
        highcol: df[highcol].values,
        lowcol: df[lowcol].values,
        closecol: df[closecol].values,
        volumecol: df[volumecol].values,
        "a/d": ad,
    })
Exemple #8
0
 def _10adema(data):
     ad = talib.AD(data.highest_price.values,
                   data.lowest_price.values,
                   data.close_price,
                   data.turnover_vol)
     result = talib.EMA(np.nan_to_num(ad), 10)
     return result[-1]
Exemple #9
0
def devfea(df, high, low, close, open, volume):
    df['AD'] = talib.AD(high, low, close, volume)
    df['CCI'] = talib.CCI(high, low, close)
    df['macd'], df['macdsignal'], df['macdhist'] = talib.MACD(close,
                                                              fastperiod=12,
                                                              slowperiod=26,
                                                              signalperiod=9)
    df['ATR'] = talib.ATR(high, low, close, timeperiod=14)
    df['ADOSC'] = talib.ADOSC(high, low, close, volume)
    df['ADX'] = talib.ADX(high, low, close)
    df['BBANDS_upper'], df['BBANDS_mid'], df['BBANDS_lower'] = talib.BBANDS(
        close)
    df['RSI'] = talib.RSI(close)
    df['MA5'] = talib.MA(close, 5)
    df['MA10'] = talib.MA(close, 10)
    df['MA20'] = talib.MA(close, 20)
    df['OBV'] = talib.OBV(close, volume)
    df['SAR'] = talib.SAR(high, low)
    df['lgvol'] = np.log(volume)
    #上影线
    df['upshadow'] = np.abs(high - ((open + close) +
                                    (np.abs(open - close))) / 2)
    #下影线
    df['downshadow'] = np.abs(low - ((open + close) -
                                     (np.abs(open - close))) / 2)
    return df
Exemple #10
0
    def __ta_array_ad(cls, high, low, close, volume):
        high_array = np.array(high)
        low_array = np.array(low)
        close_array = np.array(close)
        volume_array = np.array(volume)

        return talib.AD(high_array, low_array, close_array, volume_array)
def genTA(data, y, t): #t is timeperiod
    indicators  = {}
    y_ind = copy.deepcopy(y)
   
    for ticker in data:
    ## Overlap
        indicators[ticker] = ta.SMA(data[ticker].iloc[:,3], timeperiod=t).to_frame()        
        indicators[ticker]['EMA'] = ta.EMA(data[ticker].iloc[:,3], timeperiod=t)       
        indicators[ticker]['BBAND_Upper'], indicators[ticker]['BBAND_Middle' ], indicators[ticker]['BBAND_Lower' ] = ta.BBANDS(data[ticker].iloc[:,3], timeperiod=t, nbdevup=2, nbdevdn=2, matype=0)         
        indicators[ticker]['HT_TRENDLINE'] = ta.HT_TRENDLINE(data[ticker].iloc[:,3])
        indicators[ticker]['SAR'] = ta.SAR(data[ticker].iloc[:,1], data[ticker].iloc[:,2], acceleration=0, maximum=0)
        #rename SMA column
        indicators[ticker].rename(columns={indicators[ticker].columns[0]: "SMA"}, inplace=True)
    ## Momentum
        indicators[ticker]['RSI'] = ta.RSI(data[ticker].iloc[:,3], timeperiod=(t-1))
        indicators[ticker]['MOM'] = ta.MOM(data[ticker].iloc[:,3], timeperiod=(t-1))
        indicators[ticker]['ROC'] = ta.ROC(data[ticker].iloc[:,3], timeperiod=(t-1))
        indicators[ticker]['ROCP']= ta.ROCP(data[ticker].iloc[:,3],timeperiod=(t-1))
        indicators[ticker]['STOCH_SLOWK'], indicators[ticker]['STOCH_SLOWD'] = ta.STOCH(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], fastk_period=t, slowk_period=int(.6*t), slowk_matype=0, slowd_period=int(.6*t), slowd_matype=0)
        indicators[ticker]['MACD'], indicators[ticker]['MACDSIGNAL'], indicators[ticker]['MACDHIST'] = ta.MACD(data[ticker].iloc[:,3], fastperiod=t,slowperiod=2*t,signalperiod=int(.7*t))
        
    ## Volume
        indicators[ticker]['OBV'] = ta.OBV(data[ticker].iloc[:,3], data[ticker].iloc[:,4])
        indicators[ticker]['AD'] = ta.AD(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], data[ticker].iloc[:,4])
        indicators[ticker]['ADOSC'] = ta.ADOSC(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], data[ticker].iloc[:,4], fastperiod=int(.3*t), slowperiod=t)
        
    ## Cycle
        indicators[ticker]['HT_DCPERIOD'] = ta.HT_DCPERIOD(data[ticker].iloc[:,3])
        indicators[ticker]['HT_TRENDMODE']= ta.HT_TRENDMODE(data[ticker].iloc[:,3])
    
    ## Price
        indicators[ticker]['AVGPRICE'] = ta.AVGPRICE(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['TYPPRICE'] = ta.TYPPRICE(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
    
    ## Volatility
        indicators[ticker]['ATR'] = ta.ATR(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3],  timeperiod=(t-1))
    
    ## Statistics
        indicators[ticker]['BETA'] = ta.BETA(data[ticker].iloc[:,1], data[ticker].iloc[:,2], timeperiod=(t-1))
        indicators[ticker]['LINEARREG'] = ta.LINEARREG(data[ticker].iloc[:,3], timeperiod=t)
        indicators[ticker]['VAR'] = ta.VAR(data[ticker].iloc[:,3], timeperiod=t, nbdev=1)
    
    ## Math Transform
        indicators[ticker]['EXP'] = ta.EXP(data[ticker].iloc[:,3])
        indicators[ticker]['LN'] = ta.LN(data[ticker].iloc[:,3])
    
    ## Patterns (returns integers - but norming might not really do anything but wondering if they should be normed)
        indicators[ticker]['CDLENGULFING'] = ta.CDLENGULFING(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['CDLDOJI']      = ta.CDLDOJI(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['CDLHAMMER']    = ta.CDLHAMMER(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        indicators[ticker]['CDLHANGINGMAN']= ta.CDLHANGINGMAN(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3])
        
    #drop 'nan' values
        indicators[ticker].drop(indicators[ticker].index[np.arange(0,63)], inplace=True)
        y_ind[ticker].drop(y_ind[ticker].index[np.arange(0,63)], inplace=True)
        
    #Normalize Features
    indicators_norm = normData(indicators)
        
    return indicators_norm, indicators, y_ind
Exemple #12
0
 def test_acdi(self):
     """
     Test (Chaikin) Accumulation/Distribution line (ACDI).
     """
     q = qufilab.acdi(self.close, self.high, self.low, self.volume)
     t = talib.AD(self.high, self.low, self.close, self.volume)
     np.testing.assert_allclose(q, t, rtol=self.tolerance)
Exemple #13
0
    def ad(self, highs, lows, closes, volumes_currency):
        """
		AD = Chaikin A/D Line (Volume Indicators)
		:param highs:
		:param lows:
		:param closes:
		:param volumes_currency:
		:return:
		"""
        # nejdříve vyřízneme potřebnou délku
        # a převedeme na desetinné číslo.
        high = float(highs[-1])
        low = float(lows[-1])
        close = float(closes[-1])
        volumes_currency = float(volumes_currency[-1])
        # převedeme na datová pole
        high = numpy.asarray((high, ))
        low = numpy.asarray((low, ))
        close = numpy.asarray((close, ))
        volumes_currency = numpy.asarray((volumes_currency, ))
        # Výsledek.
        result = talib.AD(high, low, close, volumes_currency)
        # Z datového pole vyřízneme poslední výsledek
        # a navracíme jako desetinné číslo.
        cutedresult = float(result[-1])
        # Vrátí desetinné číslo.
        return cutedresult
Exemple #14
0
 def compAD(self):
     ad = talib.AD(self.high,self.low,self.close,self.tickVol)
     self.removeNullID(ad)
     self.rawFeatures['AD'] = ad 
     
     FEATURE_SIZE_DICT['AD'] = 1
     return
Exemple #15
0
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
Exemple #16
0
def get_ad(ohlc):
    ad = ta.AD(ohlc['2_high'], ohlc['3_low'], ohlc['4_close'],
               ohlc['5_volume'])

    ohlc['ad'] = ad

    return ohlc
Exemple #17
0
 def Indicators(self,df): # date close open high low volume 컬럼순 
                     # 결측치 33줄 생김 0~32 까지
     df['sma5'] = talib.SMA(np.asarray(df['close']), 5)
     df['sma20'] = talib.SMA(np.asarray(df['close']), 20)
     #df['sma120'] = talib.SMA(np.asarray(df['close']), 120)
     df['ema12'] = talib.SMA(np.asarray(df['close']), 12)
     df['ema26'] = talib.SMA(np.asarray(df['close']), 26)
     upper, middle, lower = talib.BBANDS(np.asarray(df['close']), timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)
     df['dn'] = lower
     df['mavg'] = middle
     df['up'] = upper
     df['pctB'] = (df.close - df.dn)/(df.up - df.dn)
     rsi14 = talib.RSI(np.asarray(df['close']), 14)
     df['rsi14'] = rsi14
     macd, macdsignal, macdhist = talib.MACD(np.asarray(df['close']), 12, 26, 9)  
     df['macd'] = macd
     df['macdsignal'] = macdsignal
     df['obv']=talib.OBV(df['close'], df['volume'])
     df['ad'] = talib.AD(df['high'], df['low'], df['close'], df['volume'])
     df['ADOSC'] = talib.ADOSC(df['high'], df['low'], df['close'], df['volume'], fastperiod=3, slowperiod=10)
     df=df.iloc[33:]
     df=df.fillna(0)
     df=df.drop(columns=['date'])
     
     self.add_columns_data = df
Exemple #18
0
 def ad(self, n: int, array: bool = False) -> Union[float, np.ndarray]:
     """
     AD.
     """
     result = talib.AD(self.high, self.low, self.close, self.volume, n)
     if array:
         return result
     return result[-1]
Exemple #19
0
 def ad(self, n, array=False):
     """
     AD.
     """
     result = talib.AD(self.high, self.low, self.close, self.volume, n)
     if array:
         return result
     return result[-1]
Exemple #20
0
def Chaikin(df, save=False):
    chaikin = talib.AD(df["High"].values, df["Low"].values, df["Close"].values,
                       df["Volume"].values.astype(float))
    cha_series = pd.Series(chaikin, name="Chaikin", index=df.index)
    if save:
        save_series(cha_series, "Chaikin")
    df = df.join(cha_series)
    return df
Exemple #21
0
 def calculate(self, tagged):
     data = pd.DataFrame()
     #data['Date'] = df['Date']
     data['values'] = talib.AD(df['High'], df['Low'], df['Close'],
                               df['Volume'])
     df[self.name()] = data['values']
     if tagged:
         data['tag'] = df['tag']
     return data
Exemple #22
0
    def technical_indicators_df(self, daily_data):
        """
        Assemble a dataframe of technical indicator series for a single stock
        """
        o = daily_data['Open'].values
        c = daily_data['Close'].values
        h = daily_data['High'].values
        l = daily_data['Low'].values
        v = daily_data['Volume'].astype(float).values
        # define the technical analysis matrix

        # Most data series are normalized by their series' mean
        ta = pd.DataFrame()
        ta['MA5'] = tb.MA(c, timeperiod=5) / tb.MA(c, timeperiod=5).mean()
        ta['MA10'] = tb.MA(c, timeperiod=10) / tb.MA(c, timeperiod=10).mean()
        ta['MA20'] = tb.MA(c, timeperiod=20) / tb.MA(c, timeperiod=20).mean()
        ta['MA60'] = tb.MA(c, timeperiod=60) / tb.MA(c, timeperiod=60).mean()
        ta['MA120'] = tb.MA(c, timeperiod=120) / tb.MA(c,
                                                       timeperiod=120).mean()
        ta['MA5'] = tb.MA(v, timeperiod=5) / tb.MA(v, timeperiod=5).mean()
        ta['MA10'] = tb.MA(v, timeperiod=10) / tb.MA(v, timeperiod=10).mean()
        ta['MA20'] = tb.MA(v, timeperiod=20) / tb.MA(v, timeperiod=20).mean()
        ta['ADX'] = tb.ADX(h, l, c, timeperiod=14) / tb.ADX(
            h, l, c, timeperiod=14).mean()
        ta['ADXR'] = tb.ADXR(h, l, c, timeperiod=14) / tb.ADXR(
            h, l, c, timeperiod=14).mean()
        ta['MACD'] = tb.MACD(c, fastperiod=12, slowperiod=26, signalperiod=9)[0] / \
                     tb.MACD(c, fastperiod=12, slowperiod=26, signalperiod=9)[0].mean()
        ta['RSI'] = tb.RSI(c, timeperiod=14) / tb.RSI(c, timeperiod=14).mean()
        ta['BBANDS_U'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[0] / \
                         tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[0].mean()
        ta['BBANDS_M'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1] / \
                         tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1].mean()
        ta['BBANDS_L'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2] / \
                         tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2].mean()
        ta['AD'] = tb.AD(h, l, c, v) / tb.AD(h, l, c, v).mean()
        ta['ATR'] = tb.ATR(h, l, c, timeperiod=14) / tb.ATR(
            h, l, c, timeperiod=14).mean()
        ta['HT_DC'] = tb.HT_DCPERIOD(c) / tb.HT_DCPERIOD(c).mean()
        ta["High/Open"] = h / o
        ta["Low/Open"] = l / o
        ta["Close/Open"] = c / o

        self.ta = ta
Exemple #23
0
def getVolumeIndicators(df):
    high = df['High']
    low = df['Low']
    close = df['Close']
    open = df['Open']
    volume = df['Volume']

    df['AD'] = ta.AD(high, low, close, volume)
    df['ADOSC'] = ta.ADOSC(high, low, close, volume, fastperiod=3, slowperiod=10)
    df['OBV']= ta.OBV(close, volume)
Exemple #24
0
def add_indicators(data):
    df = data.copy(deep=True)
    for indicator in lookup:
        try:
            result = getattr(talib, indicator)(df.Close)
            if isinstance(result, tuple):
                for i, val in enumerate(result):
                    df[f'{indicator}_{i}'] = val
            else:
                df[f'{indicator}'] = val
        except (KeyboardInterrupt, SystemError):
            raise
        except:
            try:
                result = getattr(talib, indicator)(df.High, df.Low)
                if isinstance(result, tuple):
                    for i, val in enumerate(result):
                        df[f'{indicator}_{i}'] = val
                else:
                    df[f'{indicator}'] = val
            except (KeyboardInterrupt, SystemError):
                raise
            except:
                try:
                    result = getattr(talib, indicator)(df.High, df.Low,
                                                       df.Close)
                    if isinstance(result, tuple):
                        for i, val in enumerate(result):
                            df[f'{indicator}_{i}'] = val
                    else:
                        df[f'{indicator}'] = val
                except (KeyboardInterrupt, SystemError):
                    raise
                except:
                    try:
                        result = getattr(talib, indicator)(df.Open, df.High,
                                                           df.Low, df.Close)
                        if isinstance(result, tuple):
                            for i, val in enumerate(result):
                                df[f'{indicator}_{i}'] = val
                        else:
                            df[f'{indicator}'] = val
                    except (KeyboardInterrupt, SystemError):
                        raise
                    except:
                        print(f'issue with {indicator}')

    df.OBV = talib.OBV(df.Close, df.Volume)
    df.AD = talib.AD(df.High, df.Low, df.Close, df.Volume)
    df.ADOSC = talib.ADOSC(df.High, df.Low, df.Close, df.Volume)
    df['HT_DCPERIOD'] = talib.HT_DCPERIOD(df.Close)
    df['HT_DCPHASE'] = talib.HT_DCPHASE(df.Close)

    return df
Exemple #25
0
def ad(high, low, close, volume):
    """
    AD(多空双方力量浮标)
    :param high: 最高价
    :param low: 最低价
    :param close: 收盘价
    :param volume: 成交量
    :return: AD值
    """
    adval = talib.AD(high, low, close, volume)
    return adval
Exemple #26
0
 def eval(self, environment, gene, date1, date2):
     date1_ = environment.shift_date(date1, -(self.window-1), -1)
     high = gene.next_value(environment, date1_, date2)
     low = gene.next_value(environment, date1_, date2)
     close = gene.next_value(environment, date1_, date2)
     volume = gene.next_value(environment, date1_, date2)
     res = pd.DataFrame(np.nan, index=high.ix[date1:date2].index, columns=high.columns)
     for i, j in product(range(res.shape[0]), range(res.shape[1])):
         res.iloc[i, j] = talib.AD(
                 high.values[i: i+self.window, j], low.values[i: i+self.window, j], close.values[i: i+self.window, j], volume.values[i: i+self.window, j])[-1]
     return res
Exemple #27
0
def ta_AD(AD_conf, curr_high_price_seq, curr_low_price_seq,
          curr_close_price_seq, curr_trade_price_seq):

    curr_feature_list = []

    AD_seqs = talib.AD(curr_high_price_seq, curr_low_price_seq,
                       curr_close_price_seq, curr_trade_price_seq)

    curr_feature_list.append("AD")

    return AD_seqs, curr_feature_list
Exemple #28
0
 def get_volume_studies(open, low, high, close, volume, df):
     # Volume Indicator Functions
     # @TODO: Fix type case error of volume column
     # https://mrjbq7.github.io/ta-lib/func_groups/volume_indicators.html
     df["AD"] = talib.AD(high, low, close, volume)
     df["ADOSC"] = talib.ADOSC(high,
                               low,
                               close,
                               volume,
                               fastperiod=3,
                               slowperiod=10)
     df["OBV"] = talib.OBV(close, volume)
    def ad(self, sym, frequency):
        if not self.kbars_ready(sym, frequency):
            return []

        highs = self.high(sym, frequency)
        lows = self.low(sym, frequency)
        closes = self.close(sym, frequency)
        volumes = self.volume(sym, frequency)

        v = ta.AD(highs, lows, closes, volumes)

        return v
Exemple #30
0
    def chaikin_ad_line(self):
        """
        名称:Chaikin A/D Line 累积/派发线(Accumulation/Distribution Line)
        简介:Marc Chaikin提出的一种平衡交易量指标,以当日的收盘价位来估算成交流量,用于估定一段时间内该证券累积的资金流量。
        研判:1、A/D测量资金流向,向上的A/D表明买方占优势,而向下的A/D表明卖方占优势
            2、A/D与价格的背离可视为买卖信号,即底背离考虑买入,顶背离考虑卖出
            3、应当注意A/D忽略了缺口的影响,事实上,跳空缺口的意义是不能轻易忽略的
        """
        result = talib.AD(high=np.array(self.dataframe['high']),
                          low=np.array(self.dataframe['low']),
                          close=np.array(self.dataframe['close']),
                          volume=np.array(self.dataframe['volume']))
        self.dataframe['chaikin_ad'] = result