KapJI / capital-gains-calculator

UK capital gains tax calculator which supports transaction history from different brokers
MIT License
112 stars 42 forks source link
capital-gains-calculator schwab trading212

CI PyPI version

UK capital gains calculator

Calculate capital gains tax by transaction history exported from Charles Schwab, Trading 212 and Morgan Stanley. Generate PDF report with calculations.

Automatically convert all prices to GBP and apply HMRC rules to calculate capital gains tax: "same day" rule, "bed and breakfast" rule, section 104 holding.

Report example

calculations_example.pdf

Installation

Install it with pipx (or regular pip):

pipx install cgt-calc

Prerequisites

Install LaTeX

MacOS

brew install --cask mactex-no-gui

Debian based

apt install texlive-latex-base

Windows

Install MiKTeX.

Docker

These steps will build and run the calculator in a self-contained environment, in case you would rather not have a systemwide LaTeX installation (or don't want to interfere with an existing one). The following steps are tested on an Apple silicon Mac and may need to be slightly modified on other platforms. With the cloned repository as the current working directory:

$ docker buildx build --platform linux/amd64 --tag capital-gains-calculator .

Now you've built and tagged the calculator image, you can drop into a shell with cgt-calc installed on $PATH. Navigate to where you store your transaction data, and run:

$ cd ~/Taxes/Transactions
$ docker run --rm -it -v "$PWD":/data capital-gains-calculator:latest
a4800eca1914:/data# cgt-calc [...]

This will create a temporary Docker container with the current directory on the host (where your transaction data is) mounted inside the container at /data. Follow the usage instructions below as normal, and when you're done, simply exit the shell. You will be dropped back into the shell on your host, with your output report pdf etc..

Usage

You will need several input files:

Then run (you can omit the brokers you don't use):

cgt-calc --year 2020 --schwab schwab_transactions.csv --trading212 trading212/ --mssb mmsb_report/

See cgt-calc --help for the full list of settings.

Disclaimer

Please be aware that I'm not a tax adviser so use this data at your own risk.

Contribute

All contributions are highly welcomed. If you notice any bugs please open an issue or send a PR to fix it.

Feel free to add new parsers to support transaction history from more brokers.

Testing

This project uses Poetry for managing dependencies.

You can also run all linters and tests manually with this command:

poetry run pre-commit run --all-files