mattjgalloway / cgtcalc

A UK capital gains tax calculator written in Swift
MIT License
94 stars 16 forks source link

Incorrect matching in complex case #2

Closed KapJI closed 3 years ago

KapJI commented 3 years ago

First, "same day rule" is not being applied correctly: From https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg51560:

All shares of the same class in the same company acquired by the same person on the same day and in the same capacity are treated as though they were acquired by a single transaction, TCGA92/S105 (1)(a).

For input like this:

BUY 02/03/2020 FOO 100 25 6
SELL 03/03/2020 FOO 100 26 5
BUY 03/03/2020 FOO 50 27 5
SELL 03/03/2020 FOO 50 28 5
BUY 03/03/2020 FOO 100 28 5
BUY 03/03/2020 FOO 4 29 0
SELL 03/03/2020 FOO 104 30 5
BUY 06/03/2020 FOO 90 28 5
SELL 06/03/2020 FOO 90 27 5

It should first be transformed into these transactions:

BUY 02/03/2020 FOO 100 25 6
BUY 03/03/2020 FOO 154 27.70 10
SELL 03/03/2020 FOO 254 28.03 15
BUY 06/03/2020 FOO 90 28 5
SELL 06/03/2020 FOO 90 27 5

And even if I do this manually output doesn't seem correct. Here is what I get:

1) SOLD 254 of FOO on 03/03/2020 for GAIN of £322
Matches with:
  - SAME DAY: 154 bought on 03/03/2020 at £27.7
  - SECTION 104: 100 at cost basis of £25.06
Calculation: (254 * 28.03 - 15) - ( (154 * 27.7 + 10) + (100 * 25.06) ) = 322

2) SOLD 90 of FOO on 06/03/2020 for LOSS of £100
Matches with:
  - SAME DAY: 90 bought on 06/03/2020 at £28
Calculation: (90 * 27 - 5) - ( (90 * 28 + 5) ) = -100

In fact "bed and breakfast" rule should be used before "section 104". And I expect something like this:

1) SOLD 254 of FOO on 03/03/2020 for GAIN of £53
Matches with:
  - SAME DAY: 154 bought on 03/03/2020 at £27.7
  - BED & BREAKFAST: 90 bought on 06/03/2020 at £28
  - SECTION 104: 10 at cost basis of £25.06
Calculation: (254 * 28.03 - 15) - ( (154 * 27.7 + 10) + (90 * 28 + 5) + (10 * 25.06) ) = 53

2) SOLD 90 of FOO on 06/03/2020 for GAIN of £169
Matches with:
  - SECTION 104: 90 at cost basis of £25.06
Calculation: (90 * 27 - 5) - ( (90 * 25.06) ) = 169

Current output

# SUMMARY

Tax year    Gain   Proceeds   Exemption   Loss carry   Taxable gain   Tax (basic)   Tax (higher)
================================================================================================
2019/2020   £221   £9550      £12000      £0           £0             £0            £0

# TAX YEAR DETAILS

## TAX YEAR 2019/2020

1) SOLD 50 of FOO on 03/03/2020 for LOSS of £10
Matches with:
  - SAME DAY: 50 bought on 03/03/2020 at £28.0384615384615384615384615384615384615
Calculation: (50 * 28 - 5) - ( (50 * 28.0384615384615384615384615384615384615 + 2.4038461538461538461538461538461538462) ) = -10

2) SOLD 104 of FOO on 03/03/2020 for GAIN of £496
Matches with:
  - SAME DAY: 4 bought on 03/03/2020 at £28.0384615384615384615384615384615384615
  - SECTION 104: 100 at cost basis of £25.06
Calculation: (104 * 30 - 5) - ( (4 * 28.0384615384615384615384615384615384615 + 0.192307692307692307692307692307692307688) + (100 * 25.06) ) = 496

3) SOLD 100 of FOO on 03/03/2020 for LOSS of £165
Matches with:
  - SAME DAY: 50 bought on 03/03/2020 at £27
  - SAME DAY: 50 bought on 03/03/2020 at £28.0384615384615384615384615384615384615
Calculation: (100 * 26 - 5) - ( (50 * 27 + 5) + (50 * 28.0384615384615384615384615384615384615 + 2.4038461538461538461538461538461538462) ) = -165

4) SOLD 90 of FOO on 06/03/2020 for LOSS of £100
Matches with:
  - SAME DAY: 90 bought on 06/03/2020 at £28
Calculation: (90 * 27 - 5) - ( (90 * 28 + 5) ) = -100

# TRANSACTIONS

02/03/2020 BOUGHT 100 of FOO at £25 with £6 expenses
03/03/2020 SOLD 100 of FOO at £26 with £5 expenses
03/03/2020 BOUGHT 50 of FOO at £27 with £5 expenses
03/03/2020 SOLD 50 of FOO at £28 with £5 expenses
03/03/2020 BOUGHT 104 of FOO at £28.0384615384615384615384615384615384615 with £5 expenses
03/03/2020 BOUGHT 4 of FOO at £29 with £0 expenses
03/03/2020 SOLD 104 of FOO at £30 with £5 expenses
06/03/2020 BOUGHT 90 of FOO at £28 with £5 expenses
06/03/2020 SOLD 90 of FOO at £27 with £5 expenses
mattjgalloway commented 3 years ago

That's curious. I will add a test case. I would expect that it would be matching B&B as well, of course.

mattjgalloway commented 3 years ago

Oh, no I see. Why would you expect B&B there? Let's number the transactions:

1) BUY 02/03/2020 FOO 100 25 6
2) BUY 03/03/2020 FOO 154 27.70 10
3) SELL 03/03/2020 FOO 254 28.03 15
4) BUY 06/03/2020 FOO 90 28 5
5) SELL 06/03/2020 FOO 90 27 5

Shouldn't 4 and 5 match completely first as they're same day. So then you're left with 3 matching partially against same day transaction 2, and then section 104 for 1.

Also the calculator should be combining transactions (of same type, buy or sell) done on the same day already into one.

mattjgalloway commented 3 years ago

@KapJI - let me know if you disagree with the interpretation above. It's my understanding that you first match all the same day transactions, then go over and do B&B, then go over the remaining ones and apply section 104.

FWIW, http://cgtcalculator.com/ agrees with this calculator.

KapJI commented 3 years ago

I re-read https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg51560 and I think your interpretation is correct:

If the number of shares acquired exceeds the number sold on the same day the surplus is added to the Section 104 holding, unless they are identified with disposals under the ‘bed and breakfast’ rule, see below.