Skip to main content

FIFO and LIFO Cost Basis in Google Sheets

When you buy the same asset several times at different prices and then sell part of it, which shares did you sell? The answer sets the cost basis of the sale, and with it your realized P&L, your holding period and your tax. tradeGIST answers it in your Google Sheets™ portfolio at every Generate Trades: it matches each sale to the lots you bought, first in, first out (FIFO) or last in, first out (LIFO), and writes one row per match on the Trades sheet.

There is nothing to set up: FIFO is the default. This page explains what happens, for when you want to check a number or change the method.

New to tradeGIST? Start with the Quick Start: four steps get your portfolio tracked, and this page is here when you need it.

FIFO vs. LIFO: a worked example​

You buy 100 shares at $10 in January and 100 more at $15 in March, then sell 150 at $20 in June. Each purchase is a lot, and the method decides which lots the sale closes:

FIFOLIFO
Lots sold100 from January at $10, 50 from March at $15100 from March at $15, 50 from January at $10
Cost basis of the sale$1,750$2,000
Realized P&L$1,250$1,000
Shares still held50 bought at $1550 bought at $10

Either way the sale takes two rows on the Trades sheet, one per lot it closes, and the 50 shares left stay on a third row as an open trade. Once everything is sold the total profit is the same; the method decides when it is realized and which lots stay open.

Choosing the matching method​

Open the tradeGIST menu, click ⚙️ Settings and set Matching method in the Tax section to FIFO or LIFO. It applies to your whole portfolio. Change it and the next Generate Trades matches your entire history again with the new method.

Which one to use depends on your tax rules: pick the method your jurisdiction or your broker's statements follow.

What goes into the cost basis​

  • Price and fees. A lot's cost basis, the Cost basis column of the Trades sheet, is its price times its volume, plus the fees paid to open it. The fees of the sale come off the proceeds.
  • Currencies. The basis is kept in the asset's currency and converted to your base currency at the FX rate of the transaction that opened the lot. See Multi-Currency Tracking.
  • Stock splits. A split scales the volume and the price of each earlier lot, so its total basis does not change. See Handling Stock Splits.
  • Exercised and assigned options. The option's premium is carried into the basis of the shares. See Managing Transactions.
  • Reinvested dividends. A drip is a new lot at the reinvestment price. See Dividend Income & Tracking.
  • Wash sales. With detection on, a disallowed loss is added to the basis of the replacement lot. See Wash Sale Detection.

Which transactions are matched together​

  • One asset at a time. A sale only closes lots of the same ticker, and each option contract is matched on its own.
  • Across your accounts, unless you separate them. By default a sale in one account can close a lot bought in another. To match an account on its own, or to keep two tax entities apart, see Accounts.
  • In date order. When you trade the same asset more than once in a day, enter the time so the lots are matched in the order they happened.
  • Short positions too. A sale larger than what you hold closes your shares and opens a short position, and the buys that cover it are matched in the same order.
  • Categories on top. To follow a strategy on its own, apart from the FIFO or LIFO order, see Trade Tagging & Categories.

Lots and average cost​

The Trades sheet works by lot, and so do your P&L and tax. The Cost basis column of the Open positions summary is a shortcut: the average cost per unit of the lots you still hold.

Disclaimer​

tradeGIST applies the method you choose to every sale, but which method you may use, and how gains are taxed, depends on your jurisdiction. This is not tax advice. Check with a tax professional and compare your figures with your broker's statements before filing.