Skip to main content

greeks-package

Black-Scholes option Greeks made easy

CI codecov Python 3.10+ License: MIT Open In Colab nbviewer

A Python library for options analytics built on NumPy/SciPy:

  • All 13 Black-Scholes-Merton Greeks (first to third order), with dividend yields.
  • Prices: Black-Scholes-Merton, Monte Carlo, and American options by finite differences.
  • Implied volatility: one option, or recomputed for a whole chain.
  • Interactive plots: Greek surfaces, volatility smiles, term structures.
  • Multi-leg strategy builder: exact breakevens, position Greeks, payoff diagrams.

Option chains download from Yahoo Finance, or you can bring your own data.

Disclaimer: market data comes from Yahoo Finance via the unofficial yfinance library and is delayed. Outside market hours, bid/ask and implied volatility can be unreliable. This package is for education and research — not investment advice.

Install

pip install greeks-package

Python ≥ 3.10. Dependencies: NumPy, pandas, SciPy, yfinance, Plotly.

Quick start

import greeks_package as gp

# 1. Plain numbers — no data or internet needed (Hull, Example 15.6)
gp.bs_price(42, 40, 0.2, 0.1, 0.5)                       # 4.76
gp.bs_greeks(42, 40, 0.2, 0.1, 0.5)                      # all 13 Greeks as a Series
gp.implied_vol(4.76, 42, 40, 0.1, 0.5)                   # ≈ 0.20

# 2. A live option chain + every Greek, vectorized
opts = gp.download_options("AAPL", opt_type="all", max_days=30)
full = gp.combine(opts, gp.greeks(opts, "AAPL"))         # calls and puts priced by type
print(full[["strike", "option_type", "lastPrice", "Delta", "Gamma", "Theta"]].head())

# 3. American options (finite differences)
gp.FDM(100, 100, 0.2, 0.05, 1.0, option_type="put", bs=True)   # shows the early-exercise premium
fdm = gp.fdm_chain(opts, "AAPL")                         # the whole chain in one pass

More examples

# Recompute stale Yahoo IVs from the bid/ask mid, then reprice
opts["impliedVolatility"] = gp.implied_vol_chain(opts, "AAPL")

# Scenario analysis: Greeks if the stock were 5% lower
lower = gp.greeks(opts, spot=0.95 * gp.get_spot("AAPL"))

# Dividends
opts["BS_div"] = opts.apply(gp.bsm_price, axis=1, ticker="AAPL", q=0.005)

# Several tickers at once — each row uses its own ticker's spot
multi = gp.multi_download(["AAPL", "MSFT"], opt_type="c", max_days=30)
multi_greeks = gp.greeks(multi)

# Index options settle at the open: measure time to expiry to 09:30
spx = gp.download_options("^SPX", opt_type="all", expiry_time="09:30")

# Strategy analysis
near = opts["expiry"].min()
res = gp.strategy_builder(opts, [
    {"strike": 200, "option_type": "call", "action": "buy",  "contracts": 1, "expiry": near},
    {"strike": 210, "option_type": "call", "action": "sell", "contracts": 1, "expiry": near},
], ticker="AAPL", greeks=True, plot=True)
res.max_profit, res.breakevens, res.net_greeks["Delta"]

# Plots
gp.vol_curve(opts, "AAPL")
gp.surface_plot(opts, "AAPL", option_type="c", z="gamma", template="plotly_white")

What's inside

Group Functions
Data download_options, multi_download, combine (alias comb), get_spot, refresh_spot
Greeks greeks, first_order, second_order, third_order, bs_greeks, and delta vega theta rho gamma vanna volga veta charm color speed ultima zomma
Pricing bsm_price, bs_price, monte_carlo_price, implied_vol, implied_vol_chain, FDM (alias fdm_price), fdm_chain, fdm_row
Plots surf_scatter, surface_plot, greek_plot, iv_plot, oi_plot, vol_curve
Strategy strategy_builder → StrategyResult, identify_strategy, validate_strategy

Run gp.help() for a grouped overview, gp.help("pricing") for one group, or gp.help(gp.FDM) for full documentation.

Conventions

  • Units: Theta is per calendar day, Vega per volatility point, Rho per 1% rate. Charm, Color and Veta are per year.
  • Spot price: comes from spot= if given, otherwise the row's Stock Price column, otherwise ticker (or the row's Ticker column).
  • Option type: option_type=None uses each row's option_type column.
  • Arguments: everything after ticker is keyword-only.
  • Time to expiry: Days to Expiry counts to the 4 pm New York close (configurable with expiry_time).

Documentation

Document Contents
USAGE.md practical guide: every function, bring-your-own-data, troubleshooting, migrating from 1.x
docs/methodology.md formulas and intuition for every Greek, assumptions, FDM method, worked textbook examples
docs/ Sphinx site with the full API reference (pip install -e ".[docs]", then python -m sphinx docs docs/_build/html)
greeks_package_demo.ipynb runnable walkthrough (Colab · nbviewer)
CHANGELOG.md release history

Accuracy

  • Every Greek is tested against finite differences, for calls and puts, with and without dividends.
  • Prices are tested against textbook values (Hull) and put-call parity, plus property-based no-arbitrage checks on thousands of random inputs.
  • The FDM solver is tested against QuantLib and a 20,000-step binomial tree. At the default grid, prices are within about 0.05% (typically 0.001–0.003 in absolute terms, more for long-dated or high-volatility options). At NAS=400, NTS=2000 they are within about 0.01%.

Citing

If you use this package in coursework or research, please cite it. GitHub's "Cite this repository" button reads CITATION.cff.

Contributing

Bug reports and pull requests are welcome. See CONTRIBUTING.md for setup, checks, and guidelines.

License

MIT. See LICENSE. Created by JR Concepcion.

Metadata

Release files for greeks-package 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for greeks-package 2.0.0
File Size Uploaded Provenance Actions
greeks_package-2.0.0.tar.gz 96.0 kB Without provenance Details for greeks_package-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for greeks-package 2.0.0
File Interpreter ABI Platform Actions
greeks_package-2.0.0-py3-none-any.whl Python 3 none any Details for greeks_package-2.0.0-py3-none-any.whl

Total release size: 144.6 kB

Release files / greeks_package-2.0.0.tar.gz

Download URL greeks_package-2.0.0.tar.gz
Size 96.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f3c3ed44bea69a124a681d8a0a8eb606243cfdae852282c00adf08eb513c4a1c
BLAKE2b-256 checksum
How to use checksums
494a2f043f6e50add5af9ee35d4d81ef3d04858ce722678f4494cb5b977e433c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / greeks_package-2.0.0-py3-none-any.whl

Download URL greeks_package-2.0.0-py3-none-any.whl
Size 48.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b16ec4e589efe2c03f2defa4f8485fa089e6ecefca0e8dbbb63ad0ce560f7d1
BLAKE2b-256 checksum
How to use checksums
6edb69dbbb2f023ad3601fea5db64f090a371cc49ccc68781f4da7ab5f0d58ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Security for greeks-package 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page