This release is a pre-release and may not be stable for production use.
wmr
策略持仓权重管理系统(ClickHouse & DuckDB 双后端)。
核心特性
- 双后端:
LocalManager(DuckDB,本地/单机/CI)与OnlineManager(ClickHouse,生产)语义等价。 - 接口对齐
czsc.traders.cwc:函数级 API 转方法封装,参数顺序与默认值完全一致。 - 追加 vs 覆盖语义:
publish_weights仅追加dt > latest_dt;publish_returns允许覆盖同日。 - 标签:在 cwc.py 三表基础上新增
tags表与 4 个标签接口。 - DSN 连接:
OnlineManager默认从WMR_CLICKHOUSE_DSN环境变量加载 DSN,密码自动脱敏。
安装
uv add wmr # 包含 DuckDB + ClickHouse 双后端
uv sync # 项目内开发,等价 uv pip install -e .
Quickstart(LocalManager)
import pandas as pd
from wmr import LocalManager
with LocalManager(db_path="./weights.duckdb") as mgr:
mgr.initialize()
mgr.set_meta("alpha", "1d", "demo", "alice", "2024-01-01", weight_type="ts")
df = pd.DataFrame({
"dt": ["2024-01-01", "2024-01-02"],
"symbol": ["BTC", "BTC"],
"weight": [0.5, 0.6],
})
mgr.publish_weights("alpha", df)
print(mgr.get_latest_weights("alpha"))
print(mgr.summary())
完整示例见 examples/quickstart.py。
OnlineManager(ClickHouse)
import os
from wmr import OnlineManager
os.environ["WMR_CLICKHOUSE_DSN"] = "clickhouse://user:pass@host:9000/czsc_strategy"
with OnlineManager() as mgr: # 自动从 env 读 DSN
mgr.initialize()
mgr.set_meta("alpha", "1d", "", "u", "2024-01-01")
签名:OnlineManager(dsn=None, database=None, client_kwargs=None)。dsn=None
时回退 WMR_CLICKHOUSE_DSN,两者均缺失则抛 ValueError。
双后端选型
| 场景 | 推荐 | 原因 |
|---|---|---|
| 本地开发 / 单机分析 | LocalManager | 零依赖,启动 < 1 秒 |
| CI 测试 | LocalManager | 无需起容器 |
| 生产 / 多用户 / 高并发 | OnlineManager | ReplacingMergeTree + FINAL,横向扩展 |
| 临时验证流水线 | LocalManager → OnlineManager parity | 用 LocalManager 跑通后再上线 |
文档
- 系统设计文档(飞书):wmr 系统设计文档
- 代码质量方案:
docs/code-quality.md
测试
# 仅单元 + 本地集成
uv run pytest -m "unit or integration" -n auto
# 全量(含 ClickHouse,需 docker)
uv run pytest -m "unit or integration or online or parity" -n auto
# 性能基准
uv run pytest -m perf --run-perf
覆盖率门槛:整体 ≥ 90%,核心模块 ≥ 95%(由 --cov-fail-under=90 强制)。
Metadata
Release files for wmr 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wmr-0.1.0a1.tar.gz | 126.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wmr-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 150.4 kB
Release files / wmr-0.1.0a1.tar.gz
| Download URL | wmr-0.1.0a1.tar.gz |
|---|---|
| Size | 126.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bff57380f636e9076bcc59eb54c64f41d77f8148e57a581373cba860d4dcc1f4
|
|
BLAKE2b-256 checksum How to use checksums |
1eb622c10a6377f03f8cefa9e9d2b99cba84e9235bb61da802ef6a50f3ff4827
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logRelease files / wmr-0.1.0a1-py3-none-any.whl
| Download URL | wmr-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 24.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e469e077833e570231fd8ba650f05b872a18236082ff424bb9f15fff874f86da
|
|
BLAKE2b-256 checksum How to use checksums |
84d52e58d90ea0eb461bb8706520de903051de3ff23d66e4a4973ef21ca877e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency log