Skip to main content

A CLI tool for option pricing and Greeks calculation

Project description

Quant Greeks CLI Tool

CI

A lightweight command-line tool for calculating option prices and Greeks using Black-Scholes and Binomial models. Built for traders, quants, and finance students to analyze options risk and sensitivity directly from your terminal.


Features

  • Comprehensive Greeks: Delta, Gamma, Vega, Theta, Rho for Black-Scholes and Binomial (European/American)
  • Flexible Option Pricing: Black-Scholes and Binomial models with American/European support
  • Implied Volatility Solver: Calculate implied volatility given a market price
  • Dividend Yield Support: Pass continuous dividend yield with --q
  • Batch/Portfolio Processing: Process CSV/JSON and output table, CSV, or JSON
  • Parameter Sweep & Plotting: Analyze/visualize how Greeks change with any parameter and save as tables, CSV, JSON, or PNG plot
  • Put-Call Parity Checker: Verify arbitrage-free pricing with a simple CLI command
  • Robust CLI & Error Handling: Helpful messages, input validation, and usage hints
  • 100% Test Coverage: Core logic thoroughly tested, including CLI behaviors
  • CI/CD: GitHub Actions for continuous integration

Installation

From PyPI:

pip install quant-greeks-cli

Or from source:

git clone https://github.com/Patience-Fuglo/quant-greeks-cli.git
cd quant-greeks-cli
pip install -r requirements.txt
pip install .

Usage

Basic Greeks calculation:

quant-greeks --option_type call --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2

For help:

quant-greeks --help

Option Argument Guide

  • --option_type: "call" or "put"
  • --S: Spot price
  • --K: Strike price
  • --T: Time to maturity (years)
  • --r: Annual risk-free rate (decimal)
  • --sigma: Volatility (decimal)
  • --q: Continuous dividend yield (optional, default 0)

Example Features

  • Implied Volatility Calculation:

    python cli.py --implied_vol --option_type call --S 100 --K 100 --T 1 --r 0.05 --price 10
    

    Output:

    Implied volatility: 0.18797
    
  • Binomial Pricing (with American support):

    python cli.py --model binomial --option_type put --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2 --steps 200 --american
    
  • Pretty table/CSV/JSON/plot outputs

  • Parameter sweep:

    python cli.py sweep --param S --start 80 --end 120 --steps 5 --option_type call --K 100 --T 1 --r 0.05 --sigma 0.2 --output plot --plot_metric delta
    
    • --output plot: Save a PNG file (plot.png) of the sweep result in your working directory.
    • --plot_metric: Metric to plot on the y-axis (price, delta, gamma, vega, theta, rho).
  • Portfolio/batch processing:

    python cli.py batch --file my_options.csv --output table
    

Supported models and parameters:

  • --model: Choose binomial (default: black-scholes)
  • --steps: Number of steps for binomial (default: 100)
  • --american: Enable American-style exercise for binomial pricing

Put-Call Parity Checker

You can check put-call parity directly from the CLI:

python cli.py parity --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2 --q 0.03

Sample Output

Put-Call Parity holds: True

Output Formats

Choose how results are displayed or saved:

  • plain (default): One result per line
  • table: Formatted terminal table
  • csv: Save results for further analysis
  • json: Machine-readable output
  • plot: Save parameter sweep as PNG

Examples

Pretty table:

python cli.py price --option_type call --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2 --output table

CSV export:

python cli.py price --option_type call --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2 --output csv --csvfile myresults.csv

Classic (plain):

python cli.py price --option_type call --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2

Batch/Portfolio Processing

You can process multiple options at once from a CSV or JSON file using the batch subcommand.

Usage

python cli.py batch --file my_options.csv --output table
python cli.py batch --file my_options.json --output csv
  • Replace my_options.csv or my_options.json with your file path.
  • Use --output table, --output csv, or --output json to choose the output format.
  • Use --csvfile <filename> to specify the output CSV name (optional).

Example CSV File

option_type,S,K,T,r,sigma,q,model,steps,american
call,100,100,1,0.05,0.2,0.0,black-scholes,100,False
put,50,45,0.5,0.03,0.25,0.01,black-scholes,100,False
call,120,110,2,0.04,0.22,0.01,binomial,200,True
put,80,85,0.8,0.02,0.18,0.0,binomial,150,False

Example JSON File

