Cost Basis & Share Matching Calculator
Match sales to purchases by your country’s rules, and see each gain or loss.
Try before you buy.
- Free preview: the rules, dates and checks that apply to your figures, with every computed amount hidden.
- Locked until you unlock it: download and copy.
- Unlock: Premium pass, ₹799 for 30 days, a one-time payment that never renews. Sold only in rupees.
Ways to unlock shows how to get the full result.
Printing this result is locked in the free preview.
Each sale and what it was matched with
Losses not allowed now
Totals by tax year
Your holding after each trade
How this was calculated
Locked in the free preview. Opens the ways to unlock this result.
Locked in the free preview. Batch runs unlock with a pass.
Locked in the free preview. Query results unlock with a pass.
Tax rules and rates change. This calculator follows the rules described on this page and may not cover every situation. Check the official source or a qualified tax professional before filing or invoicing.
About the Cost Basis & Share Matching Calculator
When you sell shares bought at different times and prices, your tax rules decide which purchases each sale is matched with — and so the cost, the gain or loss, and what is still held. This calculator applies the rule of your country to your own trades: the UK’s share identification rules (same day, then the next 30 days, then the Section 104 pool), Canada’s adjusted cost base with the superficial-loss rule, US lot identification with wash sales, first in, first out for Germany and India, and for other markets first in, first out or the average cost of identical shares, whichever your tax rules use.
Load the trades file your broker exports (or type the trades), choose the rule, and see every sale with the purchases it was matched to, the rule that matched them, the cost, the proceeds and the gain or loss, the wash-sale or superficial-loss flags with the adjusted cost, the holding after every trade and the totals for each tax year — with a CSV for the country capital-gains calculators.
Trades in another currency are converted with the rates you give: one for each currency, or one on each trade you type. Your trades are read in your browser and never uploaded.
How to use it
- Choose the rule of your country: United Kingdom, Canada, United States, Germany, India, or another market with first in, first out or the average cost, and the day your tax year starts.
- Load the trades file your broker exports, type your trades in the box, or try one of the examples of a fictional DEMO share; check the columns the reader found.
- Set the currency of your tax return and, for trades in another currency, a rate for each currency of your file or a rate on each typed trade; merge symbols that are the same shares, and add any splits.
- Read each sale with the purchases it was matched to, the gain or loss, any wash-sale or superficial-loss flag and the totals by tax year.
- Copy the summary or download the CSV for your tax return or a country’s capital-gains calculator — with a pass, or after unlocking this result.
Examples
Buy 1,000 DEMO for £2,000 on 1 January; buy 500 for £1,500 on 1 March; sell 800 for £3,200 on 10 June; buy 300 for £1,050 on 15 June
300 matched to the 15 June purchase (30-day rule) at £1,050 and 500 to the Section 104 pool at £1,166.67: cost £2,216.67, gain £983.33; the pool keeps 1,000 shares at £2,333.33
Buy 100 DEMO at $50 on 1 February; sell 100 at $40 on 1 March (a $1,000 loss); buy 100 at $42 on 15 March
The $1,000 loss is disallowed and added to the new shares: basis $5,200 ($52 a share), and the 28 days the first shares were held count towards their holding period
Buy 100 at $10 + $10 commission; buy 50 at $12 + $10; sell 60 at $15 − $10
ACB $1,010, then $1,620 for 150 shares ($10.80 each); proceeds $890 − ACB $648 = gain $242; 90 shares left at an ACB of $972
100 shares with an ACB of $1,500 sold at $12; 100 bought at $12.50 ten days later and still held 30 days after the sale
The $300 loss is denied and added to the new shares: ACB $1,550
Common uses
- Work out the gains and losses of a year of share sales for a UK return, with the 30-day rule and the Section 104 pool applied to every sale.
- Check the adjusted cost base of shares you bought in several lots before selling part of them in Canada.
- See whether a loss you took was a wash sale because you bought the shares back within 30 days.
- Turn a broker’s trade history into one line per sale for a capital-gains calculator or an accountant.
The rules
- United Kingdom. Shares sold are matched first with shares of the same company bought on the same day, then with shares bought in the 30 days after the sale (the “bed and breakfast” rule, which does not apply to shares bought while you were not UK resident), then with the Section 104 holding — all your other shares of that company at their average cost — and finally with later purchases, earliest first (CG51555, CG51560, helpsheet HS284). All sales of one day are one disposal. When several purchases fall in the 30 days, the tool takes them in date order, earliest first.
- Canada. The adjusted cost base is the average cost of all your identical shares, worked out again at each purchase, commissions included; a sale’s gain is its proceeds minus its outlays minus the ACB of the shares sold (CRA guide T4037). A loss is superficial when you (or an affiliated person) buy identical shares in the 30 days before or after the sale and still hold them 30 days after it: the loss is denied and added to the ACB of those shares (Income Tax Act, section 54).
- United States. The shares sold are those you identify; without identification, the first ones bought. Average basis is for mutual fund shares. A loss is disallowed under the wash-sale rule when you buy substantially identical shares within 30 days before or after the sale; it is added to the basis of the shares bought, and their holding period includes that of the shares sold (Publication 550). Each lot sold counts on its own, so a lot sold at a gain keeps its gain; the replacement shares are taken in the order bought and paired with the shares sold at a loss, which are taken in the order they were bought (Treasury Regulation § 1.1091-1). Held more than a year, a gain or loss is long term (Topic 409).
- Germany. For securities held in collective custody, the ones bought first are deemed sold first (§ 20 Abs. 4 Satz 7 EStG), each amount converted at the exchange rate of its own date.
- India. Shares held in a demat account are matched first in, first out. The FIFO capital gains calculator also applies India’s tax rules: holding periods, grandfathering and the gains by category.
- Other markets. Choose the method your tax rules use: first in, first out, or the average cost of all your identical shares, worked out again at each purchase (the shares sold leave the pool at that average). Check your tax authority’s rule before you use the result.
Reading the results
- Each sale lists the purchases it was matched to and the rule that matched them, so you can follow the calculation line by line against your broker’s statement.
- Proceeds are the shares × the sale price; costs of sale are the commission and fees; the allowable cost is what the matched shares cost, with the fees paid to buy them.
- A wash sale or superficial loss keeps the loss out of this year: the amount is shown, and so is the purchase it was added to, which carries it until those shares are sold.
- The holding after each trade shows the shares and their cost (the Section 104 pool in the UK, the total ACB in Canada, the open lots elsewhere).
- Totals by tax year use the UK’s 6 April to 5 April year, India’s 1 April to 31 March year and the calendar year elsewhere; under “other markets” you choose the day your tax year starts (Australia’s income year starts on 1 July).
What it leaves out
The tax itself (each country’s calculator works that out from these figures), allowances and exemptions, crypto assets (their rules differ in places), shares from employee share schemes, gifts and inheritances, and corporate actions other than splits and consolidations (enter rights issues and demergers as purchases or adjustments with your own figures). Short sales are not handled: a sale larger than your holding is flagged. The rules look at every account you hold (and, for wash sales, your spouse’s and your retirement accounts): the tool sees only the trades you load.
Limitations
- One rule at a time: choose the country whose rules apply to you.
- Splits and consolidations are entered as adjustments; other corporate actions need your own figures.
- Short sales are not handled: a sale above your holding is an error, except in the UK, where HMRC’s last rule matches the extra shares with later purchases and the page says so.
- Not for crypto assets, options or employee share schemes.
Privacy
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
What do I get without a pass?
Without a pass, Cost Basis & Share Matching Calculator shows the rules, dates and checks that apply to your figures, with every computed amount hidden. Until you unlock it, the result can’t be downloaded or copied. A Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.
Which trades file can I load?
Any CSV or Excel file with a header row and one trade per row: a date, a symbol, buy or sell, the quantity, the price and the fees. Broker exports in the formats listed on the page are recognised by themselves; for others, the mapping panel lets you pick the columns. You can also type or paste the trades.
How does the 30-day rule work in the UK?
If you sell shares and buy shares of the same company within the next 30 days, the sale is matched with those new shares first, not with the shares you held before. In the example above, 300 of the 800 shares sold are matched with the purchase five days later, at its price, and only the other 500 come from the Section 104 pool.
What happens to a loss that is disallowed?
It is not lost: it is added to the cost of the shares you bought back, so it reduces the gain (or increases the loss) when you sell them. The tool shows which purchase it was added to and the new cost.
Does it work out my tax?
No. It works out the gain or loss of each sale under your country’s matching rule and the totals for each tax year. The tax depends on your allowances, your other income and your country’s rates: the capital-gains calculators for each country take it from there.
What if I bought the shares in another currency?
Give each currency in your file a rate into the currency of your tax return, or type a rate on each trade of your own list. With a rate on each trade, each purchase is converted at its own rate and each sale at its own, as the rules ask.
Are my trades uploaded?
No. Files and typed trades are read in your browser, and nothing you enter or load is sent to our server.