It would be great if you could develop a tax optimization tool that allows users to select which specific batch of shares to sell. Currently, the profit or loss from a sale is typically calculated using the average purchase price of all shares, which is not optimal in certain scenarios. Therefore, I would like to know if it is possible to implement an additional feature that enables users to choose which batch of shares from a particular purchase date to sell.
I don’t think you can pick and choose yourself which to sell, you have to follow HMRC guidelines here which use the average price when you buy multiple shares in the same company. Unless you mean the 30 day rule but I haven’t dug that deep yet.
Selling shares in the same company
There’s a different way of working out your cost if you’ve sold the same type of shares in a company that you bought at different times.
You’ll usually need to work out the average cost of your shares and deduct this from what you got for them to work out your gain.
Example
You buy 100 shares for 80p each. The total cost is £80.
You later buy 300 shares for £1.20 each. The total cost is £360.
In total, you have 400 shares costing £440 - the average cost of each share is £1.10.
If you sell 150 shares, the cost of the shares for your tax calculations is £165 (£1.10 multiplied by 150). Deduct this from what you sold the shares for to work out your gain.
If you bought new shares of the same type in the same company within 30 days of selling your old ones, there are special rules for working out the cost to use in your tax calculations.