UK capital gains tax calculator for Charles Schwab and Trading 212 accounts
Project description
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
Installation
Install it with pipx (or regular pip):
pipx install cgt-calc
Prerequisites
- Python 3.8 or above.
pdflatex
is required to generate the report.- [Optional] Docker
Install LaTeX
MacOS
brew install --cask mactex-no-gui
Debian based
apt install texlive-latex-base
Windows
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:
-
Exported transaction history from Schwab in CSV format since the beginning. Or at least since you first acquired the shares, which you were holding during the tax year. Schwab only allows to download transaction for the last 4 years so keep it safe. After that you may need to restore transactions from PDF statements. See example.
-
Exported transaction history from Schwab Equity Awards (e.g. for Alphabet/Google employees) since the beginning (Note: Schwab now allows for the whole history of Equity Awards account transactions to be downloaded). These are to be downloaded in JSON format. Instructions are available at the top of the parser file.
-
Exported transaction history from Trading 212. You can use several files here since Trading 212 limit the statements to 1 year periods. See example.
-
Exported transaction history from Morgan Stanley. Since Morgan Stanley generates multiple files in a single report, please specify a directory produced from the report download page.
-
Exported transaction history from Sharesight Sharesight is a portfolio tracking tool with support for multiple brokers.
You will need the "All Trades" and "Taxable Income" reports since the beginning. Make sure to select "Since Inception" for the period, and "Not Grouping". Export both reports to Excel or Google Sheets, save as CSV, and place them in the same folder.
Sharesight aggregates transactions from multiple brokers, but doesn't necessarily have balance information. Use the
--no-balance-check
flag to avoid spurious errors.Since there is no direct support for equity grants, add
Stock Activity
as part of the comment associated with any vesting transactions - making sure they have the grant price filled. -
CSV file with initial stock prices in USD at the moment of vesting, split, etc.
initial_prices.csv
comes pre-packaged, you need to use the same format. -
(Optional) Monthly exchange rates prices from gov.uk.
exchange_rates.csv
gets generated automatically using HMRC API, you need to use the same format if you want to override it.
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.
- For local testing you need to install it.
- After that run
poetry install
to install all dependencies. - Then activate
pre-commit
hook:poetry run pre-commit install
You can also run all linters and tests manually with this command:
poetry run pre-commit run --all-files
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cgt_calc-1.13.0.tar.gz
.
File metadata
- Download URL: cgt_calc-1.13.0.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.8.18 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9a0c1795058275deae83232b0096a92af2ebc7a83371e4619c79949b969f29e |
|
MD5 | 3d48c426d64346fb2b42716207c99a6b |
|
BLAKE2b-256 | a7d620253d9b2c8daf3a6980c25c6e9a922c66a525d07e79a11256c036322bb7 |
File details
Details for the file cgt_calc-1.13.0-py3-none-any.whl
.
File metadata
- Download URL: cgt_calc-1.13.0-py3-none-any.whl
- Upload date:
- Size: 45.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.8.18 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9e2dd47c810fc7859944ba90d2d53fd3cefa6ec837cd33eeec41560bc16cbf4 |
|
MD5 | 02b924c983a5676a044afce00d83c5b8 |
|
BLAKE2b-256 | fb408d8339bed20012b8fe782fb72bbdf50a97d9fcb094c53fa60540d4e09448 |