Brokers · 20 Nov 2026

How Fills Become Trades: FIFO Pairing Explained

FIFO trade matching explained with three buys and two sells: which lots pair, the realised P&L of each exit, and why average cost splits it differently.

TradeFolie Team6 min readBrokersAnalytics

FIFO trade matching closes your oldest open lots first: each sell is paired with the earliest buy still open, and that pair's P&L is realised. The method decides how one set of fills splits into round trips, and so what each exit made or lost. On a fully closed position, FIFO and average-cost matching give the same total; only the per-trade figures differ.

The matching method never changes what a closed position made. It changes which exits look like wins, and that can shift per-trade metrics such as profit factor.

What FIFO in trading means

FIFO stands for first in, first out. When you sell part of a long position, the units sold are treated as the ones you bought earliest. For a short position it runs the other way: the first buy closes the oldest open sell.

The tradebook does not pair anything. It lists every executed fill with its quantity, price and time, as how to download your Zerodha tradebook and what each column means shows. Turning fills into trades needs a matching rule: FIFO is one, average cost is another.

The example: three buys and two sells

Take one index option contract (same strike, same expiry) and assume a lot size of 75. Check the current lot size on nseindia.com. Over three days the tradebook shows five fills, in time order:

FillDayTypeQuantityPrice
B1Mondaybuy75₹120
B2Mondaybuy75₹112
B3Tuesdaybuy150₹100
S1Tuesdaysell150₹115
S2Wednesdaysell150₹105

You bought 75 + 75 + 150 = 300 units for 75 × ₹120 + 75 × ₹112 + 150 × ₹100 = ₹9,000 + ₹8,400 + ₹15,000 = ₹32,400. You sold all 300 for 150 × ₹115 + 150 × ₹105 = ₹17,250 + ₹15,750 = ₹33,000. The gross result is ₹33,000 minus ₹32,400 = ₹600, before brokerage and charges.

These fills are made up for the arithmetic, not a way to trade or a result to expect.

FIFO trade matching, step by step

Take the sells in time order; each closes the oldest open buys until its quantity is used up.

  1. 1.S1, 150 at ₹115: 75 units close B1, the oldest lot, and the other 75 close B2.
  2. 2.S2, 150 at ₹105: B1 and B2 are closed, so all 150 close B3.

That gives three matched pairs, each a round trip for those units:

Round tripBuySellWorkingRealised P&L
1B1 at ₹120S1 at ₹11575 × (₹115 minus ₹120)-₹375
2B2 at ₹112S1 at ₹11575 × (₹115 minus ₹112)+₹225
3B3 at ₹100S2 at ₹105150 × (₹105 minus ₹100)+₹750

So S1 realised ₹225 minus ₹375 = a loss of ₹150, and S2 a profit of ₹750: ₹750 minus ₹150 = ₹600 together, the same total.

The same fills on average cost

Average-cost matching pools your buys into one price. After the three buys, your average is ₹32,400 ÷ 300 = ₹108. A sell does not change the average of what is left; only a new buy does.

  • S1: 150 × (₹115 minus ₹108) = 150 × ₹7 = a profit of ₹1,050.
  • S2: 150 × (₹105 minus ₹108) = 150 × (-₹3) = -₹450, a loss.

The total is ₹1,050 minus ₹450 = ₹600 again.

Same total, different trades

Counting each exit as one trade:

ExitFIFOAverage cost
S1: 150 at ₹115-₹150+₹1,050
S2: 150 at ₹105+₹750-₹450
Total+₹600+₹600

The first exit is a loss under FIFO and a win under average cost; the second flips. The totals cannot differ, because both methods set the same ₹32,400 of cost against the same ₹33,000 of proceeds.

That split reaches your metrics. Win rate is 50 percent either way, and expectancy is ₹600 ÷ 2 = ₹300 per trade either way. Profit factor is not: ₹750 ÷ ₹150 = 5.0 on FIFO, against ₹1,050 ÷ ₹450 = about 2.33 on average cost. How profit factor and expectancy are calculated walks through both formulas.

It changes your review too. Under FIFO, S1 looks like the mistake; under average cost, S2 does. Use one method for every trade, or the seven trading metrics worth reviewing every week stop being comparable from month to month.

Count the whole position, flat to flat, as one trade and it is ₹600 under either method. The method matters only when you split a position or part of it is still open.

How brokers calculate realised P&L

Realised P&L is on units you have closed; unrealised P&L is on units still open. Any report needs a matching method to decide which cost goes with the closed units, and that matters most while a position is partly open.

Stop the example on Tuesday evening, after S1, with the option at an assumed ₹105. FIFO leaves B3's 150 units at ₹100 open, so unrealised P&L is 150 × (₹105 minus ₹100) = ₹750. Average cost leaves 150 units at ₹108, so it is 150 × (₹105 minus ₹108) = -₹450, a loss.

Tuesday eveningFIFOAverage cost
Realised (S1)-₹150+₹1,050
Unrealised at ₹105+₹750-₹450
Realised + unrealised+₹600+₹600

Same position, same price, opposite realised figures. If a month or financial year ended that Tuesday, the method would decide how much P&L lands in each period.

On Zerodha, the P&L report in Console (Reports, then P&L) shows realised profit and loss per scrip for a period; how the Zerodha P&L report differs from Tax P&L is worth reading before comparing numbers. Do not assume which matching method a broker's report uses, or which one tax rules apply. Check your broker's help pages or ask support. The Tax P&L is the report built for filing, so go through it with a chartered accountant.

Where to start

Pick one method for your journal and write it down.

Then check a round trip by hand. For round trip 3, put a buy price of ₹100, a sell price of ₹105, 2 lots and a lot size of 75 into the free P&L calculator; it shows a gross profit of 2 × 75 × ₹5 = ₹750. TradeFolie imports the Zerodha tradebook file as it is and pairs the fills into complete trades, so you can check its trades the same way.

If a fully closed position's total does not match your broker's report, look for a missing fill or charges first. The matching method cannot change that total.

FAQ

What is FIFO trade matching?

It pairs each closing fill with the oldest opening fill still open in the same contract: first in, first out. Each pair is a round trip; for a long, its gross P&L is quantity × (sell price minus buy price).

Does FIFO change my total profit or loss?

Not on a position you have fully closed. FIFO and average cost split the same cost and proceeds differently between exits, changing per-trade P&L, profit factor and realised P&L on a given date, but not the total.

Is FIFO or average cost better for a trading journal?

Neither changes your total, so consistency matters more than the choice. FIFO is easier to check against a tradebook because each exit maps to specific fills; average cost is simpler when you add to and trim one position many times.

How do brokers calculate realised P&L?

A broker's report applies its own matching method, such as FIFO or average cost, to work out the cost of the units you closed, and shows P&L on those units. Check which method your broker uses in its help pages, and ask a chartered accountant which method applies for tax before you file.

This article is for education only and is not investment advice. TradeFolie is not a SEBI-registered investment adviser or research analyst. Trading in equities and derivatives involves risk, including the loss of capital. Please consult a registered professional before making financial decisions.

See these numbers on your own trades.

Import your broker tradebook and TradeFolie builds the journal, the metrics and the behaviour checks for you.