import pandas as pd import numpy as np def STOK(close, low, high, n): STOK = ((close - low.rolling(n).min()) / (high.rolling(n).max() - low.rolling(n).min())) * 100 return STOK def STOD(close, low, high, n): STOK = ((close - low.rolling(n).min()) / (high.rolling(n).max() - low.rolling(n).min())) * 100 STOD = STOK.rolling(3).mean() return STOD def RSI(series, period): delta = series.diff().dropna() u=delta*0 d = u.copy() u[delta > 0] = delta[delta > 0] d[delta < 0] = -delta[delta < 0] u[u.index[period-1]] = np.mean( u[:period] ) #first value is sum of avg gains u = u.drop(u.index[:(period-1)]) d[d.index[period-1]] = np.mean( d[:period] ) #first value is sum of avg losses d = d.drop(d.index[:(period-1)]) rs = u.ewm(com=period-1, adjust=False).mean() / \ d.ewm(com=period-1, adjust=False).mean() return 100-100/(1+rs) def ROC(df, n): M = df.diff(n - 1) N = df.shift(n - 1) ROC = pd.Series(((M / N) * 100), name = 'ROC_' + str(n)) return ROC