mattjgalloway / cgtcalc

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

Confusing output of transactions #5

Closed sodastsai closed 3 years ago

sodastsai commented 3 years ago

As pointed in the following screenshot

Screen Shot 2021-02-21 at 6 42 08 PM

Input

BUY 05/12/2020 AAPL 50 20 0
BUY 05/12/2020 AAPL 50 20 0
BUY 05/12/2020 AAPL 50 20 0
SELL 06/12/2020 AAPL 120 40 0

Output

# SUMMARY

Tax year    Gain    Proceeds   Exemption   Loss carry   Taxable gain   Tax (basic)   Tax (higher)
=================================================================================================
2020/2021   £2400   £4800      £12300      £0           £0             £0            £0          

# TAX YEAR DETAILS

## TAX YEAR 2020/2021

1) SOLD 120 of AAPL on 06/12/2020 for GAIN of £2400
Matches with:
  - SECTION 104: 150 at cost basis of £20
Calculation: (120 * 40 - 0) - ( (120 * 20) ) = 2400

# TRANSACTIONS

05/12/2020 BOUGHT 150 of AAPL at £20 with £0 expenses
05/12/2020 BOUGHT 50 of AAPL at £20 with £0 expenses
05/12/2020 BOUGHT 50 of AAPL at £20 with £0 expenses
06/12/2020 SOLD 120 of AAPL at £40 with £0 expenses

# ASSET EVENTS

NONE

The transaction printed in the output is wrong (because of grouped result?) It could be the result of this function, where "amount" are accumulated. https://github.com/mattjgalloway/cgtcalc/blob/0391b991bd574a565897310d9cb5dc66a60c10d2/Sources/CGTCalcCore/Models/Transaction.swift#L33-L43

The calculation result for the whole CGT should be still correct. But just the printed output is a bit confusing because of this. The fix could be to copy the original transaction list for printing? I can try to fix after, but just to log down this bug here first.

mattjgalloway commented 3 years ago

Ooo that's a good spot yes that's a bug. It'll be because of grouping them up but then all seem to be being printed out in the list at the end. Good find. Will add a test case and fix it.

sodastsai commented 3 years ago

Thanks Matt!