Modern Black, Black-Scholes, and Black-Scholes-Merton pricing and implied volatility with NumPy, PyTorch, and JAX backends.
Project description
fast-vollib
fast-vollib is a modern 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.
Features
- Three pricing models — Black-76, Black-Scholes, Black-Scholes-Merton
- Vectorized IV solver — Newton-Raphson with compiled bisection fallback (~10 M solves/s on CPU)
- 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 replacement —
patch_py_vollib()replacespy_vollibat runtime with no code changes
Install
pip install fast-vollib
Optional extras:
pip install "fast-vollib[torch]" # PyTorch backend
pip install "fast-vollib[jax]" # JAX backend
Quick start
import numpy as np
import fast_vollib
# Price a batch of European options
prices = fast_vollib.vectorized_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.vectorized_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,
)
DataFrame helper
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, vega
Drop-in py_vollib replacement
import fast_vollib
fast_vollib.patch_py_vollib()
# All py_vollib imports now use fast_vollib transparently
from py_vollib.black_scholes import black_scholes
Backend selection
# 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.vectorized_black_scholes(..., backend="jax")
backend="auto" resolution order:
- Explicit
backend=kwarg fast_vollib.set_backend()overrideFAST_VOLLIB_BACKENDenvironment variabletorchwhentorch.cuda.is_available()jaxwhen installednumpy
Public API
from fast_vollib import (
# Pricing
vectorized_black,
vectorized_black_scholes,
vectorized_black_scholes_merton,
# Implied volatility
vectorized_implied_volatility,
vectorized_implied_volatility_black,
# Greeks
vectorized_delta,
vectorized_gamma,
vectorized_rho,
vectorized_theta,
vectorized_vega,
get_all_greeks,
# Utilities
price_dataframe,
patch_py_vollib,
get_backend,
set_backend,
)
Full documentation: raeid-saqur.github.io/fast-vollib
Development
git clone https://github.com/raeid-saqur/fast-vollib.git
cd fast-vollib
uv sync --all-groups # install all deps (CPU)
uv run pytest # run tests
ruff check . --fix # lint
ruff format . # format
uv run mkdocs serve # local docs server → http://localhost:8000
Contributing
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.
License
MIT — 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_vollib-0.1.0.tar.gz.
File metadata
- Download URL: fast_vollib-0.1.0.tar.gz
- Upload date:
- Size: 138.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c9facb82be1e120036f177503c8fbf78bd154561789d271e6a40b38d5165d73
|
|
| MD5 |
a80e356eafbabf6f298a81a8b8fd6980
|
|
| BLAKE2b-256 |
d56f1a86a00cf6e428687c03df86373f079b212844dabc3a0927bb2ca90d15bf
|
Provenance
The following attestation bundles were made for fast_vollib-0.1.0.tar.gz:
Publisher:
release.yml on raeidsaqur/fast-vollib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_vollib-0.1.0.tar.gz -
Subject digest:
6c9facb82be1e120036f177503c8fbf78bd154561789d271e6a40b38d5165d73 - Sigstore transparency entry: 1157532399
- Sigstore integration time:
-
Permalink:
raeidsaqur/fast-vollib@102e80c741af7d87e0f298819a071b92dac07698 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/raeidsaqur
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@102e80c741af7d87e0f298819a071b92dac07698 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fast_vollib-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fast_vollib-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b434def38e8fe208756bd82ad34393a91dde6b735498de14c07a000027652a35
|
|
| MD5 |
2d4350e5833d848f09fd809fea6574aa
|
|
| BLAKE2b-256 |
46c2cbf33b33104a7d40a02ef5a9f5c64ab9411ba4216aef1d7bee2035e09479
|
Provenance
The following attestation bundles were made for fast_vollib-0.1.0-py3-none-any.whl:
Publisher:
release.yml on raeidsaqur/fast-vollib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_vollib-0.1.0-py3-none-any.whl -
Subject digest:
b434def38e8fe208756bd82ad34393a91dde6b735498de14c07a000027652a35 - Sigstore transparency entry: 1157532458
- Sigstore integration time:
-
Permalink:
raeidsaqur/fast-vollib@102e80c741af7d87e0f298819a071b92dac07698 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/raeidsaqur
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@102e80c741af7d87e0f298819a071b92dac07698 -
Trigger Event:
push
-
Statement type: