Giter Site home page Giter Site logo

cgtcalc's People

Contributors

embee8 avatar mattjgalloway avatar mrsheraton avatar sodastsai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cgtcalc's Issues

Inconsistent bed-and-breakfast results

With the following inputs:

cgtcalculator.com

B	29/08/2018	GB00B3TYHH97	20	184.65	12.50 0
B	15/03/2019	GB00B3TYHH97	20	181.56	2.00 0
S	05/11/2019	GB00B3TYHH97	40	194.22	12.50 0
B	10/11/2019	GB00B3TYHH97	20	190.19	2.00 0

cgtcalc

BUY 10/11/2019 GB00B3TYHH97 20 190.19 2
SELL 05/11/2019 GB00B3TYHH97 40 194.22 12.5
BUY 15/03/2019 GB00B3TYHH97 20 181.56 2
BUY 29/08/2018 GB00B3TYHH97 20 184.65 12.5

both cgtcalc and cgtcalculator.com disagree on the outputs, more specifically on the section 104 matching not being offset by the breakfast amount (at least in the textual representation, calculation is offset).

cgtcalc outputs the following:

1) SOLD 40 of GB00B3TYHH97 on 05/11/2019 for GAIN of £281
Matches with:
  - BED & BREAKFAST: 20 bought on 10/11/2019 at £190.19
  - SECTION 104: 40 at cost basis of £183.4675
Calculation: (40 * 194.22 - 12.5) - ( (20 * 190.19 + 2) + (20 * 183.4675) ) = 281

where as cgtcalculator.com report the following:

1. SELL: 40 GB00B3TYHH97 on 05/11/2019 at £194.22 gives GAIN of £280.00
Matches with: 
BUY: 10/11/2019 20 GB00B3TYHH97 shares of 20 bought at £190.19
BUY: SECTION 104 HOLDING. 20 GB00B3TYHH97 shares of 40 bought at average price of £183.4675
CALCULATION: Gain = £280.00 = ( 40 * 194.22 - 12.50 )
- ( 20 * 190.19 + 2.00 + 0.00 )
- ( 40 * 183.4675 ) * ( 20 / 40 )

The matching amount for section 104 is before being offset by the breakfast amount (40 vs 20)

Sell-to-cover shares should not be accounted for as a SELL event

I think this is not exactly an issue for this tool, because we can obviously work around it by simply not including the sell-to-cover shares, but it seems to be an interesting case where even HMRC are inconsistent in their messaging.

From https://web.archive.org/web/20220112102645/https://community.hmrc.gov.uk/customerforums/cgt/82d00dea-f06b-eb11-8fed-00155d975291 excerpted here for posterity:

Hi HMRC,

I would like to query the correct way to calculate and report my capital gains resulting from Restricted Stock Units (RSUs) as provided as part of my compensation by my employer and the process that they follow to cover the income tax liability.

Example context using round numbers for simplicity:

Employee E is a UK tax resident and works for a company C which is headquartered in the US.

Company C provide employee E with an RSU grant of 400 shares with a vesting schedule of 100 shares per year for 4 years.

Company C operate a "sell to cover" (STC) scheme at vesting events to cover employee E's income tax liability resulting from the vested shares: when the 100 shares vest, they sell 45% and 2% of them to cover the income tax and NI contributions respectively. The value of the 100 shares is then included as income through PAYE and the proceeds from the automatic sale cover the additional tax and NI due. This results in a similar net pay to what employee E receives in other months.

After this STC, the remaining 53 shares are then available in employee E's trading account to keep, or sell at a later date.

The dates at which these events happen are ambiguous according to the available documentation from the trading account provider.

Firstly, the trading platform provides me with a "Confirmation of Release" document which specifies a "Release date" and details the shares vested and the shares sold to cover taxes and implies that everything happens on the same day.

However, in the trading platform, it turns out that the trade has actually happened the day after the "Release date", hereby refered to as the "Sell date". This is listed in a "Trade Confirmation" document.

Finally, the account statement for the month in which the vesting takes place, it specifies a "Receive date" which is one day after the "Sell date", and a "Settlement date" which is one day after the "Receive date".

For the simplicity of this example we assume that employee makes no additional trades (i.e. buying any more shares or manually selling any shares).

I have the following question which will inform how to acurrately calculate the capital gains liability for employee E:

