import pandas as pd
times = pd.to_datetime(pd.Series(['2014-07-4',
'2014-07-15','2014-08-25','2014-08-25','2014-09-10','2014-09-15']))
strategypercentage = [0.01, 0.02, -0.03, 0.04,0.5,-0.3]
df = pd.DataFrame({'Strategy': strategypercentage}, index=times)
##lambda x: ((1+x).cumprod()-1)
df.resample("1M").agg({'Strategy' : ['sum','prod']})
数据帧包括日期、每日百分比变化、如何计算每月百分比变化(看起来像((1+x).cumprod()-1))——但是如何用agg实现呢? 预期结果: enter image description here
看来你需要:
相关问题 更多 >
编程相关推荐