RunLocalTools

Crypto & Stock FIFO Capital Gains Calculator — FIFO, LIFO, HIFO, Average Cost

Free FIFO cost-basis calculator that runs in your browser. Import a CSV or Excel trade history, compare FIFO, LIFO, HIFO and average cost, split short and long term by tax year, and export Form 8949-style CSV or PDF. Nothing is uploaded.

What it does

This calculator turns a list of your buys and sells into realized capital gains. You give it a spreadsheet of trades and it matches each sale to the purchases it used up, so you can see the proceeds, cost basis and gain or loss for every sale.

It works for crypto and for stocks. It handles fees, staking or airdrop income, stock splits, transfers between wallets and crypto-to-crypto swaps. It shows the same trades under FIFO, LIFO, HIFO and average cost side by side, so you can see how much the method matters.

How it works

  • Lot matching: Every purchase becomes a lot with a date and a cost. FIFO uses the oldest lot first, LIFO the newest, HIFO the most expensive first, and average cost pools everything per asset. A sale that spans several lots is split into one line per lot, so you can audit every number.
  • Exact arithmetic: Quantities and prices are held as fixed-point integers with 18 decimal places and half-even rounding, not floating point. That keeps 0.1 + 0.2 at exactly 0.3 and stops tiny crypto amounts from leaving rounding dust. When a lot is only partly used, the cost is split so the pieces always add up to the original.
  • Fees: A fee on a buy is added to the cost basis, and a fee on a sale is taken off the proceeds. A fee paid in the same asset (a common exchange practice) reduces the quantity received or increases the quantity disposed.
  • Short vs long term: By default a gain is long-term if you held for more than one calendar year (sold after the first anniversary). You can switch to “more than N days”. The holding period is measured on calendar dates.
  • Tax years: Choose a calendar year or a year starting on Apr 6, Apr 1, Jul 1 or Oct 1, and filter every table, chart and export to one year.
  • Wallets: Match all your lots as one pool per asset, or separately per account/wallet. In per-wallet mode, transfer rows move the oldest lots between wallets with their original date and cost intact.
  • Checks: It flags sales larger than your holdings, duplicate rows, unreadable dates and numbers, missing prices, ambiguous day/month dates, and losses followed by a repurchase within 30 days. The last one is a heads-up only, because it does not adjust any figures.

How to use it

  1. Drop in a CSV, TSV or Excel file, paste rows, or type trades in by hand. Try the sample to see the format.
  2. Check the Column mapping. Headers like Date, Type, Asset, Quantity, Price, Fee and Account are matched automatically, and you can fix any of them by hand.
  3. Choose your method, long-term rule and tax-year start in the side panel.
  4. Read the Summary, browse each sale in Disposals, and check your remaining holdings in Open lots. Type today’s prices there to see unrealized gains.
  5. Export a PDF report, a disposals CSV, a Form 8949-style CSV, a summary CSV, open lots, or a full JSON audit trail.

Exports from more than one exchange? Combine them first with the CSV merger, and if a file has stray whitespace or odd encodings, run it through the CSV cleaner. To look inside a workbook before importing, use the spreadsheet viewer.

What your file needs

Every row needs a date, an asset, a quantity and either a price per unit or a total value. A type column (buy, sell, income, split, transfer) is recommended, though without one a negative quantity is treated as a sale. Optional columns are fee, fee asset, account, to-account for transfers, and an FX-rate column that converts prices and fees into your reporting currency.

Dates are read in ISO, US, day-first, 5 Mar 2024, Unix-timestamp and Excel-serial formats. If a whole column shows which order is used (a 25/03/2024 somewhere), that order is applied; otherwise you are warned and can choose. Numbers such as 1,234.56 and 1.234,56 both work.

Privacy

Your trade history never leaves your device. There is no upload, account or server. The first PDF export, or the first Excel import, downloads a small open-source library and then works offline. If you choose to remember your data, the file is saved in your own browser storage, and Clear saved data removes it.

Limitations

This is a calculator, not tax advice, and tax rules differ by country and change over time.

  • Wash-sale adjustments are not applied. A possible one is flagged, and that’s all.
  • Country-specific pooling and matching rules (for example the UK’s Section 104 and same-day/30-day rules) are not implemented. Average cost is a simple pooled average.
  • Prices, FX rates and exchange data are never fetched. Rows without prices are flagged, and current prices for unrealized gains are typed in by you.
  • Network fees on transfers are ignored, not treated as disposals.
  • The tax estimate uses your own rates and a simple allowance and loss-offset model, and it excludes income.

FAQ

Do I have to use FIFO? Not necessarily, but it depends on where you live and what you hold. Some tax authorities require a specific method or let you choose one, and others mandate their own pooling. That’s why the tool shows all four methods next to each other. Check your local rules before filing.

What happens if I sold more than I bought? The excess is flagged as “oversold”. By default it is given a cost basis of 0 (which overstates the gain), or you can choose to ignore it. The usual cause is a missing purchase, transfer or income row, so look at the Issues tab first.

How are staking rewards and airdrops handled? As income rows, valued at the price on the day you received them. That value becomes the cost basis of the new coins and is shown separately as income received. The income itself is not included in the gains total or the tax estimate.

Can it handle a stock split? Yes. Add a split row with the ratio (2 for a 2-for-1 split, 0.5 for a 1-for-2 reverse split). Open lots are multiplied and their total cost stays the same. Sales before the split date are unaffected.

How do I record a swap from one coin to another? Use the swap helper on the Manual tab. Enter what you gave, what you got and the total value in your reporting currency. It adds the sale and the purchase for you.

Does it work with my exchange’s export? Usually. Columns are matched by common header names rather than a fixed exchange layout, so most exports map automatically, and anything unusual can be fixed in the mapping panel. Exports that put the asset inside a trading pair (like BTCUSDT) need those columns split out first.