Skip to main content

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 跑通后再上线

文档

测试

# 仅单元 + 本地集成
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wmr-0.1.0a1.tar.gz (126.2 kB view details)

Uploaded Source

Built Distribution

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

wmr-0.1.0a1-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

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

Hashes for wmr-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 bff57380f636e9076bcc59eb54c64f41d77f8148e57a581373cba860d4dcc1f4
MD5 623e7f76bd25cee7f544e444c5e3d9b5
BLAKE2b-256 1eb622c10a6377f03f8cefa9e9d2b99cba84e9235bb61da802ef6a50f3ff4827

See more details on using hashes here.

Provenance

The following attestation bundles were made for wmr-0.1.0a1.tar.gz:

Publisher: publish.yml on zengbin93/wmr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for wmr-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 e469e077833e570231fd8ba650f05b872a18236082ff424bb9f15fff874f86da
MD5 3c044ee77a80762e32c3d3a805abff74
BLAKE2b-256 84d52e58d90ea0eb461bb8706520de903051de3ff23d66e4a4973ef21ca877e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for wmr-0.1.0a1-py3-none-any.whl:

Publisher: publish.yml on zengbin93/wmr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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