Install
$ agentstack add skill-oh-rid-claude-code-plugin-ib-portfolio-rebalance ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo 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.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
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 →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:
- Sell overweight positions with losses (rebalance + harvest)
- Sell overweight positions with long-term gains (lower tax rate)
- 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
- Did the session authenticate? Stop early if not.
- Does NLV match the sum of all position mktValues + cash (approximately)? If off by more than 5%, flag it.
- Do all percentages sum to ~100%? If not, there's an unclassified bucket — show it.
- ALL drift math via
python3 -c. Verify: drift % * NLV = dollar drift. - Did we get the user's targets before calculating? Never assume a 60/40 or any model.
- Are trade suggestions sized to real share counts at real prices? No "$X of stock" — give share counts.
- Is output under 1 page? Summarize if > 15 positions.
- 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.
- Author: oh-rid
- Source: oh-rid/claude-code-plugin-ib
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.