Sub topic 12
Tax Lots and Cost-Basis Records
This chapter assumes you know what a share is, how to compute average cost per share (covered earlier in this tutorial), and how recurring purchases create many small buys. Tax rules differ by country and change over time, so the examples use US-style concepts such as capital gains and wash sales. Check your own tax authority's rules. This is education, not tax advice.
Why recurring purchases create a record-keeping task
Each recurring purchase is a separate event with its own date and price. A year of weekly $50 buys gives you 52 purchases. Add dividend reinvestment and the count grows. When you sell, the tax result depends on which of those purchases you sold, not on the average.
Three terms carry most of the chapter:
- Cost basis is what you paid for shares, including any commissions. It is the starting point for measuring gain or loss.
- Tax lot is one purchase, with its own acquisition date, share count, and cost per share. A fractional purchase of 0.166666 shares is a full tax lot.
- Realized gain or loss is the sale proceeds minus the basis of the lots you sold. It is only realized when you sell. Unrealized gains and losses on shares you still hold usually are not taxed.
What a lot looks like
Take the five purchases from the earlier averaging example. You invested $100 each time at prices of $50, $40, $25, $40, and $50.
| Lot | Date acquired | Shares | Price | Basis |
|---|---|---|---|---|
| 1 | 2026-01-15 | 2.0 | $50 | $100 |
| 2 | 2026-02-15 | 2.5 | $40 | $100 |
| 3 | 2026-03-15 | 4.0 | $25 | $100 |
| 4 | 2026-04-15 | 2.5 | $40 | $100 |
| 5 | 2026-05-15 | 2.0 | $50 | $100 |
The total is 13 shares and $500 of basis, so the average cost is about $38.46. That average is a summary. A broker's tax records normally keep the five lots separate.
Holding period
The date of each lot matters because many tax systems tax short-term gains differently from long-term gains. In the US, a lot held for more than one year before the sale is long-term. Otherwise it is short-term. Short-term gains are generally taxed at ordinary income rates, and long-term gains at lower rates for most people.
When you sell part of a position, you may sell lots with different holding periods. The same sale can produce both a long-term and a short-term result.
Choosing which lots to sell
If you sell 5 of your 13 shares, something must decide which lots those 5 shares come from. Common methods:
| Method | Rule | Typical effect |
|---|---|---|
| FIFO (first in, first out) | Sell the oldest lots first | Often the default. Tends to use older, longer-held lots |
| Specific identification | You pick the lots at the time of sale | Most control over gain, loss, and holding period |
| Highest cost first | Sell lots with the highest price first | Tends to minimize the realized gain |
| Average cost | Every share gets the same average basis | Allowed in the US for mutual funds and some other cases. Not for ordinary stock lots unless the broker offers it for that product |
Rules on which methods are allowed, and on how and when you must choose, vary by country and by product. In the US, specific identification generally has to be communicated to the broker at or before the sale. Many brokers use a default method unless you set another one in your account settings. Changing the default usually does not rewrite past sales.
Worked example: the same sale, two methods
Suppose on 2027-02-01 you sell 5 shares at $60. This script computes the result under FIFO and under highest-cost-first. It splits each gain into long-term and short-term using the one-year rule.
from datetime import date
from decimal import Decimal as D
lots = [
{"date": date(2026, 1, 15), "shares": D("2.0"), "price": D("50")},
{"date": date(2026, 2, 15), "shares": D("2.5"), "price": D("40")},
{"date": date(2026, 3, 15), "shares": D("4.0"), "price": D("25")},
{"date": date(2026, 4, 15), "shares": D("2.5"), "price": D("40")},
{"date": date(2026, 5, 15), "shares": D("2.0"), "price": D("50")},
]
def sell(lots, qty, price, sale_date, order_key=None):
ordered = sorted(lots, key=order_key) if order_key else list(lots)
remaining = D(qty)
basis = long_gain = short_gain = D(0)
for lot in ordered:
if remaining == 0:
break
take = min(lot["shares"], remaining)
remaining -= take
gain = take * (price - lot["price"])
basis += take * lot["price"]
anniversary = lot["date"].replace(year=lot["date"].year + 1)
if sale_date > anniversary:
long_gain += gain
else:
short_gain += gain
if remaining:
raise ValueError("not enough shares")
return basis, long_gain, short_gain
sale_date = date(2027, 2, 1)
methods = {
"FIFO": None,
"Highest cost": lambda lot: -lot["price"],
}
for name, key in methods.items():
basis, long_g, short_g = sell(lots, "5", D("60"), sale_date, key)
total = long_g + short_g
print(f"{name}: basis {basis:.2f} gain {total:.2f} "
f"long {long_g:.2f} short {short_g:.2f}")
# FIFO: basis 212.50 gain 87.50 long 20.00 short 67.50
# Highest cost: basis 240.00 gain 60.00 long 20.00 short 40.00Both runs sell the same 5 shares for $300. FIFO reports an $87.50 gain, of which $67.50 is short-term. Highest-cost-first reports a $60 gain. Using the average cost of $38.46 per share would give a basis of about $192.31 and a gain of about $107.69. The choice of method changes the reported gain by tens of dollars even on this small position. Note that the method changes timing, not the total economics over the life of the investment. Lower basis sold now means higher basis remains for later sales.
Fractional shares and basis precision
Fractional purchases make the basis arithmetic messier. A $50 order at $300 per share fills 0.166666 shares if the broker truncates, as in the earlier rounding example. The basis should reflect what you actually paid for the shares received. Brokers differ in how they handle the leftover fraction of a cent, so small rounding differences between your own spreadsheet and the broker's form are normal. Treat the broker's tax form as the reference unless you find a real error.
Dividend reinvestment creates lots
Each reinvested dividend buys shares, and each of those purchases is a new lot with its own date and price. In many tax systems, a dividend you reinvest is still taxable income for that year. Its amount also becomes the basis of the new shares. If you ignore this, you can count the same money twice: once as dividend income and again as a gain when you sell. Keep the reinvestment confirmations or rely on the broker's lot-level records.
The wash sale rule and automatic buys
A wash sale (US term) happens when you sell at a loss and buy the same or a substantially identical security within 30 days before or after the sale. The loss is then disallowed for now and added to the basis of the replacement shares.
Recurring investing makes this easy to trigger by accident. Suppose you sell a position at a loss to harvest the loss, but your automatic weekly buy keeps running. The next buy lands inside the 30-day window and part of your loss is deferred. Some regimes also apply the rule across accounts, including retirement accounts. If you sell at a loss, check your schedules and pause the plan or switch to a different, non-identical fund if that fits your goals.
Transfers, mergers, and gaps in records
Cost basis is easiest to lose when shares move. Points to watch:
- Broker transfers. Basis normally travels with a transfer, but not always completely. Some brokers cannot move fractional shares and sell them instead. That sale is a taxable event, usually small.
- Older holdings. Brokers report basis to tax authorities for shares bought after certain dates. Older shares may have no basis on the form. Then you must supply it.
- Corporate actions. Splits, mergers, and spin-offs change share counts and basis per share. Total basis is usually preserved or reallocated, so keep the company notices.
- Gifted or inherited shares. Special basis rules apply, which differ from a purchase.
Practical routine: once a year, download the tax documents and the full transaction history. Compare total shares and total basis against your own totals. Save the files somewhere you control, because brokers do not keep history forever.
Common errors
- Using the average price as the basis for a partial sale of stock lots when the broker tracks lots individually.
- Forgetting that reinvested dividends are separate purchases.
- Assuming the broker's default method is the best one for your situation without checking it.
- Selling "recent" shares expecting long-term treatment, when the sale actually draws on the oldest lots under FIFO, or the reverse.
- Triggering a wash sale with a scheduled buy.
- Not recording basis for shares moved between brokers.
Exercise
You hold three lots: 2 shares bought at $10, 2 shares bought at $20, and 2 shares bought at $30, all more than one year ago. You sell 3 shares at $25. Compute the gain under FIFO and under highest-cost-first.
Show answer
FIFO sells the 2 shares at $10 and 1 share at $20. The basis is 20 + 20 = $40. The proceeds are 3 x 25 = $75, so the gain is $35. Highest-cost-first sells the 2 shares at $30 and 1 share at $20. The basis is 60 + 20 = $80, so the result is a loss of $5. All lots are long-term in both cases.
Exercise
Your plan buys $100 of a fund on the 1st of every month. On June 10 you sell all your shares of that fund at a loss. Why might that loss not be fully usable, and what can you do?
Show answer
The July 1 purchase falls within 30 days after the sale, so it is a repurchase of the same security. Under a wash sale rule the loss on the matching shares is disallowed for now and added to the basis of the new shares. To avoid this, pause the recurring buy (and dividend reinvestment) for the window, or buy a different, non-identical fund, after checking your local rules.
Exercise
A dividend of $12 is reinvested at $40 per share. How many shares are added, what basis does the new lot have, and why does this matter at sale time?
Show answer
The purchase adds 12 / 40 = 0.3 shares. The lot's basis is $12 and its acquisition date is the reinvestment date. If you leave that basis out, you would overstate the gain when you sell those shares, and you would effectively be taxed twice on the same money.