Created
October 1, 2019 11:41
-
-
Save yuyasugano/f68a906fcbc96b868927d2335b5a4541 to your computer and use it in GitHub Desktop.
Technical index for features with Ta-Lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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