Skip to content

Bizzaro/cad-capital-gains

 
 

Repository files navigation

Canadian Capital Gains CLI Tool - IBKR

Manually calculating your capital gains and tracking your adjusted cost base (ACB) can be tedious, especially with Excel. This CLI tool automates the calculation of your capital gains and ACB using a CSV file with your transaction details. You can easily copy the generated output into your preferred tax filing software.

Features:

  • Works with IBKR .csv annual export
  • Supports transactions with multiple different stock tickers in the same CSV file, and outputs them in separate tables.
  • Supports transactions in CAD, USD, EUR, and GBP. For non-CAD currencies, the daily exchange rate is fetched from the Bank of Canada.
  • Will automatically apply superficial capital loss rules when calculating your capital gains and ACB. This tool only supports full superficial capital losses, and does not support partial superficial losses. In sales with a superficial capital loss, the capital loss will be carried forward as prescribed by the CRA. A sale with a capital loss will be treated as superficial if it satisfies the following:
    • Shares with the same ticker were bought in the 61 day window (30 days before or 30 days after the sale)
    • There is a non-zero balance of shares sharing the same ticker at the end of the 61 day window (30 days after the sale)
  • Outputs the running adjusted cost base (ACB) for every transaction with a non-superficial capital gain/loss
  • Supports fractional shares

Installation

# To get the latest release
pip install <directory of clone>

CSV File Requirements

NOTE: This tool only supports calculating ACB and capital gains with transactions dating from May 1, 2007 and onwards.

To start, create a CSV file that will contain all of your transactions. In the CSV file, each line will represent a BUY or SELL transaction. Your transactions must be in order, with the oldest transactions coming first, followed by newer transactions coming later. The format is as follows:

<yyyy-mm-dd>,<description>,<stock_ticker>,<action(BUY/SELL)>,<quantity>,<price>,<commission>,<currency>

Here is a sample CSV file:

# sample.csv
2017-2-15,ESPP PURCHASE,GOOG,BUY,100,50.00,10.00,USD
2017-5-20,RSU VEST,GOOG,SELL,50,45.00,0.00,CAD

Usage

To show the CSV file in a nice tabular format you can run:

$ capgains show sample.csv
+------------+---------------+----------+----------+-------+---------+--------------+------------+
| date       | description   | ticker   | action   |   qty |   price |   commission |   currency |
|------------+---------------+----------+----------+-------+---------+--------------+------------|
| 2017-02-15 | ESPP PURCHASE | GOOG     | BUY      |   100 |   50.00 |        10.00 |        USD |
| 2017-05-20 | RSU VEST      | GOOG     | SELL     |    50 |   45.00 |         0.00 |        CAD |
+------------+---------------+----------+----------+-------+---------+--------------+------------+

To calculate the capital gains you can run:

$ capgains calc sample.csv 2017
GOOG-2017
[Total Gains = -1,028.54]
+------------+---------------+----------+-------+------------+----------+-----------+---------------------+
| date       | description   | ticker   | qty   |   proceeds |      ACB |   outlays |   capital gain/loss |
|------------+---------------+----------+-------+------------+----------+-----------+---------------------|
| 2017-05-20 | RSU VEST      | GOOG     | 50    |   2,250.00 | 3,278.54 |      0.00 |           -1,028.54 |
+------------+---------------+----------+-------+------------+----------+-----------+---------------------+

Your CSV file can contain transactions spanning across multiple different tickers. You can filter the above commands by running the following:

$ capgains calc sample.csv 2017 -t GOOG
$ capgains show sample.csv -t GOOG

For additional commands and options, run one of the following:

$ capgains --help
$ capgains <command> --help

You can take this output and plug it into your favourite tax software (Simpletax, StudioTax, etc) and verify that the capital gains/losses that the tax software reports lines up with what the output of this command says.

Contributing

If you would like to contribute, please read the CONTRIBUTING.md page

DISCLAIMER

You are responsible for the numbers produced by this tool. It has not been audited or verified by a third party. This is not tax advice or certified tax software. It is recommended to perform random spot checks of calculations and consult a CPA for all tax inquiries.

About

A CLI tool built using Python for calculating your capital gains and adjusted cost base (ACB) for Canadian taxes.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 100.0%