Command-line (CLI) application that calculates the tax owed on profits or losses from stock market transactions.
The application processes sequences of buy and sell operations, maintaining an in-memory portfolio with the current share quantity, weighted-average unit cost, and accumulated losses.
To clone the repository using the command line, run:
git clone https://github.com/gustavofreze/capital-gains.gitTo install project dependencies locally, run:
make configureRun the CLI reading operations from stdin and writing the JSON result to stdout:
make calculate < use_case.txtExample use_case.txt:
[{"operation":"buy", "unit-cost":10.00, "quantity": 10000},
{"operation":"sell", "unit-cost":50.00, "quantity": 10000},
{"operation":"buy", "unit-cost":20.00, "quantity": 10000},
{"operation":"sell", "unit-cost":50.00, "quantity": 10000}]You can also paste input directly:
make calculate <<< '[{"operation":"buy", "unit-cost":10.00, "quantity": 10000},
{"operation":"sell", "unit-cost":50.00, "quantity": 10000},
{"operation":"buy", "unit-cost":20.00, "quantity": 10000},
{"operation":"sell", "unit-cost":50.00, "quantity": 10000}]'or
make calculate << 'EOF'
[{"operation":"buy", "unit-cost":10.00, "quantity": 10000},
{"operation":"sell", "unit-cost":50.00, "quantity": 10000},
{"operation":"buy", "unit-cost":20.00, "quantity": 10000},
{"operation":"sell", "unit-cost":50.00, "quantity": 10000}]
EOFAll examples above will produce the same result:
[{"tax":0.00},{"tax":80000.00},{"tax":0.00},{"tax":60000.00}]For more details, see the Use cases documentation.
Run all tests with coverage:
make test Run static code analysis:
make review Open static analysis reports (e.g., coverage, lints) in the browser:
make show-reports You can check other available commands by running
make help.