KapJI / capital-gains-calculator

UK capital gains tax calculator which supports transaction history from different brokers
MIT License
112 stars 42 forks source link

Fix bed&breakfast calculation when stock is split #511

Open sygi opened 2 months ago

sygi commented 2 months ago

The stock split action in the code is considered a 0-priced acquisition. This works as long as there is no bed&breakfast to consider (no sale in the previous 30 days).

It would be nice to fix the calculation to handle this case as well, or, at a very least, to throw an error to avoid silently incorrect calculation.

vmartinv commented 1 month ago

Can you add some minimal examples to test in whatever csv format you are using? Alongside what should be correct reported gain/loss, these cases would help:

Also I believe this is still a hard case because if you sell everything the stock split won't even show up in your export, and there's no way to detect it or warn about that.

sygi commented 2 weeks ago

I attach a CSV file with an example split. I also created a test here: #541 which shows where the problem lies (the library consider a split as an 0-cost acquisition). schwab.csv

vmartinv commented 2 weeks ago

I attach a CSV file with an example split. I also created a test here: #541 which shows where the problem lies (the library consider a split as an 0-cost acquisition). schwab.csv

I wouldn't worry about fixing it at the moment, I had one idea about it. Just having the 3 examples I listed would be helpful

sygi commented 2 weeks ago

Please find the three examples attached. Note that no2 and 3 are actually the same in terms of cgt, as both split and buy after 30 days are tax neutral.

schwab2_5_00.csv schwab_5_00.csv schwab_18_00.csv

KapJI commented 2 weeks ago

I guess the first thing we should do is detect b&b when split is involved and abort as unsupported case. Until someone figure out how to calculate this cases properly.

alexpung commented 1 week ago

I am quite sure you do the b&b matching rules with the matching quantity adjusted for the share split ratio. https://www.gov.uk/government/publications/share-reorganisations-company-takeovers-and-capital-gains-tax-hs285-self-assessment-helpsheet/hs285-share-reorganisations-company-takeovers-and-capital-gains-tax-2021

sygi commented 1 week ago

Yes, this is what I advocate above and propose strategies for implementing of #541