OmidTahouri/capital-gains-calculator
UK capital gains tax calculator which supports transaction history from different brokers
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.
The PDF is broken down in CGT and interest/dividend sections with an Overall summary for totals at the end.
The interests are reported once per month per broker to avoid long reports with daily interest brokers.
Report example
Installation
Install it with pipx (or regular pip):
pipx install cgt-calcPrerequisites
- Python 3.9 or above.
pdflatexis required to generate the report.
Install LaTeX
MacOS
brew install --cask mactex-no-guiDebian based
apt install texlive-latex-baseWindows
Usage
- You need to supply transaction history for each account you have. See below for per-broker instructions. The history needs to contain all transactions since the beginning, or at least since you first acquired the shares owned during the relevant tax years.
- Once you have all your transactions from all your brokers you need to supply them together, for example to generate the report for the tax year 2020/21:
cgt-calc --year 2020 --schwab schwab_transactions.csv --trading212 trading212/ --mssb mmsb_report/- Run
cgt-calc --helpfor the full list of settings. - If your broker is not listed below you can still try to use the raw format. We also welcome PRs for new parsers.
Broker-specific instructions
๐ฆ Instructions for Charles Schwab
You will need:
- Exported transaction history in CSV format.
Schwab only allows to download transaction for the last 4 years. If you require more, you can download the history in 4-year chunks and combine them.
See example. - Exported transaction history from Schwab Equity Awards in CSV format.
Only applicable if you receive equity awards in your account (e.g. for Alphabet/Google employees). Follow the same procedure as in the normal transaction history but selecting your Equity Award account.
Example usage for the tax year 2020/21:
cgt-calc --year 2020 --schwab schwab_transactions.csv --schwab-award schwab_awards.csvNote: For historic reasons, it is possible to provide the Equity Awards history in JSON format with --schwab_equity_award_json. Instructions are available at the top of this parser file. Please use the CSV method above if possible.
๐ฆ Instructions for Trading212
You will need:
- Exported transaction history from Trading 212.
You can provide a folder containing several files since Trading 212 limit the statements to 1 year periods.
See example.
Example usage for the tax year 2024/25:
cgt-calc --year 2024 --trading212 trading212_trxs_dir/๐ฆ Instructions for Morgan Stanley
You will need:
- 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.
See example.
Example usage for the tax year 2024/25:
cgt-calc --year 2024 --mssb morgan_stanley_trxs_dir/๐ฆ Instructions for Sharesight
You will need:
- 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.
- See example.
Comments:
-
Sharesight aggregates transactions from multiple brokers, but doesn't necessarily have balance information.
Use the--no-balance-checkflag to avoid spurious errors. -
Since there is no direct support for equity grants, add
Stock Activityas part of the comment associated with any vesting transactions - making sure they have the grant price filled (see example).
Example usage for the tax year 2024/25:
cgt-calc --year 2024 --no-balance-check --sharesight sharesight_trxs_dir/๐ฆ Instructions for Vanguard
You will need:
- Exported transaction history from Vanguard.
Vanguard can generate a report in Excel format with all transactions across all periods of time and all accounts (ISA, GA, etc). Grab the ones you're interested into (normally GA account) and put them in a single CSV file.
See example.
Example usage for the tax year 2024/25:
cgt-calc --year 2024 --vanguard vanguard.csv๐ฆ Instructions for RAW format
You will need:
- CSV using the RAW format. If your broker isn't natively supported you might choose to convert whatever report you can produce into this basic format.
See example
Example usage for the tax year 2024/25:
cgt-calc --year 2024 --raw sharesight_trxs_dir/Extra files/options that might be needed
- CSV file with initial stock prices in USD. This is needed under special circumstances for example at the moment of vesting, split, etc.
initial_prices.csvcomes pre-packaged, you need to use the same format. The program will inform when some required price is missing. - (Automatic) Monthly exchange rates prices from gov.uk. This is needed to convert foreign currencies into GBP amounts.
exchange_rates.csvgets generated automatically using HMRC API, you need to use the same format if you want to override it. - Spin-off file. Supplies extra information needed for spin-offs transactions through
--spin-offs-file. - Interest fund tickers. To calculate dividends on bond funds/ETF properly you need to pass the comma separated list of funds ticker that are taxed as interest instead of dividends, using
--interest-fund-tickersCLI option.
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..
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 installto install all dependencies. - Then activate
pre-commithook:poetry run pre-commit install
You can also run all linters and tests manually with this command:
poetry run pre-commit run --all-files