Skip to main content

Alpha analysis tools box

Project description

AlphalensPlus: A better toolbox for factors' alpha analysis

基于 QuantopianAlphalens 开发的升级版因子分析工具箱,针对 A 股市场数据结构与交易规则做了适配与增强。

安装

# 使用 uv(推荐)
uv pip install -e ".[opt]"

# 或使用 pip
pip install -e ".[opt]"

若不需要组合优化(opt 模块),可省略 [opt],无需安装 cvxpy

快速开始

以下示例展示从模拟数据生成完整分析报告的最小流程:

import pandas as pd
import numpy as np
import alphalens_plus as ap

# 1. 构造模拟行情数据(长面板)
#    索引:(order_book_id, date),必须包含 close 与 open 列
dates = pd.date_range('2023-01-01', periods=20, freq='B')
assets = ['000001.XSHE', '000002.XSHE', '000009.XSHE', '000012.XSHE']
np.random.seed(42)

prices = pd.DataFrame(
    {
        'close': 100 * np.exp(np.cumsum(np.random.randn(80) * 0.02 + 0.001)),
        'open' : 100 * np.exp(np.cumsum(np.random.randn(80) * 0.02 + 0.001)),
    },
    index=pd.MultiIndex.from_product(
        [assets, dates], names=['order_book_id', 'date']
    )
)

# 2. 构造模拟因子数据(长面板)
#    索引:(date, order_book_id),列名为 factor
factor = pd.DataFrame(
    np.random.randn(80),
    index=pd.MultiIndex.from_product(
        [dates, assets], names=['date', 'order_book_id']
    ),
    columns=['factor']
)

# 3. 计算清洗后的因子与远期收益率
factor_data = ap.get_clean_factor_and_forward_returns(
    factor, prices, periods=(1, 5), method='open-to-open'
)

# 4. 生成完整 Tear Sheet 分析报告
ap.create_full_tear_sheet(factor_data)

核心 API 速览

alphalens_plus 已将最常用函数暴露在包顶层,可直接通过 import alphalens_plus as ap 调用:

功能 顶层 API
清洗因子 + 计算远期收益 ap.get_clean_factor_and_forward_returns
因子分位数分层 ap.quantize_factor
因子排序 ap.rank_factor
信息系数 IC ap.factor_information_coefficient
平均 IC ap.mean_information_coefficient
组合权重 ap.factor_weights
完整 Tear Sheet ap.create_full_tear_sheet
最小方差优化 ap.min_variance(需安装 cvxpy

若需更细粒度的控制,仍可按需导入子模块:

from alphalens_plus import utils, performance, plotting, tears

日志与更新记录

项目开发日志已迁移至 LOGGING.md

References

  • quantopian/alphalens:

    • 原生alphalens项目,主体内容于2015年左右实现,目前可复用,但局部代码需更新。
    • 整体用作思路参考。
  • stefan-jansen/alphalens-reloaded

    • 大佬Stefan Jansen维护的alphalens项目,对最新版本python进行适配,可复用程度较高。
    • 是主要学习和参考的项目。
  • github:vnpy_alphalens

    • vnpy的自适应版,更多面向回测系统使用,次要学习和参考项目。

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

dsf_alphalens-1.0.3.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsf_alphalens-1.0.3-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file dsf_alphalens-1.0.3.tar.gz.

File metadata

  • Download URL: dsf_alphalens-1.0.3.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dsf_alphalens-1.0.3.tar.gz
Algorithm Hash digest
SHA256 5aa582cbbdb246dfa552efc179f035d2a4d61ee17c120d31cd8c31414c8cf86a
MD5 0ff2d80ace485bf06595ba0bba8e81d9
BLAKE2b-256 2add707e51498ae364586bd596566ecebe125dfbde047ce33342bc97b54fc94b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dsf_alphalens-1.0.3.tar.gz:

Publisher: release.yml on RoadToQuant/alphalens_plus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dsf_alphalens-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: dsf_alphalens-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dsf_alphalens-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9aee7bb02a7b7f6474998581a7d90658b8d088de10cc71122cf1f30559e31115
MD5 a8702d9049996461ec906718c2f8ab1f
BLAKE2b-256 c8de622091e54c456139179e9ebe7bed51e455d88686873c13d942221642bca6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dsf_alphalens-1.0.3-py3-none-any.whl:

Publisher: release.yml on RoadToQuant/alphalens_plus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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