Alpha 策略研究基础库:交易日历、存储引擎、并发框架、ClickHouse 驱动
Project description
Alpha Common
Alpha 策略研究基础库,为量化研究提供基础设施:交易日历、本地 Parquet 存储引擎、并发框架、ClickHouse 数据库驱动。
安装
pip install alpha-common
从源码安装(开发模式):
git clone https://github.com/Aequiludium/alpha-common.git
cd alpha-common
uv sync
模块
| 模块 | 说明 | 主要功能 |
|---|---|---|
xcals |
交易日历 | A 股交易日查询、日期偏移、财务报告期计算 |
blazestore |
存储引擎 | 本地 Parquet 文件存储,Hive 分区 + SQL 查询 |
ygo |
并发框架 | 延迟执行 + 线程池 + 进度管理 |
clickhouse_df |
数据库驱动 | ClickHouse 连接与 DataFrame 读写 |
使用
xcals — 交易日历
import xcals
# 交易日查询
days = xcals.get_tradingdays("2024-01-01", "2024-12-31")
today = xcals.today()
# 日期偏移
prev = xcals.shift_tradeday("2024-12-31", -5)
# 判断是否为交易日
xcals.is_tradeday("2024-12-31") # True
# 更新交易日数据
xcals.update()
# Polars 表达式集成(可用于 DataFrame 操作)
import polars as pl
df = pl.DataFrame({"date_str": ["2024-01-01", "2024-01-02"]})
df.with_columns(xcals.to_date("date_str").alias("date"))
blazestore — 本地 Parquet 存储引擎
from blazestore import ParquetStore
store = ParquetStore("/data/store")
# 写入数据(自动 Hive 分区)
store.put("trades", df)
# 读取为 LazyFrame
lf = store.read("trades WHERE date = '2024-01-01'")
# 表管理
store.list_tables()
store.get_table_info("trades")
store.optimize_table("trades")
ygo — 并发框架
from ygo import Pool
pool = Pool()
for day in trading_days:
pool.submit(download_data, day=day)
results = pool.do()
pool.close()
clickhouse_df — ClickHouse 数据库驱动
from clickhouse_df import to_polars, to_pandas
from clickhouse_df import connect
# 查询到 DataFrame
df = to_polars("SELECT * FROM system.tables")
# 查询到 Pandas
pdf = to_pandas("SELECT * FROM system.tables")
# 批量下载
from clickhouse_df import raw_download
raw_download("SELECT * FROM big_table", "output.csv", {})
开发
# 安装依赖
uv sync
# 运行测试
uv run pytest tests/
# 代码检查
uv run ruff check .
uv run ruff format --check .
许可证
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_common-0.1.1.tar.gz
(85.7 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
File details
Details for the file alpha_common-0.1.1.tar.gz.
File metadata
- Download URL: alpha_common-0.1.1.tar.gz
- Upload date:
- Size: 85.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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 |
aafc3646ae6dbe77d8fb2c21d8c878c05e3a5af66f56f8a20bba411b0650cee2
|
|
| MD5 |
64f0e6cc733f42be3e116a1909de213e
|
|
| BLAKE2b-256 |
75dbf1bfe60431886b7f60436ee6f4660ba12c5705b872d939a9c9872e877466
|
File details
Details for the file alpha_common-0.1.1-py3-none-any.whl.
File metadata
- Download URL: alpha_common-0.1.1-py3-none-any.whl
- Upload date:
- Size: 93.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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 |
bb4f8c66c11fb2f247ef4b2a17f2b50a111b948fcdd6f47b9d96c08a3c59feb8
|
|
| MD5 |
ee5734d9e6a699b63f5a4b91464f40aa
|
|
| BLAKE2b-256 |
7b6e403304688c952081c1eed4e7d1f91a251907acb38458aa390c2abab3d681
|