
Tax Loss Harvesting Algorithm: How Sell Signals Work
A tax loss harvesting algorithm is software that compares every taxable tax lot against current market value, realized gains, wash sale windows, holding period, and the investor's tax plan to decide whether to sell a loss lot, wait, or pair the loss with a gain. TaxHarvest runs this algorithmic layer on top of existing brokerage accounts, so the investor keeps the portfolio they already own while the software finds tax-aware sell signals inside it.
The important word is "decide."
Many investors think tax loss harvesting means finding the biggest red number and selling it. That is not enough. A loss can look attractive and still be the wrong trade. A smaller loss can be more valuable because it offsets a gain today. A loss with wash sale risk may be unusable. A gain can be worth realizing if another loss can absorb it.
The algorithm is the part that sorts those choices.
What Is a Tax Loss Harvesting Algorithm?
A tax loss harvesting algorithm is a repeatable decision process for finding useful capital losses in a taxable portfolio.
The raw material is the tax lot. A tax lot is a specific purchase of a security. If you buy 40 shares of an ETF in January and 40 more shares in April, you do not own one tax object. You own two lots. Each lot has its own cost basis, purchase date, holding period, current gain or loss, and wash sale exposure.
This is why tax loss harvesting is hard to do manually. A portfolio with 30 positions can contain hundreds of lots. The brokerage dashboard usually shows a blended position gain or loss. The algorithm looks underneath that summary.
At a high level, a tax loss harvesting algorithm asks six questions:
| Question | What it checks | Why it matters |
|---|---|---|
| Is there a real loss? | Current value versus cost basis | The loss is the tax asset |
| Is the loss large enough? | Expected tax value after trade costs and drift | Not every red lot is worth selling |
| Is there wash sale risk? | Purchases 30 days before or after the sale | A disallowed loss may create no current benefit |
| What income will the loss offset? | Realized gains, expected gains, or carryforward use | The same loss has different value in different years |
| Which lot should be sold? | Holding period, basis, gain character, and account context | Default lot selection can create avoidable tax |
| Should a gain be paired? | Low-basis winners that can be reset with little tax | Losses can raise future cost basis |
The output is a sell signal. In TaxHarvest, that means a specific recommendation tied to specific lots. It is not a vague note that "losses exist." It is closer to: this lot is harvestable, this purchase creates wash sale risk, this gain can be paired, and this is the estimated tax effect.
For the broader product category, see tax loss harvesting software. The algorithm is one part of that system.
What Does a Sell Signal Mean?
A sell signal is not an order to sell. It is a tax-aware recommendation.
That distinction matters. TaxHarvest is software on top of the portfolio. It helps the investor understand the tax opportunity. The investor still owns the account, holds the assets at the brokerage, and chooses whether to act.
A useful sell signal should include the lot, the reason, the tax value, the risk, and the next step.
| Signal field | Plain English meaning |
|---|---|
| Lot identified | The exact purchase lot the software is evaluating |
| Loss amount | The capital loss that would be realized if sold |
| Wash sale status | Whether recent or planned purchases could disallow the loss |
| Tax use | Whether the loss offsets current gains, future gains, or a paired gain |
| Suggested action | Sell now, wait, disable reinvestment, or pair with a gain |
This is why a good algorithm feels practical. It does not ask the investor to become a tax-lot clerk. It turns scattered lot data into a decision the investor can review.
How Does a Tax Loss Harvesting Algorithm Rank Opportunities?
The algorithm ranks opportunities by expected after-tax value, not by the size of the loss alone.
That requires a few layers of analysis.
First, it calculates the harvestable loss. This is the difference between the lot's cost basis and current value.
Second, it estimates the tax rate that could apply to the gain being offset. A loss used against a long-term capital gain may be worth 15%, 20%, or more depending on the investor's tax situation. High-income investors may also owe the 3.8% net investment income tax on investment income. A loss used against short-term gains can be worth more because short-term gains are taxed at ordinary income rates.
Third, it checks whether the loss is actually usable. The IRS wash sale rule can disallow a loss when an investor sells stock or securities at a loss and buys substantially identical stock or securities within 30 days before or after the sale. That check has to include purchases before the sale, not only after it.
Fourth, it compares the loss with other possible uses. A loss can offset a gain already realized this year. It can also be saved as a carryforward. In some cases, the better move is to use the loss immediately to realize a gain in a low-basis position. That is the matched-pair strategy.
The output is a priority score. The score is not visible math for its own sake. It answers a concrete question: which opportunity should the investor look at first?
A Worked Example: Rejecting the Bigger Loss
Suppose an investor has three possible tax moves in July.
The portfolio has:
| Candidate | Lot result | Initial reaction | Hidden issue |
|---|---|---|---|
| ETF lot | -$12,000 | Looks like the obvious harvest | Spouse bought a substantially similar ETF 8 days ago |
| AFRM lot | -$11,200 | Large clean loss | No wash sale risk found |
| NVDA lot | +$11,800 | Low-basis winner | Gain can be paired with AFRM loss |
A manual investor might sell the ETF lot first because the loss is largest. The algorithm should not.
The ETF loss has wash sale risk. If the spouse's purchase is substantially identical, some or all of the loss may be disallowed. The sell signal should either block the trade or ask the investor to wait until the window clears.
The AFRM loss is smaller, but cleaner. It can be used.
Now look at the paired trade:
| Trade | Tax result |
|---|---|
| Harvest AFRM loss | -$11,200 |
| Realize NVDA gain | +$11,800 |
| Net capital gain | $600 |
| Federal rate used | 23.8% |
| Estimated federal tax | $600 x 23.8% = $143 |
If the investor realized the NVDA gain by itself, the estimated federal tax at 23.8% would be:
| NVDA gain | $11,800 |
| Federal rate used | 23.8% |
| Standalone federal tax | $11,800 x 23.8% = $2,808 |
The paired signal changes the decision.
The algorithm rejects the bigger but messy $12,000 ETF loss. It recommends the cleaner AFRM loss because it can help realize the NVDA gain with only about $143 of federal tax instead of about $2,808.
The benefit is not only the $2,665 difference in this year's tax. The investor also resets the NVDA basis higher. That reduces future embedded gain.
This is the point of matched pairs tax loss harvesting and raising cost basis to zero tax. The right sell signal is often a pair, not a single loss sale.
Why the Biggest Loss Is Not Always the Right Signal
The biggest loss is a good place to look. It is not always the right place to act.
There are several reasons.
A loss may be blocked by wash sale risk. If the investor, a spouse, or another account bought substantially identical securities inside the 30-day window, the loss may not be currently deductible.
A loss may create portfolio drift. If selling the lot changes the investor's exposure too much, the trade may not be worth the tax benefit unless there is a good replacement plan.
A loss may be less valuable than a smaller loss that offsets a gain now. A $4,000 loss used against a 37% short-term gain can be worth more than a $6,000 loss that sits unused.
A loss may be better saved for a known future event. If the investor expects to sell a concentrated position later this year, the algorithm may rank a clean carryforward differently than a quick harvest today.
This is why optimal tax lot selection matters. The lot choice changes the tax outcome. FIFO, HIFO, and position-level summaries are shortcuts. Sometimes they work. Sometimes they miss the better move.
How Sell Signals Handle Wash Sale Risk
Wash sale risk is a timing problem, but it becomes an account-visibility problem in real life.
A brokerage can usually see trades inside that brokerage. It may not see a spouse's account, an IRA purchase, an employee stock plan, or an automatic buy in another taxable account.
That matters because the wash sale window looks backward and forward. A purchase 12 days before the loss sale can create a problem. A dividend reinvestment 9 days after the sale can create a problem too.
A tax loss harvesting algorithm should check for at least four things:
| Check | Example | Signal result |
|---|---|---|
| Recent purchases | Same ETF bought 8 days ago | Warn or block |
| Scheduled buys | Automatic investment due next week | Pause before harvesting |
| Dividend reinvestment | Reinvestment buys the same fund | Disable before the sale |
| Cross-account activity | Spouse account buys substantially identical shares | Coordinate household timing |
This is why multi-account tax loss harvesting is a software problem. The useful signal is not just "sell this loser." It is "sell this lot only if these purchases do not break the tax result."
For rule background, see tax loss harvesting rules for 2026.
How Sell Signals Raise Cost Basis Over Time
Most people think a tax loss harvesting algorithm exists to find losses.
That is only the first layer.
A more useful algorithm also finds gains that should be realized because a harvested loss can absorb them. This turns a temporary loss into a permanent improvement in cost basis.
Suppose an investor can raise basis by $18,000 a year using matched gains and harvested losses. The investor does not become richer on the trade date. The portfolio's market value is the same. But the future tax bill is smaller because $18,000 of embedded gain has been removed.
Over 10 years:
| Annual basis raised | $18,000 |
| Years | 10 |
| Total embedded gain reduced | $18,000 x 10 = $180,000 |
| Potential federal tax exposure reduced at 23.8% | $180,000 x 23.8% = $42,840 |
This is why small signals matter. A single $2,000 harvest may not feel dramatic. A decade of well-timed loss harvesting and basis-raising can change how much tax is trapped inside the portfolio.
The investor still owns the portfolio. TaxHarvest is not asking the investor to move into a robo-advisor model or a money manager's portfolio. The algorithm works on top of the existing accounts, as explained in tax loss harvesting software for your existing portfolio.
What Should Investors Expect From TaxHarvest?
Investors should expect clarity.
The software should show which lot is being evaluated. It should explain why the opportunity matters. It should show the estimated tax effect. It should warn when wash sale risk is present. It should explain whether the loss is being used to offset current gains, build a carryforward, or raise basis through a paired gain.
The investor should not have to guess whether a trade is useful.
This is also why a tax loss harvesting algorithm should run continuously. Losses appear and disappear. A lot can be down 9% in April and up 12% by December. If the algorithm only runs at year-end, the opportunity may be gone.
For a calculation-first view of the value, see tax-loss harvesting annual savings estimate. For the broader automation layer, see automated tax loss harvesting without moving accounts. For the hidden lot-level losses that sell signals often find first, see unrealized losses hidden in winners.
The simple version is this: a tax loss harvesting algorithm is a filter for attention. It looks across the portfolio the investor already owns and asks which tax-aware action is worth considering today.
Sometimes the answer is sell.
Sometimes the answer is wait.
Sometimes the answer is pair the loss with a gain and quietly make the future tax bill smaller.