rebalance

rebalance is a command for Claude Code from wbh604/UZI-Skill. It costs 35 tokens per session (898 once invoked), scanned A, original, MIT.

A portfolio rebalancing command for comparing current investment weights with target weights and preparing possible trades across Chinese, Hong Kong, and US stocks.

In plain words
What is it for?
Use it to inspect drift, identify which holdings to buy or sell, estimate share quantities and costs when values and prices are provided, and review concentration.
Why use it?
It shows when holdings have drifted beyond a chosen threshold and accounts for trading turnover costs, without applying tax-loss harvesting for mainland Chinese personal investors.

Command for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the UZI-Skill plugin — 5 skills, 20 commands, 1 agent, 1 hook shipped together

Good fit Use it to inspect drift, identify which holdings to buy or sell, estimate share quantities and costs when values and prices are provided, and review concentration.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/wbh604/uzi-skill/rebalance
About the project

UZI-Skill is a collection of coding-agent skills for analyzing individual stocks across Chinese, Hong Kong, and United States markets using public data, investor viewpoints, quantitative rules, and institutional analysis methods. It is for users who want an agent to produce detailed stock-analysis reports. The catalogue entries are the commands, skills, instructions, plugin, agent, and hook that provide this workflow in supported coding agents.

wbh604/UZI-Skill · 6,804 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/wbh604/UZI-Skill

Made for: Claude Code.

Or install UZI-Skill, the plugin that ships this one along with the rest of its 5 skills, 20 commands, 1 agent, 1 hook.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rebalance

README.md
[![agentmods](https://agentmods.dev/badge/commands/wbh604/uzi-skill/rebalance/github.svg)](https://agentmods.dev/commands/wbh604/uzi-skill/rebalance)
Your own site
<a href="https://agentmods.dev/commands/wbh604/uzi-skill/rebalance"><img src="https://agentmods.dev/badge/commands/wbh604/uzi-skill/rebalance/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for rebalance

Your own site · 80×15
<a href="https://agentmods.dev/commands/wbh604/uzi-skill/rebalance"><img src="https://agentmods.dev/badge/commands/wbh604/uzi-skill/rebalance.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 35 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 898 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00035 $0.00898
Opus 5 $0.00017 $0.00449
Sonnet 5 $0.00007 $0.00180
Haiku 4.5 $0.00003 $0.00090

Measured 9d ago against content hash 75a537ae5eb8, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

rebalance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/rebalance.md · 60 lines

What it actually says

/rebalance <持仓> [targets=等权] [threshold=5]

对一个组合做再平衡分析:当前权重偏离目标多少、要不要动、动的话买卖什么、换手要花多少钱。

A 股个人无资本利得税 → 不做税损收割 (TLH),聚焦 漂移 + 风险 + 换手成本。 (持仓含美股时,会一句话提示"美股部分可另议税损"。)

输入

持仓列表 [{ticker, weight, market, industry?, value?, price?}],与 --portfolio 的 CSV 结构同源(ticker / weight / note):

字段 必填 说明
ticker 600519.SH / 00700.HK / AAPL
weight 当前权重,0-1 小数或 0-100 百分数(自动归一化)
market A / HK / US,缺省按 ticker 后缀推断
industry 行业,用于行业分散度
value 该持仓市值(给了才能算金额/成本)
price 现价(给了才能估股数,A 股按手取整)
  • targetsNone → 等权 (1/N);或 {ticker: 目标权重} 显式目标。
  • threshold:漂移阈值,单位「百分点」,默认 5(偏离 >5pp 才动)。

工作流

from lib.tier1.rebalance import build_rebalance

out = build_rebalance(holdings, targets=None, drift_threshold=5.0)
# out = {drift_table, trades, turnover_cost, concentration, summary, methodology_log}

配合已有 --portfolio:先 python run.py --portfolio holdings.csv 跑组合体检, 再把同一份 holdings 喂给 build_rebalance 做调仓建议。

输出

  1. 漂移表 drift_table — 每只 当前 vs 目标 vs 漂移(pp) + 是否超阈值 + 方向(超配→卖/低配→买)
  2. 阈值判断 summary.any_breach / n_breached / max_drift_pp — 默认 >5pp 才触发
  3. 交易清单 trades — 仅对超阈值持仓:BUY/SELL + 金额 + 估算股数(A 股按手)
  4. 换手成本 turnover_cost — 分市场拆解:
    • A 股:卖出印花税 0.05%(2023-08 下调)+ 双边佣金 ~0.025%
    • 港股:印花税 0.1%(双边)+ 佣金
    • 美股:印花税 ≈ 0
  5. 集中度变化 concentration — 前 3 大集中度 / 最大单只 / HHI / 行业分散 的 前→后 对比

注意

  • 小幅漂移在阈值内不动,别为再平衡而再平衡。
  • 没给 value/price 时只出漂移方向,不估金额与成本。
  • 不做 TLH(A/港股个人无资本利得税);美股持仓的税损另议。

改编自 anthropics/financial-services wealth-management/portfolio-rebalance,A 股适配。 方法论详见 skills/deep-analysis/references/fin-methods/rebalance.md

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 60 lines · 35 tokens per session scan A 75a537ae5eb8

Subscribe to this mod's changes

rebalance is a command published in the GitHub repository wbh604/UZI-Skill (6,804 stars, last pushed 3d ago), licensed MIT. It adds 35 tokens to every session and 898 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.