Skip to content

Command-line (CLI) application that calculates the tax owed on profits or losses from stock market transactions.

License

Notifications You must be signed in to change notification settings

gustavofreze/capital-gains

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Capital gains

License

Overview

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.

Use cases

Installation

Repository

To clone the repository using the command line, run:

git clone https://github.com/gustavofreze/capital-gains.git

Configuration

To install project dependencies locally, run:

make configure

Execution

Run the CLI reading operations from stdin and writing the JSON result to stdout:

make calculate < use_case.txt

Example 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}]
EOF

All 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.

Tests

Run all tests with coverage:

make test 

Review

Run static code analysis:

make review 

Reports

Open static analysis reports (e.g., coverage, lints) in the browser:

make show-reports 

You can check other available commands by running make help.

About

Command-line (CLI) application that calculates the tax owed on profits or losses from stock market transactions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published