Skip to main content

factor performance visualization

Project description

AlphaInspect

仿alphalens的单因子分析工具

安装

pip install -i https://pypi.org/simple --upgrade alphainspect  # 官方源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade alphainspect  # 国内镜像源

使用

  1. 准备数据。运行data/prepare_data.py
    1. date, asset。必需的两个字段
    2. factor因子值。放在因子发生时刻
    3. forward return远期收益率。计算收益率后需要回移到开始位置。为何是shift(-n)收益率,而不是shift(n)因子呢?
      1. 多期收期率。如果移动因子,会导致一个因子就要移动多次
      2. 因子一般成百上千,全移动要的工作量非常大,而收益率则少很多
    4. 推荐大家使用expr_codegenpolars_ta等项目
  2. 运行examples/demo1.py示例弹出简易图表
  3. 运行examples/demo2.py示例弹出完整图表
  4. 运行examples/demo3.py示例多进程并行输出HTML网页报表
  5. 运行examples/demo4.py示例事件图表

部分图示

2x2 3x2 ic returns cum_returns spread turnover events

累计收益的计算方法

参考 cum_returns.md

alphainspectalphalens的不同

  1. 不自动计算forward_returns
    1. alphalensperiods=(1, 5, 10),然后内部计算持有1、5、10期数的收益率
    2. alphainspect由用户外部生成,用户可以比较同因子,不同交易方式产生的差异。例如:
      • RETURN_OC_1: T+1开盘入场,T+1收盘出场
      • RETURN_CC_1: T+0收盘入场,T+1收盘出场
      • RETURN_OO_1: T+1开盘入场,T+2开盘出场
      • RETURN_OO_5: T+1开盘入场,T+6开盘出场
  2. 不做去极值、标准化、行业中性化等操作
    1. alphalens的各参数要弄懂还是很麻烦的,初学者如绩效达不到要求就得深入研究源代码找原因
    2. alphainspect用户在外可以一次性全计算好,如F1_ORG, F1_ZS, F1_NEUT,然后在分别传不同因子进行比较即可
  3. 资金分配只用等权
    1. alphalens有因子加权、多空等设置
    2. alphainspect只提供等权一种计算方法,实现简单
  4. 收益率计算方法不同
    1. alphalens多期简单收益率几何平均成1期,然后+1累乘
    2. alphainspect由用户提供1期简单收益率,然后根据要求持有或调仓,得到新的权益,循环迭代下去。更精确
    3. alphainspect由用户提供每期收益率(也可以使用多期收益率的几何平均),然后累加。(分层计算速度提高1~1.5倍)

alphainspectalphalens的相同

  1. 数据组织方式相同。都是长表,都是因子不移动,收益率计算,然后后移到与因子产生时间对齐
  2. 不考虑滑点和手续费。单因子是用来合成多因子的,因手续费和滑点而错过部分单因子就可惜了,应当在因子合成后的回测阶段才考虑手续费
  3. 收益计算不求精确,只为能正确评价因子绩效

二次开发

git --clone https://github.com/wukan1986/alphainspect.git
cd alphainspect
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alphainspect-0.4.4.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

alphainspect-0.4.4-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file alphainspect-0.4.4.tar.gz.

File metadata

  • Download URL: alphainspect-0.4.4.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for alphainspect-0.4.4.tar.gz
Algorithm Hash digest
SHA256 a152df189a27be41ad798a7101d039a1f0b14c2de6a25a720cf6de6ed66b4d76
MD5 514e8335f86f44bceccad100e7c1fc63
BLAKE2b-256 6dd961d4851128fedfca621827f80514c33fd919602530883f9aa13803ab4063

See more details on using hashes here.

File details

Details for the file alphainspect-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: alphainspect-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for alphainspect-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 91141fecf3045ad60f4fbe1ecf529e6c7db43b1cc68ea8c2ed3b2fa5307f92fe
MD5 1f1440de87feed22a4810152f029cdc8
BLAKE2b-256 ec11df0b581e9a35e99c001c9617bd86f549a6352cf8f14f554ea3b26f2da568

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page