def DVO(df, w = [0.5, 0.5, 0, 0], N = 2, s = [0.5, 0.5], M = 252):
ratio = df.close/(df.high * w[0] + df.low * w[1] + df.open * w[2] + df.close * w[3])
theta = pd.Series(index = df.index)
dvo = pd.Series(index = df.index, name='DV%s_%s' % (N, M))
ss = np.array(list(reversed(s)))
for idx, d in enumerate(ratio.index):
if idx >= N-1:
y = ratio[idx-N+1:idx+1].values
theta[idx] = np.dot(y, ss)
if idx >= M+N-2:
ts = theta[idx-(M-1):idx+1]
dvo[idx] = stats.percentileofscore(ts.values, theta[idx])
return dvo
评论列表
文章目录