Vectorized implementation of the Black model for option pricing on futures, the Black-Scholes model for option pricing, and its extension to dividend stocks, the Black-Scholes-Merton model.
Models¶
-
py_vollib_vectorized.models.
vectorized_black
(flag, F, K, t, r, sigma, *, return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Price a Future option using the Black model. Broadcasting is applied on the inputs.
- Parameters
F – The price of the underlying asset.
K – The strike price.
sigma – The Implied Volatility (as a decimal, i.e. 0.10 for 10%).
t – The annualized time to expiration. Must be positive. For small TTEs, use a small value (1e-3).
flag – For each contract, this should be specified as c for a call option and p for a put option.
return_as – To return as a
pd.Series
object, use “series”. To return as apd.DataFrame
object, use “dataframe”. Any other value will return anumpy.array
object.dtype – Data type.
- Returns
The price of the option.
>>> import py_vollib.black >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> F = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black.black(flag, F, K, t, r, sigma, return_as='numpy') array([1.53408169, 1.38409245]) >>> py_vollib_vectorized.vectorized_black(flag, F, K, t, r, sigma, return_as='numpy') # equivalent array([1.53408169, 1.38409245])
-
py_vollib_vectorized.models.
vectorized_black_scholes
(flag, S, K, t, r, sigma, *, return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Price an option using the Black-Scholes model. Broadcasting is applied on the inputs.
- Parameters
flag – For each contract, this should be specified as c for a call option and p for a put option.
S – The underlying asset price
K – The strike price.
t – The annualized time to expiration. Must be positive. For small TTEs, use a small value (1e-3).
r – The interest free rate.
sigma – The Implied Volatility (as a decimal, i.e. 0.10 for 10%).
return_as – To return as a
pd.Series
object, use “series”. To return as apd.DataFrame
object, use “dataframe”. Any other value will return anumpy.array
object.dtype – Data type.
- Returns
The price of the option.
>>> import py_vollib.black_scholes >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black_scholes.black_scholes(flag, S, K, t, r, sigma, return_as='numpy') array([2.89558836, 0.61109351]) >>> py_vollib_vectorized.vectorized_black_scholes(flag, S, K, t, r, sigma, return_as='numpy') # equivalent array([2.89558836, 0.61109351])
-
py_vollib_vectorized.models.
vectorized_black_scholes_merton
(flag, S, K, t, r, sigma, q, *, return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Price an option using the Black-Scholes-Merton model. Broadcasting is applied on the inputs.
- Parameters
flag – For each contract, this should be specified as c for a call option and p for a put option.
S – The underlying asset price
K – The strike price.
t – The annualized time to expiration. Must be positive. For small TTEs, use a small value (1e-3).
r – The interest free rate.
sigma – The Implied Volatility (as a decimal, i.e. 0.10 for 10%).
q – The annualized continuous dividend yield.
return_as – To return as a
pd.Series
object, use “series”. To return as apd.DataFrame
object, use “dataframe”. Any other value will return anumpy.array
object.dtype – Data type.
- Returns
The price of the option.
>>> import py_vollib.black_scholes_merton >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = [95, 99] >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> q = 0 >>> py_vollib.black_scholes_merton.black_scholes_merton(flag, S, K, t, r, sigma, q, return_as='numpy') array([2.89558836, 0.23536284]) >>> py_vollib_vectorized.vectorized_black_scholes_merton(flag, S, K, t, r, sigma, q, return_as='numpy') # equivalent array([2.89558836, 0.23536284])