Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuyasugano/f68a906fcbc96b868927d2335b5a4541 to your computer and use it in GitHub Desktop.
Save yuyasugano/f68a906fcbc96b868927d2335b5a4541 to your computer and use it in GitHub Desktop.
Technical index for features with Ta-Lib
open = pd.Series(df['open'])
high = pd.Series(df['high'])
low = pd.Series(df['low'])
close = pd.Series(df['close'])
volume = pd.Series(df['volume'])
# pct_change for new column
X['diff'] = y
# Exponential Moving Average
ema = talib.EMA(close, timeperiod=3)
ema = ema.fillna(ema.mean())
# Momentum
momentam = talib.MOM(close, timeperiod=5)
momentam = momentam.fillna(momentam.mean())
# RSI
rsi = talib.RSI(close, timeperiod=14)
rsi = rsi.fillna(rsi.mean())
# ADX
adx = talib.ADX(high, low, close, timeperiod=14)
adx = adx.fillna(adx.mean())
# ADX change
adx_change = adx.pct_change(1).shift(-1)
adx_change = adx_change.fillna(adx_change.mean())
# AD
ad = talib.AD(high, low, close, volume)
ad = ad.fillna(ad.mean())
X_ = pd.concat([X, ema, momentam, rsi, adx_change, ad], axis=1).drop(['open', 'high', 'low', 'close'], axis=1)
X_.columns = ['volume','diff', 'ema', 'momentam', 'rsi', 'adx', 'ad']
X_.join(y_).head(200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment