mattjgalloway / cgtcalc

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

Support currency conversion #14

Open samfreedman opened 1 year ago

samfreedman commented 1 year ago

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.

mattjgalloway commented 1 year ago

Yes, this would be nice. However would need to assume there's a network connection present, and fetch via some API or screen scraping. From what I've found, there's no decent APIs that are free, and screen scraping I'm not particularly up for maintaining that as it will change from time to time. Also generally not keen on requiring an internet connection.

An alternative would be users providing a table with currency conversions (date and conversion factor). Which is better, but would require people to create such a table.

Personally what I do here, is I keep all my records in GBP, and do the conversion around the time I do the transaction - usually once I've got the trade confirmation. And then I have all my records in GBP anyway. That's what I would recommend others to do.

deed02392 commented 9 months ago

Here's a Python implementation using the free API, provided by HMRC themselves: https://github.com/KapJI/capital-gains-calculator/blob/main/cgt_calc/currency_converter.py

It actually generates a local cache of exchange rates, using monthly averages.