A fast, vectorized approach to calculating Implied Volatility and Greeks using the Black, Black-Scholes and Black-Scholes-Merton pricing.
Likely abandoned. No release or commit for years (last release over 5 years ago).
pip install py-vollib-vectorizedpy_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
# The usual py_vollib syntax
import numpy as np
import pandas as pd
import py_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 = py_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).
# Note that you must pass a value for each contract as *no broadcasting* is done on the inputs.
# Patch the original py_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' for call, 'p' 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 = py_vollib.black_scholes.black_scholes(flag, S, K, t, r, iv, return_as='array')
# array([12.11158143, 2.02418536])
