AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Portfolio Rebalance

skill-oh-rid-claude-code-plugin-ib-portfolio-rebalance · by oh-rid

Analyze portfolio drift against target allocation and suggest rebalancing trades. Triggers on "rebalance", "portfolio drift", "allocation check", "am I overweight", "am I underweight", "rebalance my portfolio", "check my allocation", or "portfolio balance".

No reviews yet
0 installs
5 views
0.0% view→install

Install

$ agentstack add skill-oh-rid-claude-code-plugin-ib-portfolio-rebalance

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access Used
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-oh-rid-claude-code-plugin-ib-portfolio-rebalance)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
2mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Portfolio Rebalance? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Portfolio Rebalance — Solo Trader

Compare current IB portfolio allocation to target weights. Show drift. Suggest trades.

Prerequisites

The user must have target allocations defined. If not, ask them to provide targets as a simple table:

Asset class / ticker : target %

If they say "I don't have targets" — help them define simple ones based on what they currently hold. Don't impose a model. This is their portfolio.

Workflow

Step 0: Session check

curl -sk https://localhost:5000/v1/api/tickle

Step 1: Get account and NLV

curl -sk https://localhost:5000/v1/api/portfolio/accounts
curl -sk "https://localhost:5000/v1/api/portfolio/$ACCT/summary"

Extract Net Liquidation Value (NLV) from summary. This is the denominator for all % calculations.

Step 2: Pull all positions

curl -sk "https://localhost:5000/v1/api/portfolio/$ACCT/positions/0"

For each position: ticker, assetClass, mktValue, position, unrealizedPnl.

Step 3: Classify holdings

Group positions by the user's target categories. Common groupings:

  • By asset class: stocks, bonds, cash, options, futures
  • By sector: tech, financials, energy, etc.
  • By ticker (if targets are per-position)
  • By geography: US, international, EM

Use the grouping that matches the user's targets. If targets are per-ticker, use per-ticker. If targets are by asset class, aggregate.

Step 4: Calculate drift

For each category:

current_pct = category_mkt_value / nlv * 100
drift = current_pct - target_pct
dollar_drift = drift / 100 * nlv

ALL arithmetic via python3 -c. No mental math.

Step 5: Cash and buying power

curl -sk "https://localhost:5000/v1/api/portfolio/$ACCT/ledger"

Check cash balance. If rebalancing requires buying, verify cash is available. If not, rebalancing means selling overweight to fund underweight.

Step 6: Generate trade suggestions

For each category outside the rebalancing band (default: +/- 3% drift):

  • Overweight: suggest selling $X to bring to target
  • Underweight: suggest buying $X to bring to target

Prioritize:

  1. Sell overweight positions with losses (rebalance + harvest)
  2. Sell overweight positions with long-term gains (lower tax rate)
  3. Avoid selling positions with large short-term gains if possible

Convert dollar amounts to approximate share counts using current prices.

Step 7: Get current prices for trade sizing

For positions that need trading, get live prices:

curl -sk "https://localhost:5000/v1/api/iserver/marketdata/snapshot?conids={conid1},{conid2}&fields=31,84,85,86"

Field 31 = last price. Use this to calculate share counts.

GOTCHA: First snapshot call often returns empty. Call twice with a 1-second gap.

Output format

One markdown block, max 1 page:

## Portfolio Rebalance — {date}

**NLV**: ${nlv} | **Cash**: ${cash}

### Allocation Drift

| Category | Target | Current | Drift | $ Over/Under |
|----------|--------|---------|-------|-------------|
| Tech     | 30%    | 38%     | +8%   | +$4,200     |
| ...      |        |         |       |             |

### Suggested Trades

| Action | Ticker      | Shares | ~Amount | Reason               |
|--------|-------------|--------|---------|----------------------|
| Sell   | {TECH_STOCK}| 5      | ~$3,100 | Reduce tech overweight |
| Buy    | {BOND_ETF}  | 20     | ~$1,800 | Add bond underweight   |

### Tax notes
- {any positions where selling triggers significant ST gains}

### Summary
{1-2 sentences: what's most out of balance, what to do first}

Save output

Always save the rebalance analysis to the research directory:

mkdir -p portfolio/ib
# Save to: portfolio/ib/{YYYY-MM-DD}_rebalance.md

Self-validation checks

  1. Did the session authenticate? Stop early if not.
  2. Does NLV match the sum of all position mktValues + cash (approximately)? If off by more than 5%, flag it.
  3. Do all percentages sum to ~100%? If not, there's an unclassified bucket — show it.
  4. ALL drift math via python3 -c. Verify: drift % * NLV = dollar drift.
  5. Did we get the user's targets before calculating? Never assume a 60/40 or any model.
  6. Are trade suggestions sized to real share counts at real prices? No "$X of stock" — give share counts.
  7. Is output under 1 page? Summarize if > 15 positions.
  8. Did we avoid placing any orders? Read-only. User executes in TWS.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.