Accelerated Black-Scholes pricing, implied volatility, and Greeks library with pluggable NumPy, PyTorch, and JAX backends.
fast-vollib is an accelerated --- kernel-fused, optimized --- Python library for Black, Black-Scholes, and
Black-Scholes-Merton option pricing, implied volatility solving, and Greeks —
with pluggable NumPy, PyTorch, and JAX backends and a compatibility-first API
modeled on py_vollib_vectorized.
- Three pricing models — Black-76, Black-Scholes, Black-Scholes-Merton
- Vectorized IV solver — Halley's method with compiled bisection fallback
- Full Greeks — delta, gamma, theta, rho, vega; all five in one
get_all_greekscall - Pluggable backends — NumPy (default), PyTorch (CUDA), JAX (JIT)
- Automatic backend selection — prefers CUDA > JAX > NumPy
- DataFrame-native —
price_dataframeworks directly on apandas.DataFrame - Drop-in compatibility —
patch_py_vollib()andpatch_py_vollib_vectorized()patch the scalar and vectorized upstream namespaces
pip install fast-vollibOptional extras:
pip install "fast-vollib[torch]" # PyTorch backend
pip install "fast-vollib[jax]" # JAX backend
pip install "fast-vollib[torch,jax]" # both backendsStable releases are published from Git tags to PyPI. Development snapshots are
available via to TestPyPI versions such as 0.1.2.dev3.
pip install --pre \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
fast-vollibUse the dev TestPyPI channel only if you want nightly or dev builds only.
import numpy as np
import fast_vollib
# Price a batch of European options
prices = fast_vollib.fast_black_scholes(
flag=np.array(["c", "c", "p"]),
S=100.0,
K=np.array([95, 100, 105]),
t=0.25,
r=0.05,
sigma=0.20,
return_as="numpy",
)
# Recover implied volatility
iv = fast_vollib.fast_implied_volatility(
price=prices,
S=100.0,
K=np.array([95, 100, 105]),
t=0.25,
r=0.05,
flag=np.array(["c", "c", "p"]),
return_as="numpy",
)
# All Greeks in one call (returns a pandas DataFrame)
greeks = fast_vollib.get_all_greeks(
flag=np.array(["c", "p"]),
S=100.0, K=100.0, t=0.25, r=0.05, sigma=0.20,
)import pandas as pd
df = pd.DataFrame({
"flag": ["c", "p"],
"S": [100, 100],
"K": [100, 100],
"t": [0.25, 0.25],
"r": [0.05, 0.05],
"sigma": [0.20, 0.20],
})
result = fast_vollib.price_dataframe(
df,
flag_col="flag",
underlying_price_col="S",
strike_col="K",
annualized_tte_col="t",
riskfree_rate_col="r",
sigma_col="sigma",
)
# Columns: Price, delta, gamma, theta, rho, vegaThe py_vollib_vectorized
API can be kept intact in your codebase via the included monkey-patching helper.
import fast_vollib
fast_vollib.patch_py_vollib_vectorized()
# All py_vollib_vectorized imports now use fast_vollib transparently
from py_vollib_vectorized import vectorized_black_scholes# Automatic (CUDA > JAX > NumPy)
fast_vollib.get_backend() # e.g. "torch"
# Set for the session
fast_vollib.set_backend("numpy")
# Override per call
price = fast_vollib.fast_black_scholes(..., backend="jax")backend="auto" resolution order:
- Explicit
backend=kwarg fast_vollib.set_backend()overrideFAST_VOLLIB_BACKENDenvironment variabletorchwhentorch.cuda.is_available()jaxwhen installednumpy
from fast_vollib import (
# Pricing
fast_black,
fast_black_scholes,
fast_black_scholes_merton,
# Implied volatility
fast_implied_volatility,
fast_implied_volatility_black,
# Greeks (compatibility aliases)
vectorized_delta,
vectorized_gamma,
vectorized_rho,
vectorized_theta,
vectorized_vega,
get_all_greeks,
# Utilities
price_dataframe,
patch_py_vollib,
patch_py_vollib_vectorized,
get_backend,
set_backend,
)Full documentation: raeidsaqur.github.io/fast-vollib
git clone https://github.com/raeidsaqur/fast-vollib.git
cd fast-vollib
uv sync --all-groups --extra torch --extra jax # all deps + both backends
uv run pytest # run tests
ruff check . --fix # lint
ruff format . # format
uv run mkdocs serve # local docs server → http://localhost:8000- Tagged releases like
v0.1.2publish stable builds to PyPI. - PRs on
mainpublish development snapshots to TestPyPI. - The package version is derived from Git tags with
hatch-vcs, so version strings are no longer maintained manually in source files for each release
Contributions are welcome. Please open an issue before sending a large pull request to discuss the change. See CONTRIBUTING.md if present, or follow the standard fork-and-PR workflow.
MIT — see LICENSE.