Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Fail to replicate Alphalens Backtest Returns

I would like to replicate the factor returns graph created by Alphalens (to ensure I understand correctly what goes on under the hood) but I am getting different results when I try to replicate this using pandas qcut, see attached notebook. In particular I am trying to replicate this:

mean_return_by_q, std_err_by_q = al.performance.mean_return_by_quantile(df_returns)

al.plotting.plot_quantile_returns_bar(
mean_return_by_q.apply(
al.utils.rate_of_return,
axis=0,
args=('125D',)
) );

With this:

df_returns['decile']=pd.qcut(df_returns['factor'],2,labels=False)+1
quantile_averages=df_returns.groupby('decile')['125D'].apply(lambda x:
x.mean()) quantile_averages.plot(kind='bar') plt.xlabel('ROE deciles')
plt.ylabel('125D');