Skip to main content

A High-performance And Standard Alpha Factor Mining System

Project description

Alpha Lab: High-Performance Alpha Mining System

License: MIT Python Code Style: Ruff Polars

Alpha Lab 是一个专为量化金融研究设计的高性能数据处理与因子挖掘框架。它深度集成了现代 Python 数据技术栈(Polars, Apache Arrow, ClickHouse),旨在解决传统量化研究中数据加载慢、内存占用高、计算效率低等核心痛点。

通过采用惰性计算(Lazy Evaluation)和列式存储(Columnar Storage),Alpha Lab 能够在单机环境下高效处理 TB 级别的金融时序数据。


🌟 核心特性 (Features)

  • 🚀 极致性能: 基于 Rust 编写的 Polars 引擎,支持多线程并行计算、SIMD 优化及外存(Out-of-Core)处理。
  • 💾 高效存储: 基于 Parquet 的本地数据仓库,支持自动分区管理、Hive分区结构和谓词下推,专为高频行情设计。
  • 🛠 交易日历 (Xcals): 内置高精度中国市场交易日历,支持复杂的交易日推算、偏移及周期聚合。
  • 🔄 数据访问层 (Datacenter): 独创的"统一视图"模式,无缝连接按天存储的行情数据(Market Data)与按表存储的基础信息(Inform Data),最大化 IO 效率。

📦 安装指南 (Installation)

环境要求

  • OS: Linux / macOS / Windows (WSL推荐)
  • Python: 3.9+

从 PyPI 安装(推荐)

pip install alpha-lab

从源码安装

如果需要从源码安装,我们推荐使用 uv 进行极速环境构建与依赖管理:

# 1. 安装 uv
pip install uv

# 2. 克隆仓库
git clone https://github.com/yourusername/alpha-lab.git
cd alpha-lab

# 3. 同步环境
uv sync --all-extras

# 4. 激活环境
source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate   # Windows

传统方式

# 创建虚拟环境
python -m venv .venv

# 激活环境
source .venv/bin/activate  # Linux/macOS
# .venv\Scripts\activate   # Windows

# 安装项目依赖
pip install -e .[dev]

⚙️ 配置 (Configuration)

项目首次运行会自动在用户主目录 (~) 下生成必要的配置文件。

  1. 交易日历配置 (~/.xcals)

    • 存放交易日历数据文件,确保 xcals 模块能正确计算交易日。
  2. Blazestore 配置 (~/.blaze/config.toml)

    • 配置本地数据仓库的存储路径。
    • 示例内容:
      [paths]
      store = "/home/user/BlazeStore"
      
      [databases.mysql]
      user = "your_user"
      password = "your_password"
      url = "localhost:3306/database_name"
      database = "database_name"
      
      [databases.ck]
      user = "your_user"
      password = "your_password"
      urls = "localhost:8123"
      

🚀 因子研究示例

对于因子研究员,我们提供了简洁的数据访问接口,无需了解底层存储细节。

交易日历使用

from tool_box.xcals import api

# 获取日期范围内的所有交易日
trading_days = api.get_tradingdays(beg_date="2023-01-01", end_date="2023-01-31")

# 计算 T+1 交易日
next_day = api.shift_tradeday("2023-01-20", 1)

# 判断是否为交易日
is_open = api.is_tradeday("2023-01-22")  # False (Sunday)

读取行情数据

import polars as pl
import datacenter as dc
from tool_box import xcals

# 获取日期范围
start_date = "2023-01-01"
end_date = "2023-01-31"
trading_days = xcals.get_tradingdays(start_date, end_date)

# 读取股票日线数据
df = dc.md.read_data_batch(
    start_date,
    end_date,
    dc.Instrument.STOCK,
    dc.DataType.KLINE_DAY
)

# 计算因子:5日收益率
factor_df = df.with_columns(
    # 计算每日收益率
    daily_return=pl.col("close").pct_change(),
    # 计算5日收益率
    five_day_return=pl.col("close").pct_change(periods=5)
).filter(
    # 过滤掉无效数据
    pl.col("volume") > 0
)

# 展示结果
print(factor_df.head())

读取基础信息

import datacenter as dc

# 获取股票代码列表
stock_codes = dc.jy.codes(date="2023-01-01")

# 获取可用股票(经过筛选)
available_stocks = dc.jy.asset(date="2023-01-01")

# 读取行业分类
industry = dc.jy.industry(date="2023-01-01")

# 读取股本信息
shares = dc.jy.shares(date="2023-01-01")

# 读取复权因子
adj_factors = dc.jy.adj_factors(date="2023-01-01")

📄 许可证 (License)

本项目采用 MIT 许可证 开源。

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

alpha_lab-0.1.4.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

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

alpha_lab-0.1.4-py3-none-any.whl (49.2 kB view details)

Uploaded Python 3

File details

Details for the file alpha_lab-0.1.4.tar.gz.

File metadata

  • Download URL: alpha_lab-0.1.4.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for alpha_lab-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6a67532ec433177618ea62928ece31b945c8cbadd8ef5cb459215660d5101681
MD5 89272738fa61bd820879f959fcc52ac4
BLAKE2b-256 2e2cc0e2802383ae3808f37112e1649d2d1ce98e8182b61dd20773ebbff9dca9

See more details on using hashes here.

File details

Details for the file alpha_lab-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: alpha_lab-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 49.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for alpha_lab-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 351233812343e1ea89c5712925aa4b99d63124974ceac75a8c0972e1578dbd35
MD5 a8fbccb50c2c99cdf17df5b198f169f5
BLAKE2b-256 3b16cb14b5173c15c3ff644ec10952ff4e299e5ef28f9de627abde02b30cc023

See more details on using hashes here.

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