/tax-loss-harvesting
Tax-loss harvesting opportunity identification, scoring, and planning with wash sale compliance and annual carryforward tracking
$ npx -y skills add agiprolabs/claude-trading-skills --skill tax-loss-harvesting --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/tax-loss-harvesting
Context preview
The summary Claude sees to decide when to auto-load this skill.
Tax-loss harvesting opportunity identification, scoring, and planning with wash sale compliance and annual carryforward tracking
SKILL.md
tax-loss-harvesting.SKILL.mdname: tax-loss-harvesting
description: Tax-loss harvesting opportunity identification, scoring, and planning with wash sale compliance and annual carryforward tracking
license: MIT
metadata:
author: agipro
version: "0.1.0"
category: trading
Tax-Loss Harvesting
Identify, score, and plan tax-loss harvesting (TLH) opportunities across a crypto portfolio. This skill covers unrealized-loss ranking, net-benefit calculation, wash sale compliance, annual loss carryforward tracking, and year-end "use it or lose it" strategies.
> **Disclaimer:** This skill provides informational analysis only. It is NOT tax advice. Tax rules vary by jurisdiction and change frequently. Consult a qualified tax professional before making any tax-related trading decisions.
How Tax-Loss Harvesting Works
Tax-loss harvesting is the practice of intentionally realizing investment losses to offset realized capital gains, thereby reducing your current-year tax liability.
Core Mechanism
1. **Identify** positions with unrealized losses in your portfolio. 2. **Sell** those positions to realize the loss. 3. **Offset** realized gains with the harvested loss, reducing taxable income. 4. **Optionally re-enter** a similar (but not "substantially identical") position to maintain market exposure.
Short-Term vs Long-Term
| Holding Period | Classification | Typical Tax Rate | |---------------|---------------|-----------------| | < 1 year | Short-term capital gain/loss | Ordinary income rate | | >= 1 year | Long-term capital gain/loss | Preferential rate (0-20%) |
Short-term losses first offset short-term gains; long-term losses first offset long-term gains. Remaining net losses cross over to offset the other category.
Annual Loss Deduction Limit
If total net losses exceed total gains, the excess is deductible against ordinary income up to **$3,000 per year** ($1,500 if married filing separately). Any remaining loss carries forward indefinitely to future tax years.
Ranking Unrealized Losses
Not all unrealized losses are equally valuable to harvest. This skill scores each opportunity on four dimensions:
1. Loss Magnitude
Larger dollar losses provide more tax savings. The raw loss is the difference between current market value and cost basis.
unrealized_loss = current_value - cost_basis # negative when loss
tax_savings = abs(unrealized_loss) * marginal_tax_rate
2. Days Until Long-Term Threshold
A position approaching the 1-year holding mark deserves special consideration:
- If close to crossing into long-term territory, harvesting now locks in a **short-term loss** (offsets higher-taxed short-term gains).
- If already long-term, the loss offsets long-term gains (lower tax rate benefit).
days_held = (today - acquisition_date).days
days_to_long_term = max(0, 365 - days_held)
Positions with fewer days remaining until long-term are **more urgent** to evaluate because once they cross 365 days, a short-term loss becomes a less-valuable long-term loss.
3. Wash Sale Risk (Correlation Score)
The IRS wash sale rule prohibits claiming a loss if you buy a "substantially identical" security within 30 days before or after the sale. In crypto, the exact application is evolving, but prudent planning avoids re-entering the same token within the 61-day wash sale window (30 days before + sale day + 30 days after).
**Correlation scoring**: If you hold (or plan to re-enter) a position that is highly correlated with the harvested asset, wash sale risk increases. Score this as:
wash_sale_risk = 1.0 # if same token re-entry planned within 30 days
wash_sale_risk = correlation_coefficient # if correlated substitute held
wash_sale_risk = 0.0 # if no re-entry or uncorrelated substitute
Higher wash sale risk reduces the effective score of the opportunity.
4. Available Gains to Offset
A harvested loss is only immediately useful if there are realized gains to offset. Score opportunities higher when:
- There are matching-type gains (short-term loss vs short-term gain).
- The loss amount does not greatly exceed available gains (diminishing marginal benefit beyond the $3K deduction cap).
offset_efficiency = min(1.0, available_matching_gains / abs(unrealized_loss))
Composite Score
def tlh_score(
unrealized_loss: float,
days_to_long_term: int,
wash_sale_risk: float,
offset_efficiency: float,
weights: dict | None = None,
) -> float:
w = weights or {
"magnitude": 0.35,
"urgency": 0.25,
"wash_safety": 0.20,
"offset_match": 0.20,
}
magnitude_score = min(abs(unrealized_loss) / 10_000, 1.0)
urgency_score = max(0, 1.0 - days_to_long_term / 365)
wash_safety_score = 1.0 - wash_sale_risk
return (
w["magnitude"] * magnitude_score
+ w["urgency"] * urgency_score
+ w["wash_safety"] * wash_safety_score
+ w["offset_match"] * offset_efficiency
)Net Benefit Calculation
Harvesting a loss is not free. Transaction costs (swap fees, slippage, gas) reduce the benefit.
def net_benefit(
unrealized_loss: float,
marginal_tax_rate: float,
transaction_cost: float,
re_entry_cost: float = 0.0,
) -> float:
"""Compute net dollar benefit of harvesting a loss.
Args:
unrealized_loss: Negative number representing the loss.
marginal_tax_rate: Applicable tax rate (0.0 to 1.0).
transaction_cost: Cost to execute the sell (fees + slippage).
re_entry_cost: Cost to re-enter a substitute position.
Returns:
Net benefit in dollars. Positive means harvesting is worthwhile.
"""
tax_savings = abs(unrealized_loss) * marginal_tax_rate
total_costs = transaction_cost + re_entry_cost
return tax_savings - total_costs**Rule of thumb**: Only harvest when `net_benefit > 0` by a meaningful margin. Very small losses are not worth the transaction costs and operational complexity.
Ye
Read more
name: tax-loss-harvesting description: Tax-loss harvesting opportunity identification, scoring, and planning with wash sale compliance and annual carryforward tracking license: MIT metadata: author: agipro version: "0.1.0" category: trading
Tax-Loss Harvesting
Identify, score, and plan tax-loss harvesting (TLH) opportunities across a crypto portfolio. This skill covers unrealized-loss ranking, net-benefit calculation, wash sale compliance, annual loss carryforward tracking, and year-end "use it or lose it" strategies.
> **Disclaimer:** This skill provides informational analysis only. It is NOT tax advice. Tax rules vary by jurisdiction and change frequently. Consult a qualified tax professional before making any tax-related trading decisions.
How Tax-Loss Harvesting Works
Tax-loss harvesting is the practice of intentionally realizing investment losses to offset realized capital gains, thereby reducing your current-year tax liability.
Core Mechanism
1. **Identify** positions with unrealized losses in your portfolio. 2. **Sell** those positions to realize the loss. 3. **Offset** realized gains with the harvested loss, reducing taxable income. 4. **Optionally re-enter** a similar (but not "substantially identical") position to maintain market exposure.
Short-Term vs Long-Term
| Holding Period | Classification | Typical Tax Rate | |---------------|---------------|-----------------| | < 1 year | Short-term capital gain/loss | Ordinary income rate | | >= 1 year | Long-term capital gain/loss | Preferential rate (0-20%) |
Short-term losses first offset short-term gains; long-term losses first offset long-term gains. Remaining net losses cross over to offset the other category.
Annual Loss Deduction Limit
If total net losses exceed total gains, the excess is deductible against ordinary income up to **$3,000 per year** ($1,500 if married filing separately). Any remaining loss carries forward indefinitely to future tax years.
Ranking Unrealized Losses
Not all unrealized losses are equally valuable to harvest. This skill scores each opportunity on four dimensions:
1. Loss Magnitude
Larger dollar losses provide more tax savings. The raw loss is the difference between current market value and cost basis.
unrealized_loss = current_value - cost_basis # negative when loss tax_savings = abs(unrealized_loss) * marginal_tax_rate
2. Days Until Long-Term Threshold
A position approaching the 1-year holding mark deserves special consideration:
- If close to crossing into long-term territory, harvesting now locks in a **short-term loss** (offsets higher-taxed short-term gains).
- If already long-term, the loss offsets long-term gains (lower tax rate benefit).
days_held = (today - acquisition_date).days days_to_long_term = max(0, 365 - days_held)
Positions with fewer days remaining until long-term are **more urgent** to evaluate because once they cross 365 days, a short-term loss becomes a less-valuable long-term loss.
3. Wash Sale Risk (Correlation Score)
The IRS wash sale rule prohibits claiming a loss if you buy a "substantially identical" security within 30 days before or after the sale. In crypto, the exact application is evolving, but prudent planning avoids re-entering the same token within the 61-day wash sale window (30 days before + sale day + 30 days after).
**Correlation scoring**: If you hold (or plan to re-enter) a position that is highly correlated with the harvested asset, wash sale risk increases. Score this as:
wash_sale_risk = 1.0 # if same token re-entry planned within 30 days wash_sale_risk = correlation_coefficient # if correlated substitute held wash_sale_risk = 0.0 # if no re-entry or uncorrelated substitute
Higher wash sale risk reduces the effective score of the opportunity.
4. Available Gains to Offset
A harvested loss is only immediately useful if there are realized gains to offset. Score opportunities higher when:
- There are matching-type gains (short-term loss vs short-term gain).
- The loss amount does not greatly exceed available gains (diminishing marginal benefit beyond the $3K deduction cap).
offset_efficiency = min(1.0, available_matching_gains / abs(unrealized_loss))
Composite Score
def tlh_score(
unrealized_loss: float,
days_to_long_term: int,
wash_sale_risk: float,
offset_efficiency: float,
weights: dict | None = None,
) -> float:
w = weights or {
"magnitude": 0.35,
"urgency": 0.25,
"wash_safety": 0.20,
"offset_match": 0.20,
}
magnitude_score = min(abs(unrealized_loss) / 10_000, 1.0)
urgency_score = max(0, 1.0 - days_to_long_term / 365)
wash_safety_score = 1.0 - wash_sale_risk
return (
w["magnitude"] * magnitude_score
+ w["urgency"] * urgency_score
+ w["wash_safety"] * wash_safety_score
+ w["offset_match"] * offset_efficiency
)Net Benefit Calculation
Harvesting a loss is not free. Transaction costs (swap fees, slippage, gas) reduce the benefit.
def net_benefit(
unrealized_loss: float,
marginal_tax_rate: float,
transaction_cost: float,
re_entry_cost: float = 0.0,
) -> float:
"""Compute net dollar benefit of harvesting a loss.
Args:
unrealized_loss: Negative number representing the loss.
marginal_tax_rate: Applicable tax rate (0.0 to 1.0).
transaction_cost: Cost to execute the sell (fees + slippage).
re_entry_cost: Cost to re-enter a substitute position.
Returns:
Net benefit in dollars. Positive means harvesting is worthwhile.
"""
tax_savings = abs(unrealized_loss) * marginal_tax_rate
total_costs = transaction_cost + re_entry_cost
return tax_savings - total_costs**Rule of thumb**: Only harvest when `net_benefit > 0` by a meaningful margin. Very small losses are not worth the transaction costs and operational complexity.
Ye
A comprehensive collection of 67 ready-to-use trading, DeFi, and quantitative finance Agent Skills. Works with Claude Code, Cursor, Codex, Gemini CLI, and 30+ other tools.
Repo: agiprolabs/claude-trading-skills
Other skills on trading-skills.
- /backtrader
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers, and custom indicators
Open skill - /birdeye-api
Solana token market data via Birdeye — prices, OHLCV, trades, token metadata, security checks, and trader activity
Open skill - /coingecko-api
Broad crypto market data from CoinGecko covering 13,000+ tokens. Global market stats, historical price data going back years, exchange volumes, trending tokens, and category filters. Best for macro analysis and long-term historical data.
Open skill - /cointegration-analysis
Cointegration testing for pairs trading using Engle-Granger, Johansen, and rolling stability analysis
Open skill - /copy-trading
Wallet evaluation, monitoring, and copy-trade strategy design for Solana DEX trading
Open skill - /correlation-analysis
Cross-asset correlation analysis including rolling correlation, hierarchical clustering, tail dependence, and regime-dependent correlation
Open skill

