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 py_vollib
library.
Upon import, it will automatically patch the corresponding py_vollib
functions so as to support vectorization.
Inputs can then be passed as floats, tuples, lists, numpy.array
, or pandas.Series
.
Automatic broadcasting is performed on the inputs.
On top of vectorization, modifications to py_vollib include additional numba
speedups; as such, numba
is required.
These speedups make py_vollib_vectorized
the fastest library for pricing option contracts.
See the documentation for more details.
Installation
pip install py_vollib_vectorized
Requirements
- Written for Python 3.5+
- Requires py_vollib, numba, numpy, pandas, scipy
Code samples
The library can be used in two ways.
Upon import, it monkey-patches (i.e. replaces) the corresponding functions in py_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.
Patching py_vollib
import numpy as np
import pandas as pd
import py_vollib.black_scholes
flag = 'c'
S = 100
K = 90
t = 0.5
r = 0.01
iv = 0.2
option_price = py_vollib.black_scholes.black_scholes(flag, S, K, t, r, iv)
import py_vollib_vectorized
flag = ['c', 'p']
S = (100, 100)
K = [90]
t = pd.Series([0.5, 0.6])
r = np.array([0.01])
iv = 0.2
option_price = py_vollib.black_scholes.black_scholes(flag, S, K, t, r, iv, return_as='array')
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
greeks = get_all_greeks(flag, S, K, t, r, iv, model='black_scholes', return_as='dict')
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)
See the documentation for more details.
Benchmarking
Compared to looping through contracts or to using built-in pandas functionality, this library is very memory efficient and scales fast and well to a large number of contracts.

Acknowledgements
This library optimizes the py_vollib
codebase, itself built upon Peter Jäckel's Let's be rational methodology.