A High-performance And Standard Alpha Factor Mining System
Project description
Alpha Lab
专为因子研究员设计的数据处理与因子挖掘框架,提供简洁的数据获取接口和专业的因子分析工具。
安装
# 使用 uv 安装(推荐)
uv pip install alpha-lab
# 或使用 pip
pip install alpha-lab
快速开始
1. 读取数据
import polars as pl
import datacenter as dc
from tool_box.xcals import api
# 获取交易日列表
trading_days = api.get_tradingdays("2023-01-01", "2023-01-31")
# 读取股票日线数据
df = dc.md.read_data_batch(
start_date="2023-01-01",
end_date="2023-01-31",
instrument=dc.Instrument.STOCK,
data_type=dc.DataType.KLINE_DAY
)
# 读取基础信息
stocks = dc.jy.asset(date="2023-01-01") # 可用股票
industry = dc.jy.industry(date="2023-01-01") # 行业分类
adj_factors = dc.jy.adj_factors(date="2023-01-01") # 复权因子
2. 计算因子
使用 Polars 简洁高效地计算因子:
# 计算 5 日收益率因子
factor_df = df.with_columns(
ret_5d=pl.col("close").pct_change(5)
).filter(
pl.col("volume") > 0 # 过滤停牌
)
# 更多因子示例
factor_df = df.with_columns(
ret_1d=pl.col("close").pct_change(1),
ret_5d=pl.col("close").pct_change(5),
ret_20d=pl.col("close").pct_change(20),
volume_ratio=pl.col("volume") / pl.col("volume").rolling_mean(20),
).filter(pl.col("volume") > 0)
3. 因子分析 (Rack + Polens)
使用 Rack 整合数据,Polens 进行专业因子分析:
from alphamaster.rack import Rack
from alphamaster.polens import FactorAnalyzer
# Rack: 加载行情数据并整合因子
rack = Rack()
rack.load_prices("2023-01-01", "2023-12-31") # 加载行情
rack.set_factor(factor_df) # 设置因子
# Polens: 因子分析
analyzer = FactorAnalyzer(rack.get_data(), group_col="industry")
analyzer.preprocess(periods=[1, 5, 10], quantiles=5)
analyzer.analyze()
# 获取统计指标
stats = analyzer.summary_stats()
print(stats)
# 绘制分析图表
analyzer.plot("ic_ts") # IC 时序图
analyzer.plot("quantile_cum") # 分层累积收益
analyzer.plot("stability") # 因子稳定性
提示: Rack 会自动缓存行情数据,更换因子时无需重新加载。
核心模块
| 模块 | 说明 |
|---|---|
datacenter |
数据访问层,统一获取行情和基础信息 |
tool_box.xcals |
交易日历工具 |
alphamaster.rack |
数据整合器,加载行情并整合因子数据 |
alphamaster.polens |
因子分析工具(IC、分层收益、换手率等) |
许可证
Project details
Release history Release notifications | RSS feed
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.7.tar.gz
(135.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
alpha_lab-0.1.7-py3-none-any.whl
(62.8 kB
view details)
File details
Details for the file alpha_lab-0.1.7.tar.gz.
File metadata
- Download URL: alpha_lab-0.1.7.tar.gz
- Upload date:
- Size: 135.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c808f897ac878cb015d9e2df7b431df6c50dae60a477a3ac6e57123f3196158
|
|
| MD5 |
216443e94e2a54e1ab193cd9b0bfaa99
|
|
| BLAKE2b-256 |
f2427b0bbbf3d5ce450ec9b192fa7e71966d0a63fbc247e4cffb7a5265bc5f36
|
File details
Details for the file alpha_lab-0.1.7-py3-none-any.whl.
File metadata
- Download URL: alpha_lab-0.1.7-py3-none-any.whl
- Upload date:
- Size: 62.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a74758225ed6f195162033956c9fdeeb4565efad0cbbc5bd22f243c7c81bcc28
|
|
| MD5 |
7e81fa177b09087681ab3bd4095f4003
|
|
| BLAKE2b-256 |
5680729c55118ec8674555424bf165f4653ae813db8eeccae8643205fb5745dc
|