Metadata-Version: 2.4
Name: greeks-package
Version: 2.0.0
Summary: Black-Scholes option Greeks made easy - all 13 Greeks, implied volatility, and fast American option pricing (FDM)
Author-email: JR Concepcion <jr1concepcion@gmail.com>
Maintainer-email: JR Concepcion <jr1concepcion@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/JRCon1/greeks-package
Project-URL: Documentation, https://github.com/JRCon1/greeks-package/tree/main/docs
Project-URL: Repository, https://github.com/JRCon1/greeks-package
Project-URL: Changelog, https://github.com/JRCon1/greeks-package/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/JRCon1/greeks-package/issues
Project-URL: Tutorial (v0.1.0), https://youtu.be/geyCTGodXQk?si=zT3s4Gf2bMmGQk4I
Keywords: options,greeks,black-scholes,finance,derivatives,quantitative,trading,risk-management,delta,gamma,vega,theta,volatility,implied-volatility,options-pricing,american-options,finite-difference
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: scipy>=1.10
Requires-Dist: yfinance>=0.2
Requires-Dist: plotly>=5.19
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: hypothesis>=6.0; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: pandas-stubs; extra == "dev"
Requires-Dist: pyflakes>=3.0; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: jupyter>=1.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=7.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=2.0; extra == "docs"
Requires-Dist: myst-parser>=2.0; extra == "docs"
Dynamic: license-file

# greeks-package

**Black-Scholes option Greeks made easy**

[![CI](https://github.com/JRCon1/greeks-package/actions/workflows/ci.yml/badge.svg)](https://github.com/JRCon1/greeks-package/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/JRCon1/greeks-package/branch/main/graph/badge.svg)](https://codecov.io/gh/JRCon1/greeks-package)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JRCon1/greeks-package/blob/main/greeks_package_demo.ipynb)
[![nbviewer](https://img.shields.io/badge/render-nbviewer-orange.svg)](https://nbviewer.org/github/JRCon1/greeks-package/blob/main/greeks_package_demo.ipynb)

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

```bash
pip install greeks-package
```

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

## Quick start

```python
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

```python
# 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](USAGE.md) | practical guide: every function, bring-your-own-data, troubleshooting, migrating from 1.x |
| [docs/methodology.md](docs/methodology.md) | formulas and intuition for every Greek, assumptions, FDM method, worked textbook examples |
| [docs/](docs/) | Sphinx site with the full API reference (`pip install -e ".[docs]"`, then `python -m sphinx docs docs/_build/html`) |
| [greeks_package_demo.ipynb](greeks_package_demo.ipynb) | runnable walkthrough ([Colab](https://colab.research.google.com/github/JRCon1/greeks-package/blob/main/greeks_package_demo.ipynb) · [nbviewer](https://nbviewer.org/github/JRCon1/greeks-package/blob/main/greeks_package_demo.ipynb)) |
| [CHANGELOG.md](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](CITATION.cff).

## Contributing

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

## License

MIT. See [LICENSE](LICENSE). Created by **JR Concepcion**.
