Skip to main content

Fast options pricing, Greeks, and implied volatility for Black-76, Black-Scholes, and Black-Scholes-Merton. Rust core.

Project description

OpenGreeks

Fast options pricing & Greeks for Python — Rust core, drop-in for vollib / py_vollib.

pip install opengreeks

Up to 183× faster than vollib. Bit-identical Greeks. One dependency.

OpenGreeks reimplements the Black-76, Black-Scholes, and Black-Scholes-Merton pricing paths in zero-dependency Rust, exposed through PyO3 with the same function names and signatures as py_vollib / vollib. Migration is a one-line import swap; the math is unchanged.

Headline speedups vs py_vollib==1.0.1

Workload py_vollib OpenGreeks Speedup
Implied volatility, single call 27.7 µs 0.50 µs 55×
Black-76 chain — vega × 177 strikes 262 µs 4.3 µs 61×
Black-76 chain — all-5 Greeks × 200 options ~3.5 ms ~45 µs ~80×
Black-76 chain — IV × 177 strikes 4.22 ms 0.26 ms 16×
Black-76 price (scalar) 3.83 µs 0.33 µs 11×
Black-76 theta (scalar) 5.79 µs 0.33 µs 17×
Black-Scholes IV (scalar) 17.8 µs 0.50 µs 35×
BSM IV (scalar) 17.7 µs 0.50 µs 35×

Against vollib==1.0.7 (latest canonical) the wins grow further on Greeks chains: delta 110×, vega 183×, delta on BSM chain 95× (vollib 1.0.7 added domain-check overhead that opengreeks skips).

A full NIFTY option chain refresh (~200 options, all 5 Greeks + IV) drops from ~5 ms in py_vollib to ~50 µs in OpenGreeks — the difference between "saturates a core at 100 Hz" and "uses 6% of one core."

Parity that lets you trust the swap

29 edge cases × 3 models × 7 functions each, validated against both py_vollib==1.0.1 and vollib==1.0.7:

Greek max abs error vs vollib
delta, gamma, vega, theta, rho 0.0e+00 — bit-for-bit identical
price 1.4e-12 (rel 1.7e-14, ~14 digits)
IV (well-conditioned) 8.6e-10

Textbook anchors (Hull 13.6, Hull 17.1, Haug page 4) all pass. Full report: bench/RESULTS.md.

One dependency, not seven

Package Runtime dependencies
pip install vollib py_lets_be_rational, cody_special, piecewise_rational, simplejson, numpy, pandas, scipy
pip install opengreeks numpy

No pandas, no scipy, no Cython build hell, no _testcapi import errors on minimal Python distributions.


Inspired by py_vollib and vollib by Gammon Capital LLC — same function names, same argument order, same numerical conventions. OpenGreeks reimplements the pricing math in Rust to deliver the speed and dependency wins above without changing any of the math.

Model OpenGreeks submodule vollib equivalent
Black-76 (futures options) opengreeks.black76 vollib.black
Black-Scholes (no dividends) opengreeks.black_scholes vollib.black_scholes
Black-Scholes-Merton (dividends) opengreeks.black_scholes_merton vollib.black_scholes_merton

Function names, argument order, and numerical conventions (vega × 0.01, theta / 365, rho × 0.01) match vollib exactly.


Quick start

Black-76 (futures / NIFTY options)

from opengreeks.black76 import black, implied_volatility, delta, gamma, vega, theta, rho

F, K, t, r, sigma = 22000.0, 22000.0, 30/365, 0.07, 0.18
price = black('c', F, K, t, r, sigma)        # 450.27
iv    = implied_volatility(price, F, K, r, t, 'c')   # 0.18
d     = delta('c', F, K, t, r, sigma)
g     = gamma('c', F, K, t, r, sigma)
v     = vega ('c', F, K, t, r, sigma)
th    = theta('c', F, K, t, r, sigma)
rh    = rho  ('c', F, K, t, r, sigma)

Black-Scholes (equity, no dividend)

from opengreeks.black_scholes import black_scholes, implied_volatility, delta

price = black_scholes('c', 100.0, 90.0, 0.5, 0.01, 0.20)  # 12.111581

Black-Scholes-Merton (equity with continuous dividend yield)

from opengreeks.black_scholes_merton import black_scholes_merton, implied_volatility, delta

