py_vollib_vectorized
Introduction
The py_vollib_vectorized package makes pricing thousands of option contracts and calculating greeks fast and effortless.
It is built on top of the vollib library, formerly named py_vollib.
Upon import, it will automatically patch the corresponding vollib functions so as to support vectorization.
The deprecated py_vollib import name refers to the same functions, so code that still imports py_vollib is patched too.
The patch changes vollib for the whole process; it can be turned off.
Inputs can then be passed as floats, tuples, lists, numpy.array, or pandas.Series.
Automatic broadcasting is performed on the inputs.
Results returned as pandas objects have the index of the pandas inputs.
On top of vectorization, modifications to vollib include additional numba speedups; as such, numba is required.
These speedups make py_vollib_vectorized the fastest library for pricing option contracts.
The same prices, implied volatilities and greeks are also available as Polars expressions. A compiled plugin evaluates them on DataFrames and LazyFrames, on one core or on all of them.
See the documentation for more details.
Installation
pip install py_vollib_vectorized
To use the Polars expressions, install Polars with it:
pip install "py_vollib_vectorized[polars]"
Requirements
- Written for Python 3.10+
- Requires vollib, numba, numpy, pandas
- Polars 1.0+ is optional, for the Polars expressions
- Wheels are available for Linux (x86-64, aarch64), macOS (Apple silicon, Intel) and Windows (x86-64). Installing from source on another platform takes a Rust toolchain.
Code samples
The library can be used in three ways.
Upon import, it monkey-patches (i.e. replaces) the corresponding functions in vollib.
As a more versatile alternative, users that would prefer to work with a dedicated option pricing API can make use of the utility functions provided by the library.
Users of Polars can price the columns of their frames with expressions.
Patching vollib
# The usual vollib syntax
import numpy as np
import pandas as pd
import vollib.black_scholes
flag = 'c' # 'c' for call, 'p' for put
S = 100 # Underlying asset price
K = 90 # Strike
t = 0.5 # (Annualized) time-to-expiration
r = 0.01 # Interest free rate
iv = 0.2 # Implied Volatility
option_price = vollib.black_scholes.black_scholes(flag, S, K, t, r, iv) # 12.111581435
# This library keeps the same syntax, but you can pass as input any iterable of values.
# This includes list, tuple, numpy.array, pd.Series, pd.DataFrame (with only a single column).
# Patch the original vollib library by importing py_vollib_vectorized
import py_vollib_vectorized # The same functions now accept vectors as input!
# Note that the input arguments are broadcasted.
# You can specify ints, floats, tuples, lists, numpy arrays or Series.
flag = ['c', 'p'] # 'c' or 'call' for call, 'p' or 'put' for put
S = (100, 100) # Underlying asset prices
K = [90] # Strikes
t = pd.Series([0.5, 0.6]) # (Annualized) times-to-expiration
r = np.array([0.01]) # Interest free rates
iv = 0.2 # Implied Volatilities
option_price = vollib.black_scholes.black_scholes(flag, S, K, t, r, iv, return_as='array')
# array([12.11158143, 2.02418536])
Using vollib without the patch
The patch applies to the whole process. After
import py_vollib_vectorized, a scalar call such asvollib.black_scholes.black_scholes('c', 100, 90, 0.5, 0.01, 0.2)returns apandas.DataFrameinstead of a float, also in other code of the same process that callsvollib.
Nothing in this library needs the patch: the vectorized_ functions, the utility functions and the Polars expressions below work with and without it.
To keep the scalar functions of vollib, either set the environment variable PY_VOLLIB_VECTORIZED_PATCH_VOLLIB=0 before the first import, or take the patch back after it:
import vollib.black_scholes
import py_vollib_vectorized
py_vollib_vectorized.unpatch_vollib() # vollib is as it was before the import
vollib.black_scholes.black_scholes('c', 100, 90, 0.5, 0.01, 0.2) # 12.11158143496968, a float
py_vollib_vectorized.vectorized_black_scholes('c', 100, 90, 0.5, 0.01, 0.2, return_as='array') # array([12.11158143])
py_vollib_vectorized.patch_vollib() # applies the patch again
One function takes the interest rate before the time to expiration.
vectorized_implied_volatility_black(price, F, K, r, t, flag)keeps the argument order ofvollib.black.implied_volatility.implied_volatility, and so does the Polars expressionimplied_volatility_black. Every other function takestbeforer, as invectorized_implied_volatility(price, S, K, t, r, flag). In the wrong order the two give a wrong implied volatility, and no error: passr=andt=by keyword.
Utility functions
We also define other utility functions to get all contract prices, implied volatilities, and greeks in a single call.
import pandas as pd
from py_vollib_vectorized import price_dataframe, get_all_greeks
# Using the data above, we can calculate all contracts greeks in a single call
greeks = get_all_greeks(flag, S, K, t, r, iv, model='black_scholes', return_as='dict')
# {'delta': array([ 0.80263679, -0.21293214]),
# 'gamma': array([0.0196385, 0.01875498]),
# 'theta': array([-0.01263557, -0.00964498]),
# 'rho': array([0.34073321, -0.13994668]),
# 'vega': array([0.19626478, 0.22493816])}
# We can also price a dataframe easily by specifying a dataframe and the corresponding columns
df = pd.DataFrame()
df['Flag'] = ['c', 'p']
df['S'] = 95
df['K'] = [100, 90]
df['T'] = 0.2
df['R'] = 0.2
df['IV'] = 0.2
result = price_dataframe(df, flag_col='Flag', underlying_price_col='S', strike_col='K', annualized_tte_col='T',
riskfree_rate_col='R', sigma_col='IV', model='black_scholes', inplace=False)
# Price delta gamma theta rho vega
# 2.895588 0.467506 0.046795 -0.045900 0.083035 0.168926
# 0.611094 -0.136447 0.025739 -0.005335 -0.027151 0.092838
Polars expressions
py_vollib_vectorized.polars has the same functions as expressions: strings are column names, and numbers and other expressions work too.
import polars as pl
import py_vollib_vectorized.polars as pvp
df = pl.DataFrame({
"flag": ["c", "p"], # 'c' or 'call' for call, 'p' or 'put' for put
"S": [95.0, 95.0], # Underlying asset prices
"K": [100.0, 90.0], # Strikes
"t": [0.2, 0.2], # (Annualized) times-to-expiration
"r": [0.2, 0.2], # Interest free rates
"sigma": [0.2, 0.2], # Implied Volatilities
})
df.select(
pvp.black_scholes("flag", "S", "K", "t", "r", "sigma"),
pvp.all_greeks("flag", "S", "K", "t", "r", "sigma"),
).unnest("greeks")
# ┌──────────┬───────────┬──────────┬───────────┬───────────┬──────────┐
# │ Price ┆ delta ┆ gamma ┆ theta ┆ rho ┆ vega │
# ╞══════════╪═══════════╪══════════╪═══════════╪═══════════╪══════════╡
# │ 2.895588 ┆ 0.467506 ┆ 0.046795 ┆ -0.0459 ┆ 0.083035 ┆ 0.168926 │
# │ 0.611094 ┆ -0.136447 ┆ 0.025739 ┆ -0.005335 ┆ -0.027151 ┆ 0.092838 │
# └──────────┴───────────┴──────────┴───────────┴───────────┴──────────┘
# The expressions work in lazy queries, on the streaming engine, and in filter, group_by and over.
lazy = df.lazy().with_columns(pvp.black_scholes("flag", "S", "K", "t", "r", "sigma").alias("mid"))
lazy.select(pvp.implied_volatility("mid", "S", "K", "t", "r", "flag")).collect(engine="streaming")
# IV: [0.2, 0.2]
# parallel=True splits the contracts of one expression over every core: set it for frames in one or a few chunks.
df.select(pvp.implied_volatility(2.0, "S", "K", "t", "r", "flag", parallel=True))
# price_dataframe adds the prices or the implied volatilities, and the greeks, to a DataFrame or a LazyFrame.
pvp.price_dataframe(df, flag_col="flag", underlying_price_col="S", strike_col="K", annualized_tte_col="t",
riskfree_rate_col="r", sigma_col="sigma", model="black_scholes")
# ┌──────┬──────┬───────┬─────┬─────┬───────┬──────────┬───────────┬──────────┬───────────┬───────────┬──────────┐
# │ flag ┆ S ┆ K ┆ t ┆ r ┆ sigma ┆ Price ┆ delta ┆ gamma ┆ theta ┆ rho ┆ vega │
# ╞══════╪══════╪═══════╪═════╪═════╪═══════╪══════════╪═══════════╪══════════╪═══════════╪═══════════╪══════════╡
# │ c ┆ 95.0 ┆ 100.0 ┆ 0.2 ┆ 0.2 ┆ 0.2 ┆ 2.895588 ┆ 0.467506 ┆ 0.046795 ┆ -0.0459 ┆ 0.083035 ┆ 0.168926 │
# │ p ┆ 95.0 ┆ 90.0 ┆ 0.2 ┆ 0.2 ┆ 0.2 ┆ 0.611094 ┆ -0.136447 ┆ 0.025739 ┆ -0.005335 ┆ -0.027151 ┆ 0.092838 │
# └──────┴──────┴───────┴─────┴─────┴───────┴──────────┴───────────┴──────────┴───────────┴───────────┴──────────┘
The expressions return the same numbers as the functions above. They return null where an input is null. A price that has no implied volatility gives null as well, without a warning, where the functions above give NaN.
See the documentation for more details.
Benchmarking
Compared to looping through contracts or to using built-in pandas functionality, this library scales to a large number of contracts.
The figure shows the time to price contracts with the Black-Scholes model and to compute the implied volatilities of those prices.
For one million contracts, the fastest loop over the scalar functions of vollib takes 44 seconds, the pandas API 0.90 seconds, and the Polars expressions 0.49 seconds on one thread and 0.037 seconds with parallel=True on 64 cores.
See the performance page of the documentation for the numbers and for how they were measured.
Acknowledgements
This library optimizes the vollib codebase, itself built upon Peter Jäckel's Let's be rational methodology.
The numba kernels of the implied volatility solver come from py_lets_be_rational 1.0.1 and are distributed with this library under its license (see py_vollib_vectorized/_lets_be_rational/LICENSE).
The plugin behind the Polars expressions is a Rust port of those kernels, under the same license, and follows the design of polars_ds.
Metadata
Release files for py-vollib-vectorized 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_vollib_vectorized-1.0.0.tar.gz | 145.1 kB | With provenance | Details for py_vollib_vectorized-1.0.0.tar.gz |
Built distributions (wheels)
Total release size: 31.3 MB
Release files / py_vollib_vectorized-1.0.0.tar.gz
| Download URL | py_vollib_vectorized-1.0.0.tar.gz |
|---|---|
| Size | 145.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bf9a3f2d6846ee64e1293b04fa458457e5e03a28c7f43cbd07ac9cb6fade1b4
|
|
BLAKE2b-256 checksum How to use checksums |
f8399340afa536764c8c582dc1c7585b7e6fa676cc15e4794db314b0a316957d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / py_vollib_vectorized-1.0.0-cp310-abi3-win_amd64.whl
| Download URL | py_vollib_vectorized-1.0.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 7.1 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e31d90856f51c1f4596897ecf719e38205c6cfef1d5cd5420c032b6e75f34998
|
|
BLAKE2b-256 checksum How to use checksums |
9c52a0adc509bc2620342c89d1f2a3f283ddfca72e098d4192982246c3b8d64b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / py_vollib_vectorized-1.0.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | py_vollib_vectorized-1.0.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 6.4 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
84454013c778a2d62d9a0eb3b7c427c139eaa0623a9af1f9310f7e90d857a8d4
|
|
BLAKE2b-256 checksum How to use checksums |
fd1fbd9c5e8af628640065a9751a6df76e630a32ad5545e2bdb24e360117e10e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / py_vollib_vectorized-1.0.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | py_vollib_vectorized-1.0.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e048040680762156812788393d10052da44299c7d5e27c9fb55d263f016d0637
|
|
BLAKE2b-256 checksum How to use checksums |
1750dddd6384d08b36644a567da601389ca73134c692b9837d7253bc65cff3ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / py_vollib_vectorized-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | py_vollib_vectorized-1.0.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a34482516f13f5ac59f0fecec96cadabb3df7bfdea8654f297b8eaedea96442b
|
|
BLAKE2b-256 checksum How to use checksums |
851d8eb05f291b2afc320d4879a64215e0fefd207f0ce5b4b061e662bf0fb54e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / py_vollib_vectorized-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | py_vollib_vectorized-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
27a1c7a9c8309d0b6539857a0c2a7fc87f754c2c65c7aeb09da964987491dae6
|
|
BLAKE2b-256 checksum How to use checksums |
723174d025677f49b24df3ecc31e94a2f6a7c10183144aae615ac3c06d7c1d2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for py-vollib-vectorized 1.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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for py_vollib_vectorized-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA 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.