[
  {"option_type":"call","S":100,"K":100,"T":1,"r":0.05,"sigma":0.2,"q":0.0,"model":"black-scholes","steps":100,"american":false},
  {"option_type":"put","S":50,"K":45,"T":0.5,"r":0.03,"sigma":0.25,"q":0.01,"model":"black-scholes","steps":100,"american":false}
]

Parameter Sweep & Plotting

You can analyze how Greeks and prices change as you vary a single parameter, and visualize the results.

Usage

python cli.py sweep --param <PARAM> --start <START> --end <END> --steps <N> --option_type <call|put> --S <S> --K <K> --T <T> --r <r> --sigma <sigma> [--q <q>] --output plot --plot_metric price
  • --param: S, K, T, r, sigma, or q
  • --plot_metric: price, delta, gamma, vega, theta, or rho

Output

  • PNG plot saved to plot.png
  • Table, CSV, or JSON output for further analysis

Advanced Testing and Coverage

This project includes a robust suite of automated tests, reflecting best practices in quantitative finance software development:

  • Comprehensive Unit and Integration Testing:
    All core option pricing functions (binomial, Black-Scholes, Greeks) are covered with a range of tests, including edge cases such as zero volatility, American vs. European options, and invalid parameter handling.

  • CLI and Batch Testing:
    The command-line interface is tested end-to-end for batch processing, file I/O, and user error handling.

  • Substantial Code Coverage:
    Recent test runs demonstrate major improvements in coverage:

    • binomial.py: Coverage increased from 3% to 85%
    • greeks.py: Coverage increased from 22% to 69%
    • All 14 tests pass, and the coverage report is now a meaningful indicator of code reliability.
  • Continuous Improvement:
    Tests are designed to make it easy to add new models and features with confidence. Coverage reports guide further development and ensure that new code is tested.

  • Tools Used:

    • pytest for test execution
    • pytest-cov for coverage measurement

Result:
This testing approach ensures that the codebase is reliable, maintainable, and ready for professional quantitative finance workflows.


See the /tests directory and the latest coverage report for details, or run pytest --cov=. to check coverage yourself.

Error Handling

Smart error messages for:

  • Missing/invalid arguments or parameter combinations
  • Incompatible option/model settings
  • Required parameters for implied volatility or sweep
  • File format validation for batch mode

Examples:

python cli.py price --option_type call --S -100 --K 100 --T 1 --r 0.05 --sigma 0.2
# Error(s): Stock price S must be positive.

python cli.py price --option_type call --S 100 --K 100 --T 1 --r 0.05 --sigma 0.2 --model black-scholes --american
# Error(s): Black-Scholes model does not support American options. Use binomial model with --american.

Testing

Run all tests using:

pytest

Check coverage:

pytest --cov=.

Generate HTML report:

pytest --cov=. --cov-report=html

Open htmlcov/index.html for details.

Test Coverage

  • All core logic for pricing and Greeks is tested, including edge cases and American options.
  • CLI behaviors (such as help and error messages) are included using subprocess.
  • Example test files:
    • tests/test_binomial.py (European and American, edge/exception cases)
    • tests/test_black_scholes.py (normal and error branches)
    • tests/test_greeks.py (normal and error branches)
    • tests/test_implied_vol.py (normal and error branches)
    • tests/test_cli.py (CLI help and error response)
  • CLI code itself is not directly unit tested, but its output and error handling are verified through CLI tests.

Contributing

Pull requests are welcome! Please add tests for any new features and follow the standard fork/branch/PR workflow.


License

MIT License


Author

Patience Fuglo

Project details


Download files

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

Source Distribution

quant_greeks_cli-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quant_greeks_cli-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file quant_greeks_cli-0.1.0.tar.gz.

File metadata

  • Download URL: quant_greeks_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for quant_greeks_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6564bde0df33a11105034eda6ce7bd077c4d99534f012ee93be041a9d8fbddfd
MD5 5e6d5f82820699ca47bda5db08268312
BLAKE2b-256 a7ffc3f6a248aa8afcd9b5489434372bfc6282e218c9ca1a347172daf52b957c

See more details on using hashes here.

File details

Details for the file quant_greeks_cli-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quant_greeks_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e097746c6607b2a564c9d17cebc23573795a0b1b917457fd373a0a654aa200a
MD5 abe73bbbc64bfe651c74e5b413ed1e47
BLAKE2b-256 93d642d4b94ba611fd8da4ce5d80660d0987dbfdbf46ff02ae45e1ee74add269

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page