AgentSkillsCN

rebalance

多日周期、流动性受限的投资组合再平衡执行计划器。将 Portfolio123 的目标权重转化为 IBKR 交易工作表,并在交易前进行验证。适用于以下场景:(1) 用户输入 /rebalance 或 /rebalance update;(2) 用户提及 P123、Portfolio123,或 P123 的目标/权重;(3) 用户要求对投资组合进行再平衡,或生成交易订单;(4) 用户需要基于目标权重生成执行计划、执行工作表或交易工作表;(5) 用户提及 IBKR 成交、每日更新,或在持续再平衡过程中记录成交情况;(6) 用户询问 ADV 上限、流动性约束,或在交易情境下关注“先卖后买”的顺序安排;(7) 用户希望生成或审查交易前的验证报告。

SKILL.md
--- frontmatter
name: rebalance
description: Multi-day, liquidity-constrained portfolio rebalance execution planner. Converts Portfolio123 target weights into IBKR trading worksheets with pre-trade verification. Use when the user: (1) says /rebalance or /rebalance update, (2) mentions P123, Portfolio123, or P123 targets/weights, (3) asks to rebalance a portfolio or generate trading orders, (4) needs an execution plan, execution worksheet, or trade worksheet from target weights, (5) mentions IBKR fills, daily update, or recording fills for an ongoing rebalance, (6) asks about ADV caps, liquidity constraints, or sell-before-buy sequencing in a trading context, (7) wants to generate or review a pre-trade verification report.

P123-to-IBKR Rebalance Execution Planner

What This Skill Does

Takes a P123 target portfolio (CSV of ticker + weight) and a portfolio YAML config (IBKR NAV, current holdings, ADV, FX rates) and generates a multi-day execution worksheet with daily trading orders, respecting liquidity constraints.

Workflow

Initial Rebalance (/rebalance)

  1. Ask the user for:
    • Portfolio YAML config path (or help them create one)
    • P123 CSV file path
  2. Run scripts/ingest_p123.py to parse the P123 CSV
  3. Run scripts/compute_execution.py with the parsed targets and YAML config
  4. Run scripts/generate_report.py to produce the pre-trade verification report (.md)
  5. Present the report to the user — they must review ingestion, FX rates, position sizes, and the Day 1 worksheet before proceeding
  6. Save execution state for daily updates

Daily Update (/rebalance update)

  1. Ask the user for:
    • Yesterday's fills (which orders executed, how many shares)
    • Updated prices (or confirm using existing)
    • Updated NAV (if changed)
  2. Run scripts/update_day.py with fills and new prices
  3. Display today's revised worksheet and progress summary

Commands

code
# Initial rebalance
python scripts/ingest_p123.py <p123_csv_path> --output <targets_json_path>
python scripts/compute_execution.py <targets_json_path> <portfolio_yaml_path> --output-dir <output_dir>
python scripts/generate_report.py <output_dir>/execution_state.json <portfolio_yaml_path> --output <output_dir>/report.md

# Daily update
python scripts/update_day.py <state_json_path> --fills <fills_json> --prices <prices_json> --nav <new_nav>

Key Rules

  1. Sells before buys in every worksheet — frees cash for purchases.
  2. Direction is locked on Day 0 — if a position is BUY, it stays BUY for the entire rebalance. Never reverse within a window.
  3. If target is overshot due to favorable price movement, mark that ticker DONE. Do not reverse.
  4. Liquidity caps are per-ticker: min(abs(delta_shares), adv * adv_fraction).
  5. Cash reserve is deducted before computing investable NAV.
  6. P123 weights are normalized to sum to 100% of investable NAV.
  7. Share rounding: toward zero (floor for buys, ceil for sells).

Portfolio YAML Config Format

See references/config_format.md for the full schema. Minimal example:

yaml
portfolio: "AVCO 001"
ibkr_nav: 850000
base_currency: USD
max_execution_days: 3
default_adv_fraction: 0.05
cash_reserve_pct: 0.02
current_holdings:
  ALTN:
    shares: 2000
    price: 19.61
    currency: GBP
    adv: 50000
    adv_fraction: 0.10
fx_rates:
  GBP: 1.27
  SEK: 0.095
  CAD: 0.74
  USD: 1.0