DeGiro Performance Tracker

Realized vs unrealized gains: FIFO cost basis explained

By the developer of this tracker (about) · Updated 9 October 2026

Sell part of a position and the gain splits in two: the part you've locked in and the part still riding on the price. Which shares you count as sold decides how big each part is.

Two kinds of gain

An unrealized gain is the difference between what a position you still hold is worth today and what it cost you. It exists only on paper: it moves with every price change, and it can disappear without you doing anything. A realized gain is what you actually made on shares you've sold — what the sale brought in, minus what those particular shares had cost. Once realized, it doesn't change any more.

Both depend on one number that isn't printed anywhere in a brokerage export: the cost basis, what the shares in question cost. When every share of a position was bought in one go, that's simple. When the position was built from several buys at different prices and then partly sold, it isn't, because you have to decide which shares the sale used up.

FIFO: first in, first out

The tracker answers that with FIFO — first in, first out. Every buy is kept as a separate lot, with its own quantity and its own cost per share. A sale uses up the oldest lot first, then the next oldest, and so on until the sold quantity is covered; a lot that is only partly used up keeps the rest of its shares at the same cost per share.

Lots are kept per ISIN, the instrument's international identifier, not per ticker or per exchange. The same share bought on two different exchanges has one ISIN, so it's one pool of lots, and a sale on either exchange draws from the oldest of them.

A lot's cost comes from the trade's total in Transactions.csv, which includes the transaction fee, so a lot of 10 shares bought at €50 with a €2 fee costs €502, or €50.20 a share. A sale's proceeds are likewise its total, after the fee on the way out.

A worked example

All the numbers here are round and made up, including a hypothetical €2 fee per trade. In January you buy 10 shares at €50: a total of €502, so €50.20 a share. In June you buy another 10 at €60: €602, or €60.20 a share. You now hold 20 shares that cost €1,104 in all.

In November you sell 15 shares at €70. That's €1,050, minus the €2 fee: €1,048 of proceeds. FIFO uses up the January lot first — all 10 shares, €502 — and then 5 shares from the June lot, 5 × €60.20 = €301. The cost basis of the sale is €803, and the realized gain is €1,048 − €803 = €245.

What's left is 5 shares from the June lot, with a cost basis of 5 × €60.20 = €301. If the latest price is €65, they're worth €325, an unrealized gain of €24 — about 8% on their cost.

Why the method changes the split, but not the total

Run the same trades with an average-cost method instead and the split changes. Twenty shares for €1,104 is €55.20 a share on average; the 15 sold cost €828 on that basis, so the realized gain is €220, and the 5 left have a cost basis of €276, an unrealized gain of €49.

Add the two up either way and you get the same €269: €245 + €24, or €220 + €49. And that's simply what happened — €1,048 received plus €325 still held, minus €1,104 paid. The cost method doesn't change how much you've made on the position. It changes how much of it counts as already made and how much is still at the mercy of the price — which matters most when realized gains are what something like a tax return is based on.

FIFO isn't the only method in use, and the one your tax authority requires may well be different. The tracker's realized figures are a description of your trading under FIFO, not a tax calculation; check the rules that apply to you before using them for one.

Where these figures appear in the tracker

The Positions tab shows each open position with its quantity, its average cost per share and its total cost basis — both taken from the lots still open, so after a partial sale they reflect only the shares you still hold — next to the latest price fetched for its ticker, its market value and its unrealized gain, in money and as a percentage of cost. A position with no price available has no market value and so no unrealized figure.

Below that, the realized section lists every sale, one row each, with the quantity sold, the proceeds, the FIFO cost basis of the shares it used up and the realized gain or loss, and adds them up. Each sale stands on its own; a position that has been partly sold appears in both places.

Losses work exactly the same way in the other direction. Sell below what the oldest lots cost and the sale's realized figure is negative; hold a position that has fallen and its unrealized figure is. A position sold off completely leaves the open positions list altogether, and from then on lives only in the realized section — so a list of open positions that all show gains says nothing about the ones that were sold at a loss along the way.

Two things neither figure includes

Dividends aren't part of either. A share that has paid out a lot in dividends can show a small unrealized gain while having earned its holder a good deal; dividends are counted separately, on the Income & Fees tab. And neither figure is a return: they're amounts of money per position, with no notion of how long the money was invested or of when it arrived. For a return on the account as a whole, see what return your portfolio actually made.

One caveat about history: FIFO needs every buy. A sale of shares bought before the start of your Transactions.csv export has no lot to draw from, and the tracker treats the unmatched shares as if they had cost nothing — so that sale's realized gain comes out too high. Exporting from the day the account was opened avoids it; the export guide shows how.

Related

We see you're using an ad blocker. Please disable it for this site so we can keep this service free.