price = black_scholes_merton('p', 100.0, 95.0, 0.5, 0.10, 0.20, 0.05)  # 2.4648 (Haug p.4)

Chain-wide computation (NumPy batch)

For option-chain analytics, use the *_array variants — one PyO3 boundary crossing, internal tight loop:

import numpy as np
from opengreeks import black76

K = np.linspace(20000.0, 24000.0, 200)
F = np.full_like(K, 22000.0)
t = np.full_like(K, 30/365)
s = np.full_like(K, 0.18)

prices = black76.black_array('c', F, K, t, 0.07, s)
ivs    = black76.implied_volatility_array(prices, F, K, 0.07, t, 'c')
deltas = black76.delta_array('c', F, K, t, 0.07, s)

Migrating from py_vollib / vollib

The function signatures are byte-identical. Migration is a one-line import swap.

Before:

from py_vollib.black.implied_volatility import implied_volatility as black_iv
from py_vollib.black.greeks.analytical import delta as black_delta, gamma as black_gamma

After:

from opengreeks.black76 import implied_volatility as black_iv
from opengreeks.black76 import delta as black_delta, gamma as black_gamma

The aliases (as black_iv etc.) keep the rest of your code unchanged.

Old import New import
from py_vollib.black import black from opengreeks.black76 import black
from py_vollib.black.implied_volatility import implied_volatility from opengreeks.black76 import implied_volatility
from py_vollib.black.greeks.analytical import delta, gamma, vega, theta, rho from opengreeks.black76 import delta, gamma, vega, theta, rho
from py_vollib.black_scholes import black_scholes from opengreeks.black_scholes import black_scholes
from py_vollib.black_scholes_merton import black_scholes_merton from opengreeks.black_scholes_merton import black_scholes_merton

Reproducing the benchmarks

Want to verify the speedups on your hardware before you commit? Two-command repro:

# Install the OpenAlgo production baseline + opengreeks itself
pip install py_vollib==1.0.1 py_lets_be_rational==1.0.1 numpy maturin opengreeks

# Run the bench against your CPU
python -c "import urllib.request; exec(urllib.request.urlopen('https://raw.githubusercontent.com/marketcalls/opengreeks/main/bench/bench_parity.py').read())"

Or clone the repo and run bench/bench_parity.py — it auto-detects whichever vollib version is installed and prints a full parity + performance report in 30 seconds. Headline numbers above are reproducible.

Full report including all 29 edge cases, dual-version comparison, and chain-wide tables: bench/RESULTS.md.


Project layout

OpenGreeks/                          # this monorepo
├── pyproject.toml                   # name = "opengreeks"   →   pip install opengreeks
├── Cargo.toml                       # Rust workspace
├── src/lib.rs                       # PyO3 cdylib  _opengreeks
├── python/opengreeks/
│   ├── __init__.py
│   ├── black76.py                   # opengreeks.black76 — vollib.black equivalent
│   ├── black_scholes.py             # opengreeks.black_scholes
│   └── black_scholes_merton.py      # opengreeks.black_scholes_merton
├── black76_rust/                    # pure-Rust Black-76 core (zero deps)
├── bsm_rust/                        # pure-Rust BSM (BS via q=0); depends on black76_rust
├── bench/
│   ├── bench_parity.py              # parity + performance bench
│   └── RESULTS.md                   # full report
└── .github/workflows/CI.yml         # cargo test + wheel matrix + PyPI publish

Future pricing models (Heston stochastic vol, SABR, American/Bermudan via tree, etc.) slot in as new <model>_rust/ crates + opengreeks.<model> submodules without breaking the published API.


Build from source

# Toolchain
rustup default stable
pip install maturin

# Develop install into a venv
cd OpenGreeks/
maturin develop --release

# Or build a wheel
maturin build --release
pip install target/wheels/opengreeks-*.whl

Run tests

# Rust crates
cargo test --release

# Python parity + performance bench
pip install py_vollib==1.0.1 py_lets_be_rational==1.0.1 numpy
python bench/bench_parity.py

Dependencies

Layer Dependencies
Rust core (black76_rust, bsm_rust) None — std math only
PyO3 wrapper (build-time) pyo3, numpy Rust crates
Python runtime numpy only

Compare to vollib==1.0.7 which pulls in py_lets_be_rational, cody_special, piecewise_rational, simplejson, numpy, pandas, scipy (7 packages including pandas & scipy).


Credits & inspiration

OpenGreeks is a Rust reimplementation that takes its public API directly from py_vollib / vollib (© 2017 Gammon Capital LLC, MIT-licensed) — function names, argument orders, return-value conventions, and per-day theta / per-1% vega-rho scaling. The vollib code base is the canonical Python reference for these formulas and we recommend it as the parity oracle when validating any port.

Algorithmic credit:

  • Peter Jäckel — "Let's Be Rational" (jaeckel.org). The IV inversion algorithm used by py_lets_be_rational and by future versions of OpenGreeks.
  • W. J. Cody — "Rational Chebyshev approximations for the error function" (Math. Comp., 1969). Used for the normal CDF in both libraries.
  • A. R. Wichura — "Algorithm AS 241" (Appl. Stat., 1988). Inverse normal CDF.
  • John Hull and Espen Haug — textbook formula references; their Black-76 / BS / BSM examples are the validation anchors in bench/bench_parity.py.

License

MIT — Copyright (c) 2026 Marketcalls / Rajandran R. See LICENSE.

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

opengreeks-0.1.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distributions

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

opengreeks-0.1.0-cp39-abi3-win_amd64.whl (184.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

opengreeks-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl (252.5 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

opengreeks-0.1.0-cp39-abi3-manylinux_2_28_aarch64.whl (242.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

opengreeks-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (230.3 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

opengreeks-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (239.6 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: opengreeks-0.1.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opengreeks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9b3fb1d66344e5ee2818062f3ae48ba3479fb4ccd28e33332197de24ef586bdb
MD5 c1e0b6441f1fd676e3ce1a3da086c7dd
BLAKE2b-256 288da132bacb880b6d36b442ca7c2255e9c640c1653affb357880879be58a039

See more details on using hashes here.

Provenance

The following attestation bundles were made for opengreeks-0.1.0.tar.gz:

Publisher: CI.yml on marketcalls/opengreeks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opengreeks-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: opengreeks-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 184.0 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for opengreeks-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9645ecd4a493d5982b33ffd2382b22a48f4ce4b837cf102487a57478223acab2
MD5 4800e7a53acf6505888d6445f8ee1773
BLAKE2b-256 2b136fc5a45975533a9d6dea9968bbc25ff071a6a4f0b10b3693151177203a82

See more details on using hashes here.

Provenance

The following attestation bundles were made for opengreeks-0.1.0-cp39-abi3-win_amd64.whl:

Publisher: CI.yml on marketcalls/opengreeks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opengreeks-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for opengreeks-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c19655f534141a7992000f558eebd48503645be6521d179c17b763162ccae78a
MD5 8b4b8911f19f2ce16bf811daaa49ca98
BLAKE2b-256 7399890a39043f020edc2540483c345b4375c5415456fcada3dda2140f7a92f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for opengreeks-0.1.0-cp39-abi3-manylinux_2_28_x86_64.whl:

Publisher: CI.yml on marketcalls/opengreeks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opengreeks-0.1.0-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for opengreeks-0.1.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0d5b5a0a85e8df2805930f4a50f4884ee3c7602f21d5f11b06ffc2fd48608cc6
MD5 648071c2a9d56bdae66870687159c129
BLAKE2b-256 873b4a74f2ad960d4cd5bbccb4509a730aa7737756b971fe98256a79f709c3e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for opengreeks-0.1.0-cp39-abi3-manylinux_2_28_aarch64.whl:

Publisher: CI.yml on marketcalls/opengreeks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opengreeks-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opengreeks-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6df4a367dc006825eb710af59edeeed6cd1fb5db55192a6fbd977b4ab1bdeaf
MD5 05c2dbc77f17e516b26931034e4a961b
BLAKE2b-256 6ad36b4be23a1ce62fefa789a501ed34c05ffdd7e1ff23a43881808d734d2505

See more details on using hashes here.

Provenance

The following attestation bundles were made for opengreeks-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: CI.yml on marketcalls/opengreeks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opengreeks-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for opengreeks-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d61c9d8549e8888acc8f1d9014e0322a00166b66f8ce60ca0a558e0de8135de6
MD5 704f8c5dfa60ad898c964167790947b1
BLAKE2b-256 bedd933168c426aebb55fd29637c81e2e275bd4c276092c3c282bff60fe173b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for opengreeks-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: CI.yml on marketcalls/opengreeks

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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