Tax-Aware Backtesting
Tax-aware backtesting adds account type, tax profile, lot tracking, wash-sale handling, and annual tax settlement to a historical portfolio simulation.
Access: Sign in required (Free or Pro).
Open Portfolio Backtest →What Is Tax-Aware Backtesting?
Standard backtests show pre-tax returns, which can significantly overstate returns. Tax-aware backtesting simulates the real-world impact of taxes on portfolio returns by modeling capital gains realization at every rebalance, IRS wash sale rules, cost basis lot tracking, and annual tax settlement with loss carryforward.
The engine runs a day-by-day simulation that mirrors what would happen in a real taxable brokerage account: every sale triggers gain or loss recognition, each year's net gains are taxed at the appropriate federal and state rates, and unused losses carry forward to offset future gains, exactly as the IRS requires.
Getting Started
To enable tax-aware backtesting:
- (Optionally) Go to Settings and set up your tax profile (filing status, annual income, and state of residence). These determine your marginal tax rates. The initial configuration will load this into the engine, but it is customizable per run.
- Navigate to the Portfolio Backtest page and toggle on "Tax-Aware" mode.
- Configure the tax-specific fields for your simulation.
The configurable fields are:
- Filing Status: Single, Married Filing Jointly, Married Filing Separately, or Head of Household. Determines tax bracket thresholds and the annual loss deduction limit.
- Annual Income: your ordinary income from wages and other sources. Used to determine your marginal federal bracket and whether the Net Investment Income Tax applies.
- State: your state of residence. Used to apply the appropriate state capital gains tax rate. If you enable dual-state mode on the Settings page, you can also set a separate work state for earned-income tax calculations shown on the Settings tax summary. The backtest engine uses your resident state only for investment tax drag.
- Lot Method: how shares are selected when selling: Optimized, FIFO, LIFO, or HIFO.
- Account Type: Taxable, Tax-Deferred (Traditional IRA/401k), or Tax-Free (Roth).
- Portfolio Rebalancing Settings: frequency, mode, threshold, and offset are configured in the main portfolio controls (not inside the tax profile) and are applied consistently to both pre-tax and tax-aware runs.
- Loss Carryforward: any prior capital loss carryforward you want to seed into the simulation (e.g. from real tax returns).
How the Engine Works
The tax-aware engine runs in two layers: an execution layer that emits deterministic trade events from your portfolio settings, and a tool-agnostic tax accounting layer that replays those events with lot tracking, wash sale logic, and annual settlement.
Rebalancing cadence, mode, threshold, and offset come from the portfolio configuration itself. The tax profile controls tax identity (filing status, income, lot method, account type, TLH settings), not rebalance scheduling.
- Price alignment and initial purchase: on the first day of the backtest, the portfolio is invested according to target allocations. Each purchase creates initial tax lots with the acquisition date and cost per share recorded.
- Daily loop: for each trading day, the engine updates portfolio values with current prices and checks whether a rebalance is triggered by drift and/or the selected calendar schedule. In Either mode, either condition is sufficient; in And mode, both conditions must be satisfied. Target-allocation changes from signal strategies trigger an immediate rebalance. When a rebalance occurs, sales generate realized gains or losses and new purchases create new tax lots.
- Year-end settlement: at December 31 of each year (and at the end of the backtest), the engine performs capital gains netting, applies wash sale adjustments, computes the federal and state tax bill, and carries forward any unused losses.
The engine is strategy-agnostic: it works with any strategy that produces target allocations, including buy-and-hold and signal-based strategies. The three-phase cycle (trade execution, wash sale detection, year-end tax netting) repeats for every year in the backtest.
Cost Basis & Lot Tracking
Every purchase of shares creates a distinct tax lot that records the acquisition date, number of shares, and cost per share. When shares are sold, the engine selects which lots to dispose of based on your chosen lot method:
- Optimized: minimizes total tax impact by considering both the gain/loss amount and the holding period of each lot. Lots are sorted into four priority buckets and sold in this order:
- Short-term losses (biggest loss first), harvested first because they offset short-term gains taxed at the highest rates.
- Long-term losses (biggest loss first), harvested next to offset long-term gains, or cross-character to offset short-term gains.
- Long-term gains (smallest gain first): when gains must be realized, prefer long-term since they are taxed at the lower capital gains rate (0-20%).
- Short-term gains (smallest gain first): the most expensive gains from a tax perspective, deferred as long as possible.
- FIFO (First In, First Out): sells the oldest lots first. This is the IRS default method and tends to realize long-term gains sooner.
- LIFO (Last In, First Out): sells the newest lots first. Tends to realize short-term gains or losses.
- HIFO (Highest In, First Out): sells the highest-cost lots first, which minimizes realized gains (or maximizes realized losses).
When a sale does not consume an entire lot, the lot is split proportionally: the sold portion is recognized as a gain or loss, and the remaining portion retains its original acquisition date and cost basis.
The holding period determines the tax character of each gain or loss. Shares held for more than one year (366+ days) qualify as long-term, which is taxed at preferential rates. Shares held for one year or less are short-term and taxed as ordinary income.
Capital Gains Netting (IRS Rules)
At year-end, the engine follows IRS netting rules to determine your taxable gains:
- Separate netting: short-term gains and losses are netted against each other, and long-term gains and losses are netted against each other, producing a net short-term amount and a net long-term amount.
- Cross-character netting: if one character (short-term or long-term) has a net loss, it is used to offset the other character's net gain. For example, a net short-term loss of $5,000 can offset $5,000 of net long-term gains.
- Annual loss deduction: if there is still a net capital loss after cross-character netting, up to $3,000 ($1,500 for Married Filing Separately) can be deducted against ordinary income. This generates a tax benefit at your marginal ordinary income rate.
- Loss carryforward: any remaining net capital loss beyond the $3,000 annual limit carries forward indefinitely to future tax years. Carryforward losses are applied to the same character first (short-term carryforward offsets short-term gains first, then long-term).
Prior-year carryforward losses from the seed value you enter (or accumulated from previous simulation years) are applied at the start of each year's netting process, same character first, before cross-character netting occurs.
Wash Sale Rules
The IRS wash sale rule disallows a capital loss when a "substantially identical" security is repurchased within a 61-day window: 30 days before the sale, the sale date itself, and 30 days after the sale. The engine fully models this:
- Loss disallowance: when a wash sale is triggered, the disallowed loss is not deducted in the current year.
- Basis adjustment: the disallowed loss amount is added to the cost basis of the replacement lot, preserving the economic loss for future recognition.
- Holding period tacking: the holding period of the original (washed) lot is added to the replacement lot's holding period, which can cause what would have been a short-term lot to qualify for long-term treatment.
- Partial wash sales: if you sell 100 shares at a loss but only repurchase 60 replacement shares within the window, only 60 shares' worth of the loss is disallowed. The remaining 40 shares' loss is fully deductible.
- Cross-year wash sales: a wash sale that spans December and January can cause a previously settled prior-year tax bill to be re-calculated, as losses from December may become disallowed based on January purchases.
Tax Rates
The engine applies federal, state, and Net Investment Income Tax rates based on your profile:
- Short-term capital gains: taxed as ordinary income at your marginal federal rate. The 2026 federal brackets range from 10% to 37% depending on taxable income and filing status.
- Long-term capital gains: taxed at preferential rates of 0%, 15%, or 20% depending on your total income. Most taxpayers pay 15%; the 0% rate applies to lower income levels and 20% to the highest earners.
- Net Investment Income Tax (NIIT): an additional 3.8% surtax on investment income for taxpayers with modified adjusted gross income above $200,000 (Single) or $250,000 (Married Filing Jointly). This applies on top of both short-term and long-term rates.
- State capital gains tax: modeled with progressive state income-tax brackets (2025 table) and applied incrementally on top of your ordinary income baseline. Rates still range from 0% in states like Florida, Texas, and Nevada to 13.3% top marginal in California.
- Tax benefit from losses: capital losses that offset ordinary income (up to the $3,000 annual limit) generate a tax benefit calculated at your marginal ordinary income rate, providing a partial refund of the tax drag.
Account Types
The tax treatment depends entirely on the account type you select:
- Taxable Brokerage: the full tax simulation runs, including capital gains on every sale, wash sale tracking, annual netting, and loss carryforward. This is the default and most detailed mode.
- Tax-Deferred (Traditional IRA/401k): no annual tax events occur during the backtest. All gains grow tax-deferred. Upon withdrawal, the entire amount is taxed as ordinary income at your marginal rate. The engine models the deferred tax liability at the end of the simulation.
- Tax-Free (Roth IRA/401k): no tax events at all. Qualified withdrawals are completely tax-free. The after-tax and pre-tax lines will be identical.
Reading the Results
When tax-aware mode is active, the results page expands with several additional visualizations and data points:
- Pre-Tax vs. After-Tax Chart: the solid line shows pre-tax portfolio growth and the dashed line shows after-tax growth. The shaded area between them represents cumulative tax drag (the total wealth lost to taxes over the backtest period).
- Cumulative Tax Paid Chart: a running total of all taxes paid over the backtest period, showing how the tax burden accumulates year by year.
- Tax Summary Cards: at-a-glance figures including total tax paid, total short-term and long-term gains and losses, total wash sale disallowances, and remaining loss carryforward at the end of the simulation.
- Annual Tax Bills Table: a year-by-year breakdown showing short-term tax, long-term tax, NIIT, dividend tax, state tax, loss offset benefit, and total tax for each calendar year.
- After-Tax Metrics in Summary Tab: the standard summary tab gains additional rows: after-tax ending value, after-tax CAGR, tax drag percentage, and total taxes paid over the backtest.
Tips for Tax-Efficient Investing
- Use Optimized lot selection: the default method considers both gain/loss amount and holding period to minimize total tax impact. It harvests losses first, then when gains must be realized it prefers long-term gains (taxed at 0-20%) over short-term gains (taxed as ordinary income at 10-37%). Over a multi-decade backtest, this can result in meaningfully lower cumulative tax drag compared to FIFO or even HIFO.
- Favor longer holding periods: gains on shares held for more than one year qualify for the preferential long-term capital gains rate (0-20%) rather than ordinary income rates (10-37%). Less frequent rebalancing naturally increases holding periods.
- Monitor tax-loss harvesting opportunities: the wash sale and loss data in the results reveal how much harvesting occurred naturally during rebalancing. Significant wash sale amounts suggest the engine detected loss-generating sales followed by repurchases.
- Loss carryforward is a tax asset: accumulated loss carryforward reduces future tax bills dollar for dollar. If your simulation shows a large carryforward balance, that is deferred tax savings waiting to be used.
Limitations & Assumptions
The tax-aware engine models the main sources of tax drag for taxable portfolios: capital gains realization, wash sale disallowances, and the difference between short-term and long-term rates. The engine also makes the following simplifying assumptions:
- Uses 2026 federal tax brackets throughout the entire backtest period. Brackets are not inflation-adjusted across years, which means simulations spanning many decades may overstate taxes for early years (when real income thresholds would have been lower).
- State tax modeling uses progressive brackets for Single and Married Filing Jointly filing statuses. Other filing statuses fall back to top marginal rates. The backtest engine taxes investment income by resident state only; work state affects only the earned-income tax summary shown on the Settings page.
- No Alternative Minimum Tax (AMT) modeling. Taxpayers subject to AMT may see different effective rates than the simulation suggests.
- No local or city taxes (e.g. New York City's additional income tax) are included.
- Dividend events are modeled (including DRIP), but upstream dividend data can be degraded or unavailable for some tickers/date ranges. When this happens, the UI shows a warning and tax drag may be understated.
- Qualified dividend treatment uses asset-level eligibility plus a per-lot holding-period check around the ex-dividend date. The engine still does not model issuer-reported yearly qualified-dividend percentages (for example, an ETF that is 85% qualified and 15% ordinary in a specific tax year).
- Wash sale matching includes conservative substantially-identical groups (for common ETF pairs) plus TLH substitute mappings. It is not a complete legal classifier for every possible ETF/security pair.
- If a simulation ends mid-year, the engine settles taxes at the end date as if that tax year is being finalized for analysis purposes. This is useful for comparability, but real tax filing occurs only at year-end.
- Tax simulation currently assumes a lump-sum initial investment for tax accounting; portfolio cashflow entries (DCA/withdrawals) still affect the pre-tax backtest but are not yet modeled inside the tax accounting engine.