How to use the cost basis lot matcher
- List each purchase with its date, quantity and price per unit. Add as many lots as you need.
- List each sale with its date, quantity and price per unit. Sales are matched against purchases made on or before the sale date.
- Choose which method's matches to show in detail: first in first out, last in first out, highest cost first, or average cost.
- Read the four-way comparison of cost basis and gain, then the detail table showing which lot each part of a sale came from and how long it was held.
Formula
Gain on a matched piece = quantity x (sale price - purchase price)
First in, first out: oldest lots first
Last in, first out: newest lots first
Highest cost first: the most expensive lots first
Average cost: total cost of units still held / number of units
For average cost, every lot bought up to the sale date joins one pool, and a sale takes units from the pool at that pool's average. Later purchases join the pool at their own cost.
Three purchases and one sale
Buy 100 units at $20 on 2023-02-10, 50 at $30 on 2023-08-15 and 80 at $25 on 2024-03-01. On 2024-06-20 sell 120 units at $40, for proceeds of $4,800.
First in, first out sells the 100 at $20 and 20 of the $30 lot: cost $2,600, gain $2,200. Last in, first out takes the 80 at $25 and 40 of the $30 lot: cost $3,200, gain $1,600. Highest cost first takes the 50 at $30 and 70 of the $25 lot: cost $3,250, gain $1,550. Average cost is $5,500 / 230 = $23.9130 a unit, so the cost is $2,869.57 and the gain is $1,930.43. The gains differ by $650 from the same sale.
Why the method changes the gain
When you buy the same thing at different prices, a sale of part of it has to be matched to specific purchases. The matching changes the cost used and so the gain. Prices that rose over time give a larger gain under first in first out, since the oldest lots are cheapest, and a smaller gain under last in first out or highest cost first.
The total profit over the whole life of the holding is the same, since you spent the same money and received the same proceeds. The methods only move gains between sales and tax years. For a single sale with tax rates you enter yourself, see the Capital Gains Calculator, and for repeated buys the Stock Average Calculator.
What this page does not decide
Which methods you can use, whether you must name lots when you sell, how holding periods are counted and what rates apply depend on your country, your account and your broker. A broker may apply a default method to your sales. Nothing here is tax or legal advice, and no rate is built into the tool.
The same matching ideas are used for goods in a warehouse, shown in the FIFO and LIFO Inventory Valuation Calculator. Use the detail table's days held as a plain count of days, and read your own rules for what counts as a long or short holding.
Assumptions and limits
- Each sale can only use units bought on or before the sale date, and a sale larger than the units available is rejected.
- Fees, commissions, stock splits, wash sale style rules and currency changes are not modeled.
- Quantities can be fractions. Prices are per unit in one currency.
- Dates are read as calendar dates with no time of day, so same-day purchases and sales are allowed.
Frequently asked questions
What is a cost basis lot?
A lot is a group of units bought at one time and price. When you sell, the cost of the units you sold depends on which lots they came from, which is why matching rules exist.
What does highest cost first do?
It sells the units you paid the most for first, which usually lowers the gain on that sale. It is an option some brokers offer, but whether you may use it depends on your account and your rules.
Why does average cost have no lot dates?
Average cost merges everything you hold into one pool. A sale takes units from the pool at the pool's average price, so there is no individual lot to point to or hold date to count.
Does the tool tell me what tax I owe?
No. It reports gain per method and the days held, and leaves out rates, brackets and special rules on purpose. Use your own country's rules or an adviser for the tax side.