Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. open = pd.Series(df['open'])
  2. high = pd.Series(df['high'])
  3. low = pd.Series(df['low'])
  4. close = pd.Series(df['close'])
  5. volume = pd.Series(df['volume'])
  6.  
  7. # pct_change for new column
  8. X['diff'] = y
  9.  
  10. # Exponential Moving Average
  11. ema = talib.EMA(close, timeperiod=3)
  12. ema = ema.fillna(ema.mean())
  13.  
  14. # Momentum
  15. momentam = talib.MOM(close, timeperiod=5)
  16. momentam = momentam.fillna(momentam.mean())
  17.  
  18. # RSI
  19. rsi = talib.RSI(close, timeperiod=14)
  20. rsi = rsi.fillna(rsi.mean())
  21.  
  22. # ADX
  23. adx = talib.ADX(high, low, close, timeperiod=14)
  24. adx = adx.fillna(adx.mean())
  25.  
  26. # ADX change
  27. adx_change = adx.pct_change(1).shift(-1)
  28. adx_change = adx_change.fillna(adx_change.mean())
  29.  
  30. # AD
  31. ad = talib.AD(high, low, close, volume)
  32. ad = ad.fillna(ad.mean())
  33.  
  34. X_ = pd.concat([X, ema, momentam, rsi, adx_change, ad], axis=1).drop(['open', 'high', 'low', 'close'], axis=1)
  35. X_.columns = ['volume','diff', 'ema', 'momentam', 'rsi', 'adx', 'ad']
  36. X_.join(y_).head(200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement