Cost Basis Methods
Supported methods
| Method | ID | IRS Compliant | Notes |
|---|---|---|---|
| First In, First Out | FIFO | ✅ Default | Oldest lots sold first |
| Last In, First Out | LIFO | ⚠️ Specific ID | Must elect Specific ID |
| Highest In, First Out | HIFO | ⚠️ Specific ID | Must elect Specific ID |
| Specific ID | SPECIFIC_ID | ✅ | Manual lot selection |
| Germany FIFO | GERMANY_FIFO | 🇩🇪 | §23 EStG, 1-year holding |
| PMPA | PMPA | 🇨🇦 🇦🇺 | Adjusted Cost Base |
| Total Average | TOTAL_AVERAGE | 🌍 | Average cost basis |
| UK Share Pooling | UK_SHARE_POOLING | 🇬🇧 | Section 104 pool + 30-day rule |
IRS note
The IRS allows FIFO and Specific Identification for crypto (Rev. Rul. 2023-14). LIFO and HIFO are technically Specific ID strategies — you must maintain lot-level records and consistently apply your method.
Usage
import { computeGains, compareAllMethods } from '@dtax/tax-engine';
// Single methodconst result = computeGains(transactions, { method: 'FIFO', taxYear: 2024,});
// Compare all 7 comparable methods (excludes SPECIFIC_ID)const comparison = compareAllMethods(transactions, 2024);comparison.forEach(({ method, totalGain, recommendation }) => { console.log(`${method}: $${totalGain} ${recommendation ? '← recommended' : ''}`);});Result shape
interface GainResult { shortTermGain: number; longTermGain: number; totalGain: number; disposals: Disposal[]; unrealizedGain?: number;}