---
name: trader-rebalance
description: >-
  Rebalancer. Brings the portfolio back to its target weights when it drifts: values every holding at current prices, works out each stock's drift from its target in percentage points, trades only the stocks outside a band (default 5 points), keeps the cash buffer and the per-stock cap, skips tiny trades, lists sells before buys, and writes the trades to trader/orders.json as proposals. Use when the user says "rebalance", "my portfolio drifted", "bring it back to the targets", "I added money", "the new 13F changed the weights", "am I overweight", or on a schedule (monthly or quarterly) after /trader-copycat updates the targets.
argument-hint: "[band in points]"
title: trader-rebalance
canonical_url: https://skilld.dev/gh/jakeschincariol/trader-skill/trader-rebalance
last_updated: 2026-10-31T12:30:53.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [rebalance.py](https://skilld.dev/api/skills-raw/jakeschincariol/trader-skill/trader-rebalance/rebalance.py).
>
> If the user asked to install this Skill, run `npx skilld install jakeschincariol/trader-skill/trader-rebalance`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/trader-rebalance`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jakeschincariol/trader-skill/trader-rebalance) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/trader-rebalance`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/trader-rebalance --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/trader-rebalance --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# trader-rebalance

The Rebalancer keeps the portfolio looking like the plan. Prices move, new
money arrives and a new 13F changes the weights; this skill finds the stocks
that drifted too far and proposes the trades that bring them back. It writes
proposals only: trader-risk checks them and trader-broker asks the user yes
or no for each one.

`${CLAUDE_SKILL_DIR}` below is this skill's folder (where this SKILL.md lives).

```bash
python3 "${CLAUDE_SKILL_DIR}/rebalance.py"                    # the drift table, no files written
python3 "${CLAUDE_SKILL_DIR}/rebalance.py" --band 5 --write   # proposals -> trader/orders.json
python3 "${CLAUDE_SKILL_DIR}/rebalance.py" --sell-untracked   # also sell holdings not in the targets
python3 "${CLAUDE_SKILL_DIR}/rebalance.py" --json
```

## What it reads and writes

| file | what |
| --- | --- |
| `trader/portfolio.json` | cash and positions (shares); same shape as trader-tax's `portfolio.example.json` |
| `trader/prices.json` | a price for every holding and every target (trader-alerts writes it) |
| `trader/targets.json` | the target weights (trader-copycat writes it) |
| `trader/config.json` | cash buffer, cap, min and max order, `rebalance_band_pct` |
| `trader/orders.json` | the proposals it writes with `--write`, sells first |

## How it decides

- **Account value** = cash + every holding at its price.
- **Targets**: the weights renormalised over the stock sleeve (account minus
  the cash buffer), with no stock above `max_position_pct` of the account. The
  excess is shared out, the same way trader-budget does it, so a capped stock
  is not bought back over the cap every month.
- **Drift** = current percent of the account minus target percent.
- **Band**: only stocks drifting MORE than the band trade (default 5 points).
  A trade takes the stock all the way back to its target. A small band means
  more trades; a wide band means fewer.
- **Sells first**, then buys. Buys only spend cash above the buffer; if there
  is not enough, all buys are scaled down by the same share.
- Trades under `min_order_usd` are skipped. A trade over `max_order_usd` is
  cut to the max with a note to run again after it fills.
- **Untracked** holdings (not in the targets) are left alone and listed,
  unless the user asks to sell them with `--sell-untracked`.

## Steps

1. Refresh prices: trader-alerts `alerts.py quote --holdings --write`.
2. Run `rebalance.py` and show the drift table in plain words: which stocks
   are over or under, by how many points, and what it would trade.
3. Before any sell, run trader-tax (`lots.py sell TICKER SHARES`) and show
   what the sale would realize. Selling a winner can mean a tax bill.
4. If the user wants the trades: `rebalance.py --write`, then `/trader-risk`,
   then `/trader-broker`, one yes per order.

## Example: the reel's portfolio

The copy portfolio bought on 2026-10-13 (AAPL $1,250 capped, AXP $1,119,
GOOGL $823, KO $708, BAC $600, $500 cash), valued at that day's closes, sits
on its targets: every drift is under 0.1 point, so `rebalance.py` says
"Nothing is outside the band" and exits 1. If the user adds $2,000 of cash,
the account is $7,000 and the cap becomes $1,750. AAPL is now 7.1 points under
its target and AXP 6.4, both outside the 5-point band, so it proposes buying
$499 of AAPL and $446 of AXP. GOOGL, KO and BAC are under target too, but
inside the band, so they wait. Add $5,000 instead and all five are outside
the band: five buys that leave the $1,000 buffer in cash.

## What it never does

It never places an order, never trades inside the band to chase small
differences, never sells holdings outside the targets unless asked, and
never says a rebalance will improve returns.

## Safety

- Education and tooling, not financial advice. A rebalance follows the user's own targets, not a forecast.
- Paper trading by default (`"paper": true`). Going live is the user's own decision, in their own config.
- Nothing in this pack places an order except trader-broker, and only when all three hold: trader-risk
  passed that exact order today, the user typed an explicit yes for that one order in the chat, and the
  user clicked Allow once on Claude's own card because the order tool is set to "Needs approval"
  (Customize > Connectors > tool permissions). Never set an order tool to "Always allow".
- No options, margin, short selling or leverage unless the config allows it and the user confirms.
- Broker keys live in environment variables or the Claude Desktop config, never in the chat.
