mattjgalloway / cgtcalc

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

Incorrect dividend acquisition matching #1

Closed adamgibbins closed 3 years ago

adamgibbins commented 3 years ago

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.

mattjgalloway commented 3 years ago

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:

Is this because the ex-div date is between 21/02/2018 and 21/03/2018? Use the ex-div date for the date.

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.

It is for CGT purposes. You have no gain, or loss, so nothing to report.

This calculator doesn't do anything related to income tax you might have to pay on dividends.

You probably need to research about when dividends are taken into account for CGT purposes. Note that it's ONLY on accumulation funds. And even then you need to research equalisation payments as well (which this calculator supports).

mattjgalloway commented 3 years ago

I’ll close this out, but if you still think there is an issue then please re-open @adamgibbins!