Weight Manager — 策略持仓权重管理系统(DuckDB / ClickHouse 双后端)
Project description
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 强制)。
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
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 wmr-0.1.0a1.tar.gz.
File metadata
- Download URL: wmr-0.1.0a1.tar.gz
- Upload date:
- Size: 126.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bff57380f636e9076bcc59eb54c64f41d77f8148e57a581373cba860d4dcc1f4
|
|
| MD5 |
623e7f76bd25cee7f544e444c5e3d9b5
|
|
| BLAKE2b-256 |
1eb622c10a6377f03f8cefa9e9d2b99cba84e9235bb61da802ef6a50f3ff4827
|
Provenance
The following attestation bundles were made for wmr-0.1.0a1.tar.gz:
Publisher:
publish.yml on zengbin93/wmr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wmr-0.1.0a1.tar.gz -
Subject digest:
bff57380f636e9076bcc59eb54c64f41d77f8148e57a581373cba860d4dcc1f4 - Sigstore transparency entry: 1397059353
- Sigstore integration time:
-
Permalink:
zengbin93/wmr@9250c305fec7e81d17e1968afc7a9bb7a371bb62 -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/zengbin93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9250c305fec7e81d17e1968afc7a9bb7a371bb62 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wmr-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: wmr-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e469e077833e570231fd8ba650f05b872a18236082ff424bb9f15fff874f86da
|
|
| MD5 |
3c044ee77a80762e32c3d3a805abff74
|
|
| BLAKE2b-256 |
84d52e58d90ea0eb461bb8706520de903051de3ff23d66e4a4973ef21ca877e1
|
Provenance
The following attestation bundles were made for wmr-0.1.0a1-py3-none-any.whl:
Publisher:
publish.yml on zengbin93/wmr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wmr-0.1.0a1-py3-none-any.whl -
Subject digest:
e469e077833e570231fd8ba650f05b872a18236082ff424bb9f15fff874f86da - Sigstore transparency entry: 1397059383
- Sigstore integration time:
-
Permalink:
zengbin93/wmr@9250c305fec7e81d17e1968afc7a9bb7a371bb62 -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/zengbin93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9250c305fec7e81d17e1968afc7a9bb7a371bb62 -
Trigger Event:
push
-
Statement type: