Skip to main content

Capital gains calculator

Project description


Capital gains calculator.

This transforms transaction histories into a format suitable for IRS form 8949, taking care of wash sale adjustments.

Note: The logic is ignorant of share type, and cannot account for e.g. bargain elements for ESPP, ISO, and NSO. You must enter the appropriate cost basis depending on your situation, e.g. the fair market value on exercise date for ESPP disqualifying dispositions.

See also nkouevda/estimated-taxes.


pip install capital-gains


usage: capital-gains [<options>] [--] <input file>

Capital gains calculator

optional arguments:
  -h, --help            show this help message and exit
  -d <n>, --decimal-places <n>
                        round $ to <n> decimal places; default: 0
  -s <n>, --shares-decimal-places <n>
                        round shares to <n> decimal places; default: 0
  -t, --totals          output totals
  -v, --verbose         verbose output
  -V, --version         show program's version number and exit

Input Format

See input/example.csv.

Each entry has the following format:


Buys have positive shares; sells have negative shares. price and fee are always positive. fee and name are optional. A sell without a name will sell all open lots FIFO; a sell with a name will only sell lots with the same name. Thus name can be used to specify sell orders other than FIFO.


capital-gains -t input/example.csv > output/example.txt


  • STCG vs. LTCG


MIT License

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for capital-gains, version 1.0.5
Filename, size File type Python version Upload date Hashes
Filename, size capital_gains-1.0.5-py3-none-any.whl (7.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size capital-gains-1.0.5.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page