Python 成交量加权移动平均线
我有一个数据框,看起来像:Python 成交量加权移动平均线,python,python-2.7,python-3.x,pandas,Python,Python 2.7,Python 3.x,Pandas,我有一个数据框,看起来像: LAST PRICE VOLUME volume_ratio date 2005-01-03 1202.08 1.332210e+09 1.23 2005-01-04 1188.05 1.552646e+09 1.55
LAST PRICE VOLUME volume_ratio
date
2005-01-03 1202.08 1.332210e+09 1.23
2005-01-04 1188.05 1.552646e+09 1.55
2005-01-05 1183.74 1.428365e+09 1.65
2005-01-06 1187.89 1.331004e+09 1.23
2005-01-07 1186.19 1.273960e+09 0.83
2005-01-10 1190.25 1.213694e+09 1.06
对于
period=5
,我想计算移动平均值VAMA=CumSum/CumDiv
,其中CumSum=(df['volume\u ratio']*df['LAST PRICE'])。CumSum()
和CumDiv=df['volume\u ratio'].CumSum()
,条件是CumDiv仅使用rolling
您是否有要验证的输出?
cum_div = df['volume_ratio'].expanding(min_periods = 1).sum()
cum_summ = (df['LAST PRICE']*df['volume_ratio']).expanding(min_periods =1).sum()
df['cum_sum'] = df.apply(lambda x: cum_summ if cum_div <= 13, axis = 1)
df['myrollingmean'] = df.VAMA.rolling(window = 5).mean()