Skip to main content

Alpha 策略研究基础库:交易日历、存储引擎、并发框架、ClickHouse 驱动

Project description

Alpha Common

License: MIT Python Ruff

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 .

许可证

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_common-0.1.2.tar.gz (85.7 kB view details)

Uploaded Source

Built Distribution

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

alpha_common-0.1.2-py3-none-any.whl (93.5 kB view details)

Uploaded Python 3

File details

Details for the file alpha_common-0.1.2.tar.gz.

File metadata

  • Download URL: alpha_common-0.1.2.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

Hashes for alpha_common-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2fe89622cc757627ca42de8287e41e2107ce86fbe4e8f2332090622fb2cac486
MD5 77c3af9e5ff03dd80decc8752015f88f
BLAKE2b-256 b24575e2454392f563d9cbdf1677b7b8fe375854cfcc14222ed85874a3d1bdbc

See more details on using hashes here.

File details

Details for the file alpha_common-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: alpha_common-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 93.5 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

Hashes for alpha_common-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9483813997e52eb2d2e3ee603c4d343968528a0dfe90f270425bb17c68d3f933
MD5 4be493b21f04f448d7edc2e8d84f43ac
BLAKE2b-256 b98b2f67f08386fcddf6836fac65ba621df1ed84f8f4f2cbf3ab1da702cd6b44

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