def RSI(df, n): """相对强弱指标""" lc = df["close"].shift(1) rsi = ta_func.sma(pd.Series(np.where(df["close"] - lc > 0, df["close"] - lc, 0)), n, 1) / \ ta_func.sma(np.absolute(df["close"] - lc), n, 1) * 100 new_df = pd.DataFrame(data=rsi, columns=["rsi"]) return new_df
def RCCD(df, n, n1, n2): """异同离差变化率指数""" new_df = pd.DataFrame() rc = df["close"] / df["close"].shift(n) arc = ta_func.sma(rc.shift(1), n, 1) new_df["dif"] = ta_func.ma(arc.shift(1), n1) - ta_func.ma(arc.shift(1), n2) new_df["rccd"] = ta_func.sma(new_df["dif"], n, 1) return new_df
def MICD(df, n, n1, n2): """异同离差动力指数""" new_df = pd.DataFrame() mi = df["close"] - df["close"].shift(1) ami = ta_func.sma(mi, n, 1) new_df["dif"] = ta_func.ma(ami.shift(1), n1) - ta_func.ma(ami.shift(1), n2) new_df["micd"] = ta_func.sma(new_df["dif"], 10, 1) return new_df
def SLOWKD(df, n, m1, m2, m3): """慢速KD""" new_df = pd.DataFrame() rsv = (df["close"] - df["low"].rolling(n).min()) / \ (df["high"].rolling(n).max() - df["low"].rolling(n).min()) * 100 fastk = ta_func.sma(rsv, m1, 1) new_df["k"] = ta_func.sma(fastk, m2, 1) new_df["d"] = ta_func.sma(new_df["k"], m3, 1) return new_df
def VRSI(df, n): """量相对强弱""" vrsi = ta_func.sma( pd.Series( np.where(df["volume"] - df["volume"].shift(1) > 0, df["volume"] - df["volume"].shift(1), 0)), n, 1) / ta_func.sma(np.absolute(df["volume"] - df["volume"].shift(1)), n, 1) * 100 new_df = pd.DataFrame(data=list(vrsi), columns=["vrsi"]) return new_df
def KD(df, n, m1, m2): """随机指标""" new_df = pd.DataFrame() hv = df["high"].rolling(n).max() lv = df["low"].rolling(n).min() rsv = pd.Series(np.where(hv == lv, 0, (df["close"] - lv) / (hv - lv) * 100)) new_df["k"] = ta_func.sma(rsv, m1, 1) new_df["d"] = ta_func.sma(new_df["k"], m2, 1) return new_df
def WAD(df, n, m): """威廉多空力度线""" new_df = pd.DataFrame() new_df["a"] = np.absolute( np.where( df["close"] > df["close"].shift(1), df["close"] - np.where(df["close"].shift(1) < df["low"], df["close"].shift(1), df["low"]), np.where( df["close"] < df["close"].shift(1), df["close"] - np.where(df["close"].shift(1) > df["high"], df["close"].shift(1), df["high"]), 0)).cumsum()) new_df["b"] = ta_func.sma(new_df["a"], n, 1) new_df["e"] = ta_func.sma(new_df["a"], m, 1) return new_df
def LWR(df, n, m): """威廉指标""" hv = df["high"].rolling(n).max() lv = df["low"].rolling(n).min() rsv = pd.Series(np.where(hv == lv, 0, (df["close"] - hv) / (hv - lv) * 100)) new_df = pd.DataFrame(data=list(ta_func.sma(rsv, m, 1)), columns=["lwr"]) return new_df
def DBCD(df, n, m, t): """异同离差乖离率""" new_df = pd.DataFrame() bias = (df["close"] - ta_func.ma(df["close"], n)) / ta_func.ma( df["close"], n) dif = bias - bias.shift(m) new_df["dbcd"] = ta_func.sma(dif, t, 1) new_df["mm"] = ta_func.ma(new_df["dbcd"], 5) return new_df
def SRMI(df, n): """MI修正指标""" new_df = pd.DataFrame() new_df["a"] = np.where( df["close"] < df["close"].shift(n), (df["close"] - df["close"].shift(n)) / df["close"].shift(n), np.where(df["close"] == df["close"].shift(n), 0, (df["close"] - df["close"].shift(n)) / df["close"])) new_df["mi"] = ta_func.sma(new_df["a"], n, 1) return new_df
def DDI(df, n, n1, m, m1): """方向标准离差指数""" new_df = pd.DataFrame() tr = np.where( np.absolute(df["high"] - df["high"].shift(1)) > np.absolute(df["low"] - df["low"].shift(1)), np.absolute(df["high"] - df["high"].shift(1)), np.absolute(df["low"] - df["low"].shift(1))) dmz = np.where((df["high"] + df["low"]) <= (df["high"].shift(1) + df["low"].shift(1)), 0, tr) dmf = np.where((df["high"] + df["low"]) >= (df["high"].shift(1) + df["low"].shift(1)), 0, tr) diz = pd.Series(dmz).rolling(n).sum() / (pd.Series(dmz).rolling(n).sum() + pd.Series(dmf).rolling(n).sum()) dif = pd.Series(dmf).rolling(n).sum() / (pd.Series(dmf).rolling(n).sum() + pd.Series(dmz).rolling(n).sum()) new_df["ddi"] = diz - dif new_df["addi"] = ta_func.sma(new_df["ddi"], n1, m) new_df["ad"] = ta_func.ma(new_df["addi"], m1) return new_df
def SRDM(df, n): """动向速度比率""" new_df = pd.DataFrame() dmz = np.where((df["high"] + df["low"]) <= (df["high"].shift(1) + df["low"].shift(1)), 0, np.where( np.absolute(df["high"] - df["high"].shift(1)) > np.absolute(df["low"] - df["low"].shift(1)), np.absolute(df["high"] - df["high"].shift(1)), np.absolute(df["low"] - df["low"].shift(1)))) dmf = np.where((df["high"] + df["low"]) >= (df["high"].shift(1) + df["low"].shift(1)), 0, np.where( np.absolute(df["high"] - df["high"].shift(1)) > np.absolute(df["low"] - df["low"].shift(1)), np.absolute(df["high"] - df["high"].shift(1)), np.absolute(df["low"] - df["low"].shift(1)))) admz = ta_func.ma(pd.Series(dmz), 10) admf = ta_func.ma(pd.Series(dmf), 10) new_df["srdm"] = np.where(admz > admf, (admz - admf) / admz, np.where(admz == admf, 0, (admz - admf) / admf)) new_df["asrdm"] = ta_func.sma(new_df["srdm"], n, 1) return new_df
def SMA(df, n, m): """扩展指数加权移动平均""" new_df = pd.DataFrame(data=list(ta_func.sma(df["close"], n, m)), columns=["sma"]) return new_df
def MV(df, n, m): """均量线""" new_df = pd.DataFrame() new_df["mv1"] = ta_func.sma(df["volume"], n, 1) new_df["mv2"] = ta_func.sma(df["volume"], m, 1) return new_df
def RC(df, n): """变化率指数""" rc = df["close"] / df["close"].shift(n) new_df = pd.DataFrame(data=list(ta_func.sma(rc.shift(1), n, 1)), columns=["arc"]) return new_df
def MI(df, n): """动量指标""" new_df = pd.DataFrame() new_df["a"] = df["close"] - df["close"].shift(n) new_df["mi"] = ta_func.sma(new_df["a"], n, 1) return new_df