14.Tax lots — Schedule D, FIFO/LIFO, wash-sale awareness
Tax-lot tracker computes per-lot cost basis and realized gain/loss at year-end, supports FIFO / LIFO / specific-ID methods, separates short-term from long-term, surfaces wash-sale adjustments, and exports Schedule D-ready CSV / JSON.
Lot vs trade — what's the difference?
The FIFO roll-up that produces trades rows (step 03) is a strategy view: each trade is one idea, opened and closed. The tax-lot tracker is a tax view of the same fills: every share / contract is tracked from acquisition to disposition with a holding period and a cost basis. The two views differ on partial closes:
- Trade view — closing 100 of 300 leaves one open trade with reduced quantity.
- Lot view — closing 100 of 300 pulls 100 shares off the FIFO (or LIFO, etc.) lot queue and emits one disposition row with cost basis = the lot's price + fees.
Method selector
GET /api/tax-lots/{account_id}?year=&method=FIFO|LIFO|SpecificID. Three accounting methods, selectable per query:
- FIFO — oldest lots dispose first. The IRS default for stocks if you don't specify otherwise.
- LIFO — newest lots dispose first. Requires affirmative election with your broker; mostly useful for offsetting high-cost-basis lots in a declining market.
- Specific ID — pick lots by hand. The view shows the FIFO suggestion but lets you reassign dispositions to specific lot IDs (writes to
tax_lot_overrides; export honors the overrides).
Holding period — short vs long term
Long-term capital gains in the US apply when the lot was held > 1 year (specifically: day after acquisition through disposition date inclusive). The tracker computes the holding period per disposition, splits each year's report into short-term and long-term subtotals, and applies the appropriate label.
Options have a wrinkle: deep-in-the-money calls that satisfy the "qualified covered call" rule have their LT eligibility suspended. The tracker flags potential QCC-suspended lots; manual confirmation required.
Wash sales
A wash sale: you sell at a loss and buy a "substantially identical" position within 30 days (before or after). The loss is disallowed for the current tax year and the disallowed amount is added to the basis of the replacement lot.
The tracker:
- Imports broker wash-sale adjustments from year-end 1099-B (most US brokers compute these for you and report them on the 1099).
- Optionally surfaces local-only wash detection — when no 1099 is available (e.g. mid-year reporting), the tracker can flag candidate wash sales against your own execution history. The local detector is a "did the broker miss anything?" sanity check, not a substitute for the 1099.
- Per-account scope — wash rules cross accounts you own (IRA + taxable). The tracker honors per-account scope but flags cross-account candidates; manual confirmation required (the IRS's "substantially identical" test is a judgment call your CPA needs to weigh in on).
Schedule D export
The Tax Lots view has a one-click Export at the top: CSV or JSON. The CSV layout mirrors Form 8949 / Schedule D columns:
Description, Date Acquired, Date Sold, Proceeds, Cost Basis, Wash Sale Adjustment, Code, Adjustment Amount, Gain or Loss, Short-Term/Long-Term
Suitable for direct entry into TurboTax / FreeTaxUSA / your CPA's workpaper. The JSON keeps the same columns plus lot IDs, source-execution IDs, and the method used (FIFO / LIFO / SpecificID), so the export is reproducible — re-running the export with the same method + year + import set yields byte-identical CSV.
Year-end checklist
- Verify all imports are loaded — last-day-of-year CSV from every account.
- Run
POST /api/trades/close-expired-options— closes any options that expired worthless or were assigned. Needed for accurate disposition dates on those positions. - Import broker 1099-B wash-sale adjustments (when they arrive in January / February).
- Open Tax Lots → pick the year → confirm the method matches your broker election.
- Review wash-sale flags — every disallowed loss should match a 1099 entry; mismatches are usually due to a missing import.
- Export Schedule D CSV.
- Hand off to your CPA or tax software; reconcile against the 1099-B totals before filing.
Per-asset-class subtotals (stocks vs options vs futures vs forex) are surfaced so you can reconcile against the corresponding 1099 (1099-B for stocks/options, 1099-B Section 1256 for futures, 1099-MISC for forex if you haven't elected ordinary).