Does HMRC consider employee E to have:

a. Simply acquired 53 shares on the "receive date", meaning that the employee isn't considered to have disposed of any shares?

b. Acquired 100 shares on the "Release date" and disposed of 47 shares on the same date, meaning that the disposal is matched with 47 of the 100 shares acquired on the same day using the "same day rule"?

c. Acquired 100 shares on the "Receive date" and disposed of 47 shares on the "Sell date", meaning that the disposal of 47 shares would be matched against 47 of the 100 acquired on the "Receive date" using the "bed and breakfast rule"?

d. Acquired 100 shares on the "Release date" and disposed of 47 shares on the "Sell date", meaning that the 100 shares are added to the Section 104 holding, and that the disposal of 47 shares would be matched against the holding and the capital gain calculated using the average pool of cost of the holding?

As far as I can tell, (a) would be the simplest for reporting.

It could be argued that (b) might be more accurate and of the remaining options is most in keeping with the intention of the sell-to-cover process since employee E never had any agency over the 47 shares that were sold or, critically, WHEN they were sold.

If I understand correctly, (c) will be equivalent to (b) in the absense of any other trades, so this would ve fine too.

However, (d) would typically impose an unfair penalty on employee E that is not of their making. Consider the scenario where company C's share price has increased since previous vesting events. In this case the average pool of cost, after adding the 100 shares from this vesting event, would likely be significantly lower than the cost of the shares at the time of event. Therefore the capital gains will likely be significantly higher, through no fault of employee E. Specifically, if employee E had full agency over the 100 shares they could have sold them on the same day and avoided this issue.

Additionally, the company provide the following statement:

After this tax withholding, [company C] transfers ownership of the remaining shares to you and deposits them in your [trading platform] account. You own these shares outright.

This implies (a) but the income tax liability itself does not.

HMRC specifies both options a) or b) may apply, although one HMRC representative concedes option a) is the correct way.

Support currency conversion

