[关闭]
@Channelchan 2017-07-13T16:18:25.000000Z 字数 1485 阅读 29976

Alphalens


Alphalens是什么?

Alphalens是一个Python包,用于对阿尔法因子进行性能分析。Alpha因子表示一些给定的信息和未来的回报之间的预测关系。通过将这种关系应用于多个股票,能够产生阿尔法信号,然后从中交易。开发一个好的alpha信号是很有挑战性的,那么用Alphalens能让事情变得更简单,因为一套用于分析alpha因素的常用工具会对量化交易产生很大的影响。通过Alphalens分析你在研究中的因素,你可以花更少的时间来写和运行回测。因此,这允许更快的思想迭代,以及最终的算法,您可以对它有信心。Alphalens建立了一个严格的工作流程,将使你的策略更有活力,更不容易过度拟合。


Alphalens提供了什么功能?

  1. 收益分析(Returns Analysis)
  2. 信息系数(Information Coefficient Analysis)
  3. 换手率分析(Turnover Analysis)
  4. 板块分析(Sector Analysis)

数据格式:

factor: DataFrame.stack()
prices: DataFrame


常用代码:

  1. import alphalens
  2. def get_clean_factor_and_forward_returns(factor,
  3. prices,
  4. groupby=None,
  5. by_group=False,
  6. quantiles=5,
  7. bins=None,
  8. periods=(1, 5, 10),
  9. filter_zscore=20,
  10. groupby_labels=None):
  11. #计算因子表
  12. factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factor, prices, quantiles=5, period=(10))
  13. #求Quantile的均值与标准差
  14. mean_return_by_q, std_err_by_q = alphalens.performance.mean_return_by_quantile(factor_data, by_date=True)
  15. #求IC相关
  16. ic = alphalens.performance.factor_information_coefficient(factor_data)
  17. mean_monthly_ic = alphalens.performance.mean_information_coefficient(factor_data, by_time='M')
  1. import matplotlib.pyplot as plt
  2. # 图形可视化
  3. alphalens.plotting.plot_cumulative_returns_by_quantile(mean_return_by_q, 10)
  4. alphalens.plotting.plot_cumulative_returns(mean_return_by_q.iloc[:,0], period=1)
  5. alphalens.plotting.plot_ic_hist(ic)
  6. alphalens.plotting.plot_monthly_ic_heatmap(mean_monthly_ic)
  7. plt.show()

官方文档: http://quantopian.github.io/alphalens/
Github: https://github.com/quantopian/alphalens
大鱼案例: https://github.com/ChannelCMT/QS/tree/master/Class_1_Alpha

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注