def MA_RIBBON(df, ma_series):
ma_array = np.zeros([len(df), len(ma_series)])
ema_list = []
for idx, ma_len in enumerate(ma_series):
ema_i = EMA(df, n = ma_len, field = 'close')
ma_array[:, idx] = ema_i
ema_list.append(ema_i)
corr = np.empty([len(df)])
pval = np.empty([len(df)])
dist = np.empty([len(df)])
corr[:] = np.NAN
pval[:] = np.NAN
dist[:] = np.NAN
max_n = max(ma_series)
for idy in range(len(df)):
if idy >= max_n - 1:
corr[idy], pval[idy] = stats.spearmanr(ma_array[idy,:], range(len(ma_series), 0, -1))
dist[idy] = max(ma_array[idy,:]) - min(ma_array[idy,:])
corr_ts = pd.Series(corr*100, index = df.index, name = "MARIBBON_CORR")
pval_ts = pd.Series(pval*100, index = df.index, name = "MARIBBON_PVAL")
dist_ts = pd.Series(dist, index = df.index, name = "MARIBBON_DIST")
return pd.concat([corr_ts, pval_ts, dist_ts] + ema_list, join='outer', axis=1)
评论列表
文章目录