It would be great if cgtcalc supported automatic currency conversions. My understanding is that, for CGT purposes, any acquisitions of assets in non-sterling currency (eg stock bought in USD) should be calculated in GBP using the exchange rate at the time of acquisition (or the HMRC monthly average rate, or any other equivalent rate as long as you are consistent - I'll happily be pointed at a more accurate explanation though). Equally, disposals should be converted using the same rate from the originating currency back to GBP. This is important to correctly determine the Section 104 pool value.

I've been experimenting with cgtcalc, and have resorted to manually looking up the exchange rate on https://www.xe.com/currencytables/, and doing the conversion maths myself. It would be very helpful if the calculator parsed the provided <AMOUNT> in each row to determine what currency it was in, and used the transaction date to look up the historical conversion rate.

Error in Dividends accounting?

Hi,
I found your code very helpful to validate my calculations.

I may have spotted an error. If you run this test example you'll notice that the 20/21 Capital gain is 1533, whilst it should be 1647.
The error arises from the code taking into account the 27/5/2021 dividend which is incorrect. The only dividend to be subtracted from 20/21 capital gains is the 28/5/20 dividend. The 27/5/2021 dividend QTY is net of the 20/12/2020 sale, so there is no proportion of the 21/12/2020 Divi to be allocated to the 20/12/2020 sale.

BUY 18/5/2019 TESTFUND 117.4812 170.24 0
BUY 20/4/2019 TESTFUND 117.1097 170.78 0
BUY 13/6/2019 TESTFUND 29.6701 168.52 0
SELL 14/9/2019 TESTFUND 0.288 179 0
DIVIDEND 28/5/2020 TESTFUND 263.973 696.53
SELL 28/12/2020 TESTFUND 77.2161 194.26 0
DIVIDEND 27/5/2021 TESTFUND 186.7569 389.08

Confusing output of transactions

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.

func groupWith(transaction: Transaction) throws {
guard transaction.kind == self.kind, transaction.date == self.date, transaction.asset == self.asset else {
throw CalculatorError.InternalError("Cannot group transactions that don't have the same kind, date and asset.")
}
let selfCost = self.amount * self.price
let otherCost = transaction.amount * transaction.price
self.amount += transaction.amount
self.price = (selfCost + otherCost) / self.amount
self.expenses += transaction.expenses
self.groupedTransactions.append(transaction)
}

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.

PDF output format

It would be good to have a PDF output format to complement the text output that currently exists.

Incorrect dividend acquisition matching

Hi,
Thanks for this tool, it's been incredibly useful in validating my own calculations.

I've found what I think is a bug in both dividends and capital return events. It seems that the code assumes dividends are being paid on all holdings, when they're only being paid on one?

Take for example:

BUY 21/02/2018 FOO 80 1.6732 0
BUY 21/03/2018 FOO 90 1.6528 0
DIVIDEND 30/04/2018 FOO 80 4.01

There are two holdings of FOO brought at two different times. The 21/03/2018 entry is not eligible for the dividend for whatever reason (as reported by my broker statements). However this errors:

[INFO] Begin processing
[INFO] Begin pre-processing transactions for FOO.
[DEBUG]  - Processing dividend event: <AssetEvent: kind=Dividend(80, 4.01), date=2018-04-30 00:00:00 +0000, asset=FOO>.
[ERROR] Failed: InvalidData("Error pre-processing FOO. Dividend amount doesn\'t match acquisitions.")

If I add the units for both holdings together and report a dividend on that instead:

BUY 21/02/2018 FOO 80 1.6732 0
BUY 21/03/2018 FOO 90 1.6528 0
DIVIDEND 30/04/2018 FOO 170 4.01

it works fine:

[INFO] Begin pre-processing transactions for FOO.
[DEBUG]  - Processing dividend event: <AssetEvent: kind=Dividend(170, 4.01), date=2018-04-30 00:00:00 +0000, asset=FOO>.
[DEBUG]     - Matching to acquisition <TransactionToMatch: transaction=<Transaction: kind=Buy, date=2018-02-21 00:00:00 +0000, asset=FOO, amount=80, price=1.6732, expenses=0, groupedTransactions=[]>, amount=80, underlyingPrice=1.6732, price=1.6732, expenses=0, offset=0>, apportioned value of 1.88705882352941176470588235294117647058.
[DEBUG]     - Matching to acquisition <TransactionToMatch: transaction=<Transaction: kind=Buy, date=2018-03-21 00:00:00 +0000, asset=FOO, amount=90, price=1.6528, expenses=0, groupedTransactions=[]>, amount=90, underlyingPrice=1.6528, price=1.6528, expenses=0, offset=0>, apportioned value of 2.12294117647058823529411764705882352938.
[INFO] Finished pre-processing transactions for FOO.
[INFO] Begin processing transactions for FOO.
[INFO] Begin matching processor.
[INFO] Finished matching processor. Matched 0 and there are 0 disposals left.
[DEBUG] Section 104: Begin processor
[DEBUG] Section 104: Finished processor. There are 0 disposals left.
[DEBUG] Tax events for FOO
[INFO] Finished processing transactions for FOO. Created 0 tax events.
[INFO] Finished processing
# SUMMARY

Tax year   Gain   Proceeds   Exemption   Loss carry   Taxable gain   Tax (basic)   Tax (higher)
===============================================================================================


# TAX YEAR DETAILS


# TRANSACTIONS

21/02/2018 BOUGHT 80 of FOO at £1.6732 with £0 expenses
21/03/2018 BOUGHT 90 of FOO at £1.6528 with £0 expenses


# ASSET EVENTS

30/04/2018 FOO DIVIDEND on 170 for £4.01

I do not believe this to be accurate and isn't aligned with the way my brokers tax statements report, although the answer is correct irrelevant in most circumstances.

Proceeds calculation, transaction rounding, allowable cost

First of all, thanks a lot for open-sourcing this project!

I have noticed some minor gaps between what the calculator generates and my own calculations of the values that need to go into the capital gains section of the tax return.

What follows is a sample input, output, some extra calculations accompanied by some commentary.

INPUT

BUY 15/05/2022 SHARE_A 100 9.8 0.23
SELL 16/08/2022 SHARE_A 100 12.8 1.54

BUY 15/05/2022 SHARE_B 100 10.2 2.45
SELL 16/08/2022 SHARE_B 100 11.8 4.97

BUY 15/05/2022 SHARE_C 100 53.2 1.67
SELL 16/08/2022 SHARE_C 100 49.3 2.86

BUY 15/05/2022 SHARE_D 100 100.5 3.98
SELL 16/08/2022 SHARE_D 100 111.2 5.02

OUTPUT

SUMMARY

Tax year Gain Proceeds Exemption Loss carry Taxable gain Tax (basic) Tax (higher)
2022/2023 £1116 £18510 £12300 £0 £0 £0 £0

TAX YEAR DETAILS

TAX YEAR 2022/2023

  1. SOLD 100 of SHARE_A on 16/08/2022 for GAIN of £298
    Matches with:
  • SECTION 104: 100 at cost basis of £9.8023
    Calculation: (100 * 12.8 - 1.54) - ( (100 * 9.8023) ) = 298
  1. SOLD 100 of SHARE_B on 16/08/2022 for GAIN of £152
    Matches with:
  • SECTION 104: 100 at cost basis of £10.2245
    Calculation: (100 * 11.8 - 4.97) - ( (100 * 10.2245) ) = 152
  1. SOLD 100 of SHARE_C on 16/08/2022 for LOSS of £395
    Matches with:
  • SECTION 104: 100 at cost basis of £53.2167
    Calculation: (100 * 49.3 - 2.86) - ( (100 * 53.2167) ) = -395
  1. SOLD 100 of SHARE_D on 16/08/2022 for GAIN of £1061
    Matches with:
  • SECTION 104: 100 at cost basis of £100.5398
    Calculation: (100 * 111.2 - 5.02) - ( (100 * 100.5398) ) = 1061

TRANSACTIONS

15/05/2022 BOUGHT 100 of SHARE_A at £9.8 with £0.23 expenses
16/08/2022 SOLD 100 of SHARE_A at £12.8 with £1.54 expenses
15/05/2022 BOUGHT 100 of SHARE_B at £10.2 with £2.45 expenses
16/08/2022 SOLD 100 of SHARE_B at £11.8 with £4.97 expenses
15/05/2022 BOUGHT 100 of SHARE_C at £53.2 with £1.67 expenses
16/08/2022 SOLD 100 of SHARE_C at £49.3 with £2.86 expenses
15/05/2022 BOUGHT 100 of SHARE_D at £100.5 with £3.98 expenses
16/08/2022 SOLD 100 of SHARE_D at £111.2 with £5.02 expenses

ASSET EVENTS

NONE

LOGS

[INFO] Begin processing
[INFO] No pre-processing of transactions required for SHARE_D.
[INFO] Begin processing transactions for SHARE_D.
[INFO] Begin matching processor.
[INFO] Finished matching processor. Matched 0 and there are 1 disposals left.
[INFO] Finished processing transactions for SHARE_D. Created 1 tax events.
[INFO] No pre-processing of transactions required for SHARE_C.
[INFO] Begin processing transactions for SHARE_C.
[INFO] Begin matching processor.
[INFO] Finished matching processor. Matched 0 and there are 1 disposals left.
[INFO] Finished processing transactions for SHARE_C. Created 1 tax events.
[INFO] No pre-processing of transactions required for SHARE_B.
[INFO] Begin processing transactions for SHARE_B.
[INFO] Begin matching processor.
[INFO] Finished matching processor. Matched 0 and there are 1 disposals left.
[INFO] Finished processing transactions for SHARE_B. Created 1 tax events.
[INFO] No pre-processing of transactions required for SHARE_A.
[INFO] Begin processing transactions for SHARE_A.
[INFO] Begin matching processor.
[INFO] Finished matching processor. Matched 0 and there are 1 disposals left.
[INFO] Finished processing transactions for SHARE_A. Created 1 tax events.
[INFO] Finished processing

CALCULATIONS

The following H2 headings are values needed for the tax return.

Number of disposals

4

Disposal proceeds

(100 * 12.8 - 1.54) + (100 * 11.8 - 4.97) + (100 * 49.3 - 2.86) + (100 * 111.2 - 5.02) = 18495.61
// Proceeds from the summary table: £18510 (higher because it includes the fees)

Allowable costs

(100 * 9.8023) + (100 * 10.2245) + (100 * 53.2167) + (100 * 100.5398) = 17378.33
// The summary table does not include this value

Gains in the year, before losses

// Using the rounded values from the transaction list above
Gains (before losses): 298 + 152 + 1061 = 1511

// Using the exact decimal values
Gains (before losses): (100 * 12.8 - 1.54) - ( (100 * 9.8023) ) + (100 * 11.8 - 4.97) - ( (100 * 10.2245) ) + (100 * 111.2 - 5.02) - ( (100 * 100.5398) ) = 1511.81

Losses in the year

// Using the rounded values from the transaction list above
Losses: -395

// Using the exact decimal values
(100 * 49.3 - 2.86) - ( (100 * 53.2167) ) = -394.53

Gains, after losses (not required in the tax return)

// Option 1: Using rounded values (this is how the summary table value is calculated)
1511 - 395 = 1116

// Option 2: Using decimal values
1511.81 - 394.53 = 1117.28

// Option 3: Proceeds - allowable cost (practically the same as option 2)
18495.61 - 17378.33 = 1117.28
// If we were to use the proceeds value from the table: 18510 - 17378.33 = 1131.67

Questions

  • Should the total proceeds include or exclude transaction fees?
  • Can the summary table include an allowable cost column?
  • Can the calculator retain the decimal values for each transaction and only round the final gains value, instead of rounding each transaction and accumulating rounding errors?

CAPRETURN equalisation payments incorrectly applied

Hello,

I believe you are applying equalisation payments incorrectly. No specific shares or past purchases attract equalisation. Equalisation payments are considered a one off capital return on the date they are paid, which has the result of lowering your acquisition costs. Put another way, a one off adjustment to the running total pool cost and pool unit cost.

From your example, it is not "01/04/2020: Dividend equalisation of £50 on 15 shares". Instead it is simply "01/04/2020: Equalisation of £50".

From your example:

01/08/2019: BUY 10 at £100 (10 pool units, £1000 pool cost, £100 pool unit cost)
01/09/2019: SELL 5 at £105 (5 pool units, £500 pool cost, £100 pool unit cost, £25 capital gain)
01/01/2020: BUY 10 at £90 (15 pool units, £1400 pool cost, £93.3333 pool unit cost)
01/04/2020: Dividend equalisation of £50 (15 pool units, £1350 pool cost, £90 pool unit cost)
01/04/2020: Dividend income of £30 on 15 shares

01/06/2020: BUY 10 at £80 (25 pool units, £2150 pool cost, £86 pool unit cost)
01/07/2020: SELL 5 at £100 (20 pool units, £1720 pool cost, £86 pool unit cost, £70 capital gain)
01/04/2021: Dividend equalisation of £10 (20 pool units, £1710 pool cost, £85.5 pool unit cost)
01/04/2021: Dividend income of £40 on 20 shares

This also allows simplification of the input from:
CAPRETURN 01/04/2020 GB00B41YBW71 15.0 50.0

To:
CAPRETURN 01/04/2020 GB00B41YBW71 50.0

Regards,

Dan Dodex

Expenses not accounted for in calculation

Given the following transactions:

BUY 26/05/2022 SomeCompany 3063 3.21570356 49.25
BUY 26/05/2022 SomeCompany 3067 3.21095859 49.24
BUY 26/05/2022 SomeCompany 3067 3.21106945 49.24
BUY 26/05/2022 SomeCompany 3068 3.20996741 49.24
BUY 26/05/2022 SomeCompany 3067 3.21085099 49.24
BUY 26/05/2022 SomeCompany 3069 3.20900945 49.24
SELL 27/05/2022 SomeCompany 401 3.28127182 0
SELL 27/05/2022 SomeCompany 3000 3.28126 0
SELL 27/05/2022 SomeCompany 3000 3.28034333 0
SELL 27/05/2022 SomeCompany 3000 3.28126 0
SELL 27/05/2022 SomeCompany 3000 3.28126 0
SELL 27/05/2022 SomeCompany 3000 3.28484333 0
SELL 27/05/2022 SomeCompany 3000 3.28484333 0

Stamp Duty Paid: 295.45

Total Cost: 59385.82 + 295.45 = 59681.72

Total Disposal = 60397.22

Total Disposal - Total Cost = 715.95

CGT output estimates 1101 gain, so is not removing the stamp duty allowable costs:

1) SOLD 18401 of SomeCompany on 27/05/2022 for GAIN of £1011
Matches with:
  - SECTION 104: 18401 at cost basis of £3.22731
Calculation: (18401 * 3.28227922231509157111026574642682462909 - 0) - ( (18401 * 3.22731) ) = 1011

Incorrect matching in complex case

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.