IRS asset FIFO calculator

Documentation Status

Tax calculator that tracks capital gains from multiple purchases and sales. This program uses a CSV file as input.

This file is called “asset_tx.csv” in the published example, but any name can be be used, using this name in the python call. The file has the following header: “Date”, “Asset”, “Amount (asset)”, “Sell price ($)”, “Buy price ($)”, “Account number”, “Entity”, “Notes”, “Remaining”

Table of Contents

What this project does

This repository implements a small Python tool to calculate IRS-style capital gains using the FIFO (First In, First Out) method and produce Form 8949–style output.

Given a CSV of asset transactions (buys, sells, exchanges, transfers), the library:

  1. Groups related rows by Tx Index into logical “blocks” (one trade).

  2. Parses each block into:

    • Buy side (what you acquired)

    • Sell side (what you disposed of)

    • Fees (possibly in one or more assets)

  3. Maintains a FIFO ledger of “lots” for each asset (amount, price, cost basis, date).

  4. For each sale, consumes the oldest lots first to compute:

    • Cost basis

    • Proceeds

    • Gain or loss

  5. Writes the result as rows suitable for Form 8949.

FIFO in one paragraph

Under FIFO, the earliest purchased units are considered sold first. If you bought 10 NVDA on January 1 and 5 NVDA on February 1, then sell 12 NVDA on March 1, the sale is treated as:

  • 10 units from the January lot, and

  • 2 units from the February lot.

Each slice gets a proportional share of the total proceeds, and its own cost basis and gain/loss. This tool automates that book-keeping and emits one Form 8949 row per “slice”.

For a more detailed explanation (with tables and numeric examples), see docs/fifo_overview.md.

Installation

No installation is required.

Quick start

  1. Put your transactions in asset_tx.csv with the header: Date, Tx Index, Asset, Amount (asset), Sell price ($), Buy price ($), Type, ...

  2. Run from CLI:

   cd src
   python -m irs_asset_fifo_calculator.calculate_taxes

Technologies

IRS asset FIFO calculator uses the following technologies and tools:

  • Python

  • Sphinx

Development

Building the docs

In order to create Sphinx documentation from the docstrings in PyCharm, a new run task must be created: Run > Edit Configurations… > + (top-left) > Sphinx task. In the window that opens, name the Sphinx task in the “Name” field, select “html” under the “Command:” dropdown, select the docs folder in the root folder in the “Input:” field, and select the docs/_build folder in the “Output:” field. If the docs or docs/_build folder do not already exist, they will perhaps need to be created. The Sphinx documentation can now be created by going to Run > Run… and selecting the Sphinx task name.

Contributing

To contribute to the development of IRS asset FIFO calculator, follow the steps below:

  1. Fork IRS asset FIFO calculator from https://github.com/elliottbache/irs_asset_fifo_calculator/fork

  2. Create your feature branch (git checkout -b feature-new)

  3. Make your changes

  4. Commit your changes (git commit -am 'Add some new feature')

  5. Push to the branch (git push origin feature-new)

  6. Create a new pull request

Contributors

Here’s the list of people who have contributed to IRS asset FIFO calculator:

  • Elliott Bache – elliottbache@gmail.com

The IRS asset FIFO calculator development team really appreciates and thanks the time and effort that all these fellows have put into the project’s growth and improvement.

Author

  • Elliott Bache – elliottbache@gmail.com

Change log

  • 0.1.0

    • First public FIFO release

License

IRS asset FIFO calculator is distributed under the MIT license.