Quantopian的Alphalens的平均收益错误

时间:2019-05-12 18:30:42

标签: python pandas-groupby quantopian

重新创建通过Alphalens软件包获得的结果时遇到了一些麻烦。特别是,mean_return_by_quantile函数给我的结果与熊猫的groupby函数给我的结果不同。

我已复制一个最小示例来说明问题:

我创建了一个min示例来说明问题

import pandas as pd
import alphalens as al

dict1 = [
        {'ticker':'jpm','date': '2016-11-29','1D': 0,'factor_quantile': 1},
{ 'ticker':'ge','date': '2016-11-29','1D': 0,'factor_quantile': 1},
{'ticker':'fb', 'date': '2016-11-29','1D': 0,'factor_quantile': 1},
{'ticker':'aapl', 'date': '2016-11-29','1D': 3,'factor_quantile': 2},
{'ticker':'msft','date': '2016-11-29','1D': 3,'factor_quantile': 2},
{'ticker':'amzn','date': '2016-11-29','1D': 3,'factor_quantile': 2},
{'ticker':'jpm','date': '2016-11-30','1D': 0,'factor_quantile': 1},
{'ticker':'ge', 'date': '2016-11-30','1D':0,'factor_quantile': 1},
{'ticker':'fb','date': '2016-11-30','1D': 0,'factor_quantile': 1},
{'ticker':'aapl','date': '2016-11-30','1D': 3,'factor_quantile': 2},
{'ticker':'msft','date': '2016-11-30','1D': 3,'factor_quantile': 2},
{'ticker':'amzn','date': '2016-11-30','1D': 3,'factor_quantile': 2}
]
df1 = pd.DataFrame(dict1)
factor_data=df1.set_index(['date',"ticker"], drop=True) 

# These two functions should produce the same mean by quantile 
factor_data.groupby(['factor_quantile']).mean()

mean_return_by_q, std_err_by_q = al.performance.mean_return_by_quantile(factor_data)
print(mean_return_by_q)

0 个答案:

没有答案