USE CASE

Tax-loss harvesting for AI agents

2026-11-06 · 5 min read

Tax-loss harvesting sells a position at a loss to offset gains, then holds a replacement so the account keeps its exposure. Abacus Labs finds the lots, picks replacements that do not trigger a wash sale, and returns a checked trade list with the tax effect and the risk change.

The problem

Harvesting is lot arithmetic under a time rule. A loss is disallowed if the person buys the same or a substantially identical security within 30 days before or after the sale, a 61-day window the SEC describes here and the IRS details in Publication 550. The rule applies across accounts, so a dividend reinvested in an IRA can wash a loss taken in the taxable account.

The value is real but front-loaded. AQR's regression over 45 overlapping S&P 500 histories puts the after-tax benefit of a harvested index portfolio near 339 basis points in year one, falling to about 18 basis points a year after year ten with no new cash (AQR, 2022). Chaudhuri, Burnham and Lo find 1.08% a year before costs over 1926 to 2018, and 0.82% once the wash-sale rule is enforced (Financial Analysts Journal, 2020). Leaving losses behind, or washing them, costs most of the benefit.

A language model alone cannot do this. It does not see tax lots, it does not hold 30 days of trade history across accounts, and it cannot choose a replacement that keeps sector and factor exposure without a risk model. Our measurements show frontier models writing trades directly produce a feasible list 10% to 25% of the time.

What the agent asks

USER    Anything worth harvesting before year end?

        agent -> analyze(account)
        agent -> propose(account, "harvest losses, keep exposure", options=3)

AGENT   You have $11,960 of losses in Intel and an energy
        fund. Three ways to take them:

          1   harvest all, replace with ETFs    tax -$11,960   drift 0.3%
          2   harvest Intel only                tax -$8,400    drift 0.1%
          3   harvest all, hold cash 31 days    tax -$11,960   drift 2.1%

USER    Option 1, but don't touch my Apple.

        agent -> propose(option_1, change={ "exclude": ["AAPL"] })
        agent -> commit(option_1b)

AGENT   Done. Four trades. The replacement ETFs are not
        substantially identical to what you sold, and your
        IRA has no purchases inside the window.

What Abacus Labs returns

{
  "status": "ok",

  "trades": [
    { "symbol": "INTC", "side": "sell", "qty": 400, "lots": ["lot_03", "lot_07"] },
    { "symbol": "XLE",  "side": "sell", "qty": 60,  "lots": ["lot_11"] },
    { "symbol": "SCHD", "side": "buy",  "qty": 51 },
    { "symbol": "VDE",  "side": "buy",  "qty": 42 }
  ],

  "tax":  { "realized_gain": 0.00, "realized_loss": -11960.00,
            "short_term": -3100.00, "long_term": -8860.00 },

  "risk": { "before": 0.19, "after": 0.19, "tracking_error_to_target": 0.003 },

  "wash_sale": { "window_days": 61,
                 "accounts_checked": ["acct_demo_1", "ira_demo_1"],
                 "blocked_until": { "INTC": "2026-12-08", "XLE": "2026-12-08" } },

  "checks": { "cash": "pass", "whole_shares": "pass",
              "wash_sale": "pass", "limits": "pass" },

  "explain": "Sells both Intel lots and the energy fund at a loss, replaces them with funds that keep sector exposure within 0.3% of where it was.",
  "certificate": "cert_2026-11-06_41d2"
}

How it works

Abacus Labs reads cost basis per lot and marks every lot with an unrealized loss as a candidate. It scans 30 days of history in every linked account, plus the buys in the plan itself, and blocks any pair that would wash. Replacements come from our point-in-time risk model: a buy qualifies when it keeps sector and factor exposure near the sold position without being substantially identical.

The agent sets the shape with plain constraints: a tracking-error budget, excluded tickers, a minimum loss per lot, whole shares and a cash floor. Explore answers in tens of milliseconds, so the agent can show several options and iterate. Commit re-solves the chosen option with an exact mixed-integer solver and returns a certificate listing the rules that were checked. The same engine runs direct indexing accounts, where harvesting happens name by name against an index.

With a watch on the account, Abacus Labs calls analyze on a schedule and posts to the agent's webhook when a loss crosses a threshold, so harvesting happens when the loss exists rather than in December.

Tax benefit by account age


Year 1     ########################################  339 bp

Year 2     #############                             114 bp

Year 3     ########                                   67 bp

Year 5     ####                                       37 bp

Year 10+   ##                                         18 bp

Source: AQR, The Tax Benefits of Direct Indexing (2022), S&P 500, no new cash, losses offset short-term gains, 1975 to 2019. Simulated, before costs. Not an Abacus Labs result.

Who uses this

Broker agents
A year-end scan across every taxable account, with the person choosing from two or three options inside the chat.
Direct indexing apps
Name-level harvesting against an index with a tracking-error budget, called through the portfolio API or the MCP server.
Advisor tools
Household harvesting where the IRA, the spouse's account and the taxable account are checked together for wash sales.

The Personal plan is free: 3 portfolios and 300 credits a month, no card. Paid plans add portfolios, credits and client use.

Related