Skip to content

Cost Basis Methods

Supported methods

MethodIDIRS CompliantNotes
First In, First OutFIFO✅ DefaultOldest lots sold first
Last In, First OutLIFO⚠️ Specific IDMust elect Specific ID
Highest In, First OutHIFO⚠️ Specific IDMust elect Specific ID
Specific IDSPECIFIC_IDManual lot selection
Germany FIFOGERMANY_FIFO🇩🇪§23 EStG, 1-year holding
PMPAPMPA🇨🇦 🇦🇺Adjusted Cost Base
Total AverageTOTAL_AVERAGE🌍Average cost basis
UK Share PoolingUK_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 method
const 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;
}