@Channelchan
2017-07-13T16:18:25.000000Z
字数 1485
阅读 29976
Alphalens是一个Python包,用于对阿尔法因子进行性能分析。Alpha因子表示一些给定的信息和未来的回报之间的预测关系。通过将这种关系应用于多个股票,能够产生阿尔法信号,然后从中交易。开发一个好的alpha信号是很有挑战性的,那么用Alphalens能让事情变得更简单,因为一套用于分析alpha因素的常用工具会对量化交易产生很大的影响。通过Alphalens分析你在研究中的因素,你可以花更少的时间来写和运行回测。因此,这允许更快的思想迭代,以及最终的算法,您可以对它有信心。Alphalens建立了一个严格的工作流程,将使你的策略更有活力,更不容易过度拟合。
factor: DataFrame.stack()
prices: DataFrame
import alphalens
def get_clean_factor_and_forward_returns(factor,
prices,
groupby=None,
by_group=False,
quantiles=5,
bins=None,
periods=(1, 5, 10),
filter_zscore=20,
groupby_labels=None):
#计算因子表
factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factor, prices, quantiles=5, period=(10))
#求Quantile的均值与标准差
mean_return_by_q, std_err_by_q = alphalens.performance.mean_return_by_quantile(factor_data, by_date=True)
#求IC相关
ic = alphalens.performance.factor_information_coefficient(factor_data)
mean_monthly_ic = alphalens.performance.mean_information_coefficient(factor_data, by_time='M')
import matplotlib.pyplot as plt
# 图形可视化
alphalens.plotting.plot_cumulative_returns_by_quantile(mean_return_by_q, 10)
alphalens.plotting.plot_cumulative_returns(mean_return_by_q.iloc[:,0], period=1)
alphalens.plotting.plot_ic_hist(ic)
alphalens.plotting.plot_monthly_ic_heatmap(mean_monthly_ic)
plt.show()
官方文档: http://quantopian.github.io/alphalens/
Github: https://github.com/quantopian/alphalens
大鱼案例: https://github.com/ChannelCMT/QS/tree/master/Class_1_Alpha