|
import pandas as pd
|
|
import numpy as np
|
|
|
|
df = pd.read_csv('candles.csv')
|
|
|
|
|
|
from talib import RSI, BBANDS, MACD, ATR, EMA, SMA
|
|
|
|
|
|
|
|
grouped = df.groupby('market')
|
|
|
|
|
|
for market, group in grouped:
|
|
|
|
print('Calculating indicators for', market)
|
|
df.loc[group.index,'rsi'] = RSI(group['close'], timeperiod=14)
|
|
|
|
upper, middle, lower = BBANDS(group['close'], timeperiod=20)
|
|
df.loc[group.index,'bb_upper'] = upper
|
|
df.loc[group.index,'bb_middle'] = middle
|
|
df.loc[group.index,'bb_lower'] = lower
|
|
|
|
macd, macdsignal, macdhist = MACD(group['close'], fastperiod=12, slowperiod=26, signalperiod=9)
|
|
df.loc[group.index,'macd'] = macd
|
|
df.loc[group.index,'macdsignal'] = macdsignal
|
|
df.loc[group.index,'macdhist'] = macdhist
|
|
|
|
df.loc[group.index,'atr'] = ATR(group['high'], group['low'], group['close'], timeperiod=14)
|
|
|
|
df.loc[group.index,'ema'] = EMA(group['close'], timeperiod=30)
|
|
df.loc[group.index,'sma'] = SMA(group['close'], timeperiod=30)
|
|
|
|
|
|
df = df.dropna()
|
|
|
|
|
|
|
|
print(df.tail())
|
|
df.to_csv('indicators.csv', index=False) |