Rebalancing

From JoelLewis/finance_skills · View interactive version

Rebalancing is an AI agent skill from the GitHub repository JoelLewis/finance_skills. Maintain portfolio allocations over time using calendar-based, threshold-based, and tax-efficient rebalancing strategies. Use when the user asks about when to rebalance, rebalancing bands, transaction cost trade-offs, tax-efficient rebalancing, or the rebalancing premium. Also trigger when users men

How to use this skill

Skill file

Rebalancing

Core Concepts

Calendar Rebalancing

Rebalance at fixed time intervals regardless of drift magnitude:

Calendar rebalancing is simple to implement and schedule but may miss large dislocations between dates or trigger unnecessary trades when drift is minimal.

Threshold (Band) Rebalancing

Rebalance when any asset weight drifts beyond a defined tolerance band around its target:

Threshold rebalancing is more responsive to market dislocations and avoids unnecessary trades when markets are calm. However, it requires more frequent monitoring.

Optimal Band Width (Leland Model)

Leland (2000) derived the optimal no-trade band width as a function of transaction costs, risk aversion, and asset variance:

Band width proportional to (3 * transaction_cost / (2 * risk_aversion * variance))^(1/3)

Key intuition:

Rebalancing Premium

Systematic rebalancing generates a "volatility harvesting" or "rebalancing premium" through the buy-low/sell-high mechanism:

This effect is sometimes called Shannon's Demon: in a two-asset portfolio with equal expected returns but independent volatility, the constantly rebalanced portfolio outperforms buy-and-hold. The rebalancing premium is larger when:

Note: The rebalancing premium is not a free lunch — it underperforms in trending markets where winners keep winning.

Transaction Costs

Costs incurred when rebalancing that reduce net returns:

Total implementation cost = commissions + half-spread + market impact + opportunity cost

Tax-Efficient Rebalancing

Strategies to minimize tax impact when rebalancing in taxable accounts:

  1. Use cash flows: Direct new contributions to underweight assets and withdrawals from overweight assets
  2. Redirect dividends and interest: Reinvest income from overweight assets into underweight assets
  3. Rebalance with new contributions: The most tax-efficient method — no selling required
  4. Asset location: Hold tax-inefficient assets (bonds, REITs) in tax-deferred accounts; rebalance these freely
  5. Selective lot identification: When selling, choose tax lots with the highest cost basis (lowest gain) or lots held over one year (long-term capital gains rate)

Coordinating with Tax-Loss Harvesting (TLH)

Rebalancing and TLH should be planned together, not as separate trade lists:

Tax benefit = Realized loss * Marginal tax rate. For the 61-day wash-sale window, the $3,000 ordinary-income offset, replacement selection, and full TLH mechanics, see the tax-loss-harvesting skill.

Rebalancing Across Account Types

When an investor has multiple account types (taxable, IRA, 401k), optimize rebalancing by:

Drift Tolerance Setting

Factors that determine optimal band width:

Cash Flow Rebalancing

Use regular deposits or withdrawals to move toward target weights without explicit rebalancing trades:

Rebalancing Workflow

The concepts above describe the what and why of rebalancing. This section covers the operational how — the step-by-step process an advisor follows to execute a rebalance for a client household.

Step 1: Aggregate Household View

Assemble the complete picture across all accounts (taxable brokerage, Traditional IRA, Roth IRA, 401(k), 529, trust). Calculate the household-level allocation by summing positions across all accounts, not just individual account allocations. Many drift problems are invisible at the account level but obvious at the household level.

Step 2: Asset Location Review

Before proposing trades, document which account types hold which asset classes:

If asset location is suboptimal, the rebalance is an opportunity to improve it — but only if the tax cost of repositioning is justified by the long-term tax savings.

Step 3: Drift Analysis and Trade Generation

For each asset class, calculate drift from target and compare against tolerance bands (from the IPS or firm default):

Step 4: Tax-Impact Estimation

For each proposed sell trade in a taxable account, estimate the tax consequence:

Step 5: Cross-Account Optimization

Minimize total household tax impact by choosing where to execute each trade:

Step 6: Before/After Comparison

Generate a before/after allocation comparison for advisor review and client communication:

This comparison serves as both a decision tool (does the rebalance justify its costs?) and a compliance artifact (documenting the rationale for the trades).

Step 7: Execution and Confirmation

Key Formulas

| Formula | Expression | Use Case |

|---------|-----------|----------|

| Threshold Trigger | |w_actual - w_target| > tolerance | Rebalancing trigger condition |

| Optimal Band Width | band ~ (3tc / (2lambda*sigma^2))^(1/3) | Leland optimal no-trade zone |

| Tax-Loss Benefit | Benefit = Loss * Tax Rate | Value of harvested losses |

| Transaction Cost | TC = commission + spread/2 + impact | Total rebalancing cost |

| Drift | Drift_i = w_actual_i - w_target_i | Weight deviation from target |

| Trade Size | Trade_i = (w_target_i - w_actual_i) * Portfolio Value | Dollar amount to trade |

| Rebalancing Premium | RP ~ (1/2) * Σ w_i * sigma_i^2 - (1/2) * sigma_p^2 | Volatility harvesting estimate |

Worked Examples

Example 1: Threshold Rebalancing — 60/40 Portfolio

Given:

Calculate: Rebalancing trigger and required trades

Solution:

Check drift:

Target dollar amounts:

Required trades:

Proceeds from equity sales fund the bond purchases. In a taxable account, check the cost basis of equity lots being sold to estimate tax impact before executing.

Example 2: Tax-Loss Harvesting Benefit

Given:

Calculate: Tax benefit of harvesting the loss

Solution:

Realized loss from sale: $10,000

Tax benefit calculation:

If the investor had no capital gains to offset:

Implementation:

  1. Sell the losing position for $40,000
  2. Immediately purchase a similar but not substantially identical replacement (e.g., swap a total US stock ETF for an S&P 500 ETF)
  3. Do NOT repurchase the original security within 30 days (wash sale rule)
  4. After 31 days, may swap back to original security if preferred

Note: TLH creates a lower cost basis in the replacement security, so taxes are deferred, not eliminated. However, the time value of the tax deferral and the ability to offset gains at favorable rates makes TLH valuable.

Common Pitfalls

Cross-References

Running the script

Run with uv run scripts/rebalancing.py (the PEP 723 header resolves dependencies automatically) or with python3 scripts/rebalancing.py after pip install numpy scipy. The bare run prints a demo covering drift analysis, threshold checks, trade generation, cash flow rebalancing, transaction costs, tax-aware lot selection, Leland bands, and the rebalancing premium. Pass --verify to assert the demo outputs match this skill's worked examples (prints PASS/FAIL), or --help for an overview of the available classes. The file is primarily meant to be imported as a module (e.g., from rebalancing import DriftAnalyzer, TradeGenerator, TaxAwareLotSelector).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.