Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 成交量加权移动平均线_Python_Python 2.7_Python 3.x_Pandas - Fatal编程技术网

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()