Tax loss harvesting

From JoelLewis/finance_skills · View interactive version

Tax loss harvesting is an AI agent skill from the GitHub repository JoelLewis/finance_skills. Execute a complete tax-loss harvesting workflow from candidate identification through post-harvest monitoring. Use when the user asks about finding TLH candidates, gain/loss budgeting, replacement security selection, wash-sale compliance, or harvest execution planning. Also trigger when users mentio

How to use this skill

Skill file

Tax-Loss Harvesting

Core Concepts

Candidate Identification

Scan the portfolio for positions with unrealized losses that meet all three filters:

Gain/Loss Budgeting

Before harvesting, build the year-to-date tax budget:

  1. Realized gains YTD: Sum all short-term and long-term capital gains already realized (including fund distributions).
  2. Planned gain exposure: Estimate gains from pending rebalancing trades, planned liquidations, or expected fund capital gain distributions.
  3. Loss carryforward balance: Check prior-year unused capital loss carryforwards (these offset gains before new harvests do).
  4. Target harvest amount: Target Harvest = (Realized Gains YTD + Planned Gains) - Loss Carryforward + $3,000 ordinary income offset. Harvesting this amount offsets all expected gains AND captures the full $3,000 annual deduction against ordinary income; harvest more to build carryforward for future years.

Replacement Security Selection

The replacement must maintain market exposure without being "substantially identical":

Wash-Sale Compliance

The wash-sale rule (IRC Section 1091) disallows a loss if a substantially identical security is acquired within the 61-day window (30 days before + sale date + 30 days after):

Execution Planning

Translate candidates into an actionable trade list:

Tax Savings Calculation

Quantify the dollar value of each proposed harvest:

Post-Harvest Monitoring

After executing the harvest:

Household-Level Coordination

TLH across a household with multiple accounts requires centralized tracking:

Key Formulas

| Formula | Expression | Use Case |

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

| Tax Benefit | Benefit = Realized_Loss * Applicable_Tax_Rate | Dollar value of a single harvest |

| Net Tax Alpha | Alpha = Tax_Savings - Tracking_Error_Cost - Transaction_Costs | True value after implementation costs |

| Break-Even Holding Period | T_be = Tax_Savings / (Annual_Tracking_Error_Cost + Annual_Expense_Delta) | How long replacement can be held before costs exceed benefit |

| Wash-Sale Adjusted Basis | New_Basis = Replacement_Purchase_Price + Disallowed_Loss | Cost basis when wash sale is triggered |

| Annual TLH Capacity | Capacity = Portfolio_Value * Expected_Volatility * Loss_Capture_Rate | Estimate of harvestable losses per year |

| Target Harvest Amount | Target = Realized_Gains_YTD + Planned_Gains - Loss_Carryforward + 3000 | Harvest needed to offset all gains plus the $3,000 ordinary-income deduction |

Worked Examples

Example 1: Single Position Harvest with Replacement Selection

Given:

Calculate: Tax benefit, net tax alpha, and break-even holding period for the replacement.

Solution:

  1. Unrealized loss: $31,000 - $40,000 = -$9,000 (short-term)
  2. Applicable rate: 35% federal + 9.3% state + 3.8% NIIT = 48.1% combined
  3. Tax benefit: $9,000 * 48.1% = $4,329
  4. Transaction costs: Commission $0 (zero-commission broker) + estimated spread cost 0.05% * $31,000 * 2 trades = $31
  5. Tracking error cost: 1.4% annualized * $31,000 * (30/365) = $36 (for the 30-day minimum hold)
  6. Net tax alpha: $4,329 - $31 - $36 = $4,262
  7. Annual cost of replacement: $31,000 * (0.10% expense + 1.4% tracking error drag estimate of 0.05%) = $46.50/year
  8. Break-even holding period: $4,262 / $46.50 = 91.7 years — the tax benefit overwhelmingly justifies the swap
  9. Action: Sell XYZ Corp (Spec ID, all lots), buy Sector ETF. Set wash-sale window reminder for 31 calendar days. Suspend any XYZ DRIP in all household accounts.

Example 2: Portfolio-Wide TLH Scan with Gain/Loss Budget

Given:

Calculate: Target harvest amount, prioritized trade list, and total tax savings.

Solution:

  1. Gain/loss budget:
  1. Candidate ranking by tax benefit:
  1. Harvest plan: Harvest all three: $14,000 + $6,500 + $2,100 = $22,600 in total losses — $7,400 short of the $30,000 target, so every harvested dollar is consumed offsetting gains and the $3,000 ordinary-income offset is not reached
  1. Coordinate with rebalancing: Position A is also 2% overweight — its TLH sell doubles as a rebalance sell, saving one round-trip trade.

Example 3: Wash-Sale Violation Across Accounts

Given:

Calculate: Wash-sale impact and corrected cost basis.

Solution:

  1. Wash-sale triggered: The 401(k) fund is substantially identical to VTI (same underlying index, same fund family). The purchase on November 20 falls within the 30-day post-sale window (November 5 + 30 = December 5).
  2. Disallowed loss: The wash-sale disallowance is proportional to the replacement shares acquired. If 500 VTI shares were sold and the $750 401(k) purchase acquired the equivalent of approximately 3 shares at $250/share, then 3/500 = 0.6% of the loss is disallowed.
  3. Disallowed amount: $8,000 * (3/500) = $48 disallowed
  4. Remaining allowable loss: $8,000 - $48 = $7,952 — still deductible
  5. Basis adjustment — 401(k) trap: The $48 disallowed loss would normally be added to the replacement security's cost basis. However, because the replacement was purchased inside a 401(k), the cost basis adjustment provides NO future tax benefit (401(k) distributions are taxed as ordinary income regardless of basis). The $48 is permanently lost.
  6. Prevention: Before executing TLH, review the client's 401(k) fund lineup and contribution schedule. If the 401(k) holds a substantially identical fund, either (a) temporarily redirect that 401(k) allocation to a non-identical fund during the wash-sale window, or (b) delay the TLH sale until after the next 401(k) contribution and ensure no contribution occurs for 30 days after.

Common Pitfalls

Cross-References

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.