A Practical Way to Use AI When Trading a Taxable Portfolio
How to combine investment objectives, taxes, and trade execution
Abstract: This article examines how AI can help investors execute portfolio decisions more efficiently by combining investment objectives, tax consequences, wash-sale considerations, and current market conditions. The central principle is simple: AI should improve execution, not replace investment judgment.
Much of the discussion about AI and investing focuses on whether artificial intelligence can identify the next winning stock. A more practical use may be much less ambitious: helping investors execute portfolio decisions they already have reason to make.
Investors sell securities for many reasons. They may want to reduce their exposure to stocks because their portfolio has become more aggressive than intended or because they believe the market is unusually expensive. They may want to replace an investment they regard as relatively weak with one they believe has better prospects. Or there may be no judgment about the investment at all: an investor may simply need cash for a down payment on a house, tuition, a major purchase, or a larger precautionary reserve.
In each case, the investor has a reason to sell. That investment or financial objective should come first. Tax considerations should help determine how to execute the decision, not determine whether the decision should be made.
Trading in a taxable brokerage account can nevertheless create substantially different tax consequences depending on what is sold. Net short-term gains are generally taxed at ordinary-income rates, while qualifying net long-term gains may receive preferential rates. Capital losses offset capital gains, and only after losses exceed gains can up to $3,000 of the remaining net capital loss generally be deducted against ordinary income, with additional losses carried forward.
The tax value of a loss can therefore depend not merely on its size but also on what it offsets. A short-term loss used against a short-term gain can be particularly valuable because net short-term gains are taxed at ordinary-income rates; the immediate tax value may be lower if that loss instead offsets a preferentially taxed long-term gain.
Losses also require another check. Under the federal wash-sale rule, a loss can be disallowed when substantially identical securities are acquired during the period beginning 30 days before and ending 30 days after the loss sale.
The tax value of a loss should never be confused with the investment value of selling the security. The tax benefit from realizing a loss is limited, while the opportunity cost of abandoning an investment that subsequently recovers can be much larger. A loss should therefore generally be harvested when selling is already consistent with the investor’s objectives, or when the investor can maintain the desired economic exposure with an acceptable alternative.
Once the objective has been established, however, taxes and execution can matter considerably. An investor may have several securities that could be sold, multiple tax lots, some positions with gains and others with losses, and both short- and long-term holdings.
This leads to the practical question examined here:
Regardless of why an investor wants or needs to trade, can artificial intelligence help identify a more economically and tax-efficient way to carry out those transactions?
The answer appears to be yes—but only if AI is given the right information and the investor keeps the priorities straight.
What Information Does AI Need?
The first requirement is the investor’s year-to-date tax position. AI should know realized short-term gains and losses and realized long-term gains and losses from all taxable brokerage accounts reported on the same tax return, including both spouses’ accounts when filing jointly, along with any capital-loss carryforwards from previous years.
The second important input is the portfolio at the tax-lot level. For securities that might be sold, AI should know the number of shares with short- and long-term gains or losses, the amount of each unrealized gain or loss, and the relevant purchase dates.
The capital-gain and capital-loss calculations discussed here concern primarily taxable brokerage accounts, rather than investments held inside tax-advantaged retirement accounts.
If losses are being considered, AI also needs enough recent transaction information to identify possible wash sales. That can require looking beyond the brokerage account in which the security will be sold to other relevant household accounts, including a spouse’s accounts. AI cannot identify transactions it has never been shown.
Wash-sale analysis is another task AI can help automate. Instead of manually checking transaction histories across several accounts, the investor can provide those records and ask AI to flag purchases that fall inside the wash-sale window.
For ETFs, investors can often preserve broadly similar market exposure by buying a close substitute—a “twin” fund—but the tax rule turns on whether the replacement is substantially identical, so similarity alone does not automatically make the trade safe from the wash-sale rule.
Finally, AI needs to know what the investor is trying to accomplish—whether that means reducing stock exposure, replacing weaker investments with stronger ones, or simply raising cash. With that objective defined, AI can compare alternative sales and identify the combination that best preserves the desired portfolio while avoiding unnecessary taxes.
For an investor who simply needs to raise cash, the central question might be:
Which combination raises the required cash, moves the remaining portfolio closest to my desired allocation, and produces an acceptable tax result?
A Hypothetical Investor Example
Consider an investor who had accumulated roughly 50 positions, including several very small holdings in companies he did not know particularly well. His goal was to simplify the portfolio toward perhaps 20 positions and gradually shift away from small individual-company bets toward ETFs and a smaller number of large companies whose businesses and fundamentals he understood better.
Several positions he wanted to eliminate were trading at losses. The investment objective was already clear: simplify the portfolio and reduce exposure to companies about which the investor had relatively little conviction. But he did not want to sell the losing positions indiscriminately. If possible, he wanted to exit them at reasonably favorable prices while taking the tax consequences into account.
This is where AI became useful. Instead of evaluating a single trade, it could help screen roughly 50 holdings simultaneously for portfolio desirability, tax status, and current market performance. Among the positions targeted for elimination, AI could identify securities that remained below their purchase prices but were nevertheless having relatively good trading days, potentially providing better opportunities to exit.
Four unwanted positions were sold as part of the portfolio simplification. The proceeds were then redeployed into Berkshire Hathaway, Visa, and Apple, larger companies the investor was more comfortable owning. Approximately half of the new purchases were executed at market prices and the remainder through limit orders.
AI therefore contributed to more than the tax calculation. It helped sort the existing holdings for possible sales, identify losing positions that were performing relatively well that day, and use current market information to identify reasonable entry prices for the securities being added.
The tax loss considerations did not create the investment strategy. The investor had already decided to simplify the portfolio, reduce holdings in companies he knew less well, and concentrate more heavily on ETFs and larger companies he understood better. Tax information and current market prices helped determine how to execute that strategy more efficiently.
This illustrates the broader role for AI: it can combine an investor’s desired portfolio changes, tax position, and current market conditions to help answer not simply what should be sold, but which of the contemplated transactions make the most sense to execute now and how should the proceeds be redeployed?
This discussion is for educational purposes and is not individualized tax or investment advice. Tax circumstances vary, and complicated transactions or uncertain wash-sale situations may warrant review by a tax professional.
Author’s Note: I write Economic and Political Insights, a multi-topic blog covering investing and personal finance, economic policy, health care and retirement policy, and politics and elections. Readers interested in the investment research may also want to see When Similar Funds Produce Different Results, which examines how supposedly similar growth ETFs can produce materially different portfolio results; The 10% International Diversification Trap, which tests whether a small international allocation actually reduced portfolio risk; and Can Investors Find the Few Stocks That Create Most Market Wealth?, which examines the case for individual-stock selection against Hendrik Bessembinder’s evidence on the extraordinary concentration of long-run stock-market wealth creation.


One of the stranger features of the wash-sale rule is how poorly the information can line up with the tax reporting system.
Suppose an investor sells a stock at a loss at Broker A and buys substantially identical shares within 30 days at Broker B. Both brokers may report their own transactions to the IRS, but the brokers generally are not responsible for matching transactions across separate accounts. The taxpayer still has to identify the wash sale and report the loss correctly.
It gets stranger. IRS Revenue Ruling 2008-5 says that a loss in a taxable account can also be disallowed if substantially identical securities are purchased in the investor’s **IRA or Roth IRA** during the wash-sale period—even though the IRA transaction is not naturally paired with the taxable sale on Form 1099-B.
This seems like an ideal job for AI. Give it transaction histories from the relevant brokerage and retirement accounts and let it do the tedious cross-account matching, flagging possible wash sales before the tax return is prepared. The taxpayer or accountant can then deal with the genuinely ambiguous cases.
The IRS rule is here: [Revenue Ruling 2008-5](https://www.irs.gov/pub/irs-drop/rr-08-05.pdf).
I understand why wash-sale rules exist. But expecting ordinary investors to manually reconcile taxable accounts at multiple brokers with transactions buried inside IRAs strikes me as, to use the technical Yiddish term, **meshuggeneh**.