Often referred to as the greeks, these variables describe the different dimensions of risk involved when taking an options position.
Greeks¶
-
py_vollib_vectorized.greeks.
delta
(flag, S, K, t, r, sigma, q=None, *, model='black_scholes', return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Return the delta of a contract, as specified by the pricing model 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 price of the underlying asset.
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.
q – The annualized continuous dividend yield.
model – Must be one of ‘black’, ‘black_scholes’ or ‘black_scholes_merton’.
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
pd.Series
,pd.DataFrame
ornumpy.array
object containing the delta for each contract.
>>> import py_vollib.black_scholes.greeks.numerical >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black_scholes.greeks.numerical.delta(flag, S, K, t, r, sigma, return_as='numpy') array([ 0.46750566, -0.1364465 ]) >>> py_vollib_vectorized.vectorized_delta(flag, S, K, t, r, sigma, model='black_scholes', return_as='numpy') # equivalent array([ 0.46750566, -0.1364465 ])
-
py_vollib_vectorized.greeks.
gamma
(flag, S, K, t, r, sigma, q=None, *, model='black_scholes', return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Return the gamma of a contract, as specified by the pricing model 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 price of the underlying asset.
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.
q – The annualized continuous dividend yield.
model – Must be one of ‘black’, ‘black_scholes’ or ‘black_scholes_merton’.
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
pd.Series
,pd.DataFrame
ornumpy.array
object containing the gamma for each contract.
>>> import py_vollib.black_scholes.greeks.numerical >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black_scholes.greeks.numerical.gamma(flag, S, K, t, r, sigma, return_as='numpy') array([0.0467948, 0.0257394]) >>> py_vollib_vectorized.vectorized_gamma(flag, S, K, t, r, sigma, model='black_scholes', return_as='numpy') # equivalent array([0.0467948, 0.0257394])
-
py_vollib_vectorized.greeks.
rho
(flag, S, K, t, r, sigma, q=None, *, model='black_scholes', return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Return the rho of a contract, as specified by the pricing model 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 price of the underlying asset.
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.
q – The annualized continuous dividend yield.
model – Must be one of ‘black’, ‘black_scholes’ or ‘black_scholes_merton’.
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
pd.Series
,pd.DataFrame
ornumpy.array
object containing the rho for each contract.
>>> import py_vollib.black_scholes.greeks.numerical >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black_scholes.greeks.numerical.rho(flag, S, K, t, r, sigma, return_as='numpy') array([ 0.0830349 , -0.02715114]) >>> py_vollib_vectorized.vectorized_rho(flag, S, K, t, r, sigma, model='black_scholes', return_as='numpy') # equivalent array([ 0.0830349 , -0.02715114])
-
py_vollib_vectorized.greeks.
theta
(flag, S, K, t, r, sigma, q=None, *, model='black_scholes', return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Return the theta of a contract, as specified by the pricing model 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 price of the underlying asset.
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.
q – The annualized continuous dividend yield.
model – Must be one of ‘black’, ‘black_scholes’ or ‘black_scholes_merton’.
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
pd.Series
,pd.DataFrame
ornumpy.array
object containing the theta for each contract.
>>> import py_vollib.black_scholes.greeks.numerical >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black_scholes.greeks.numerical.theta(flag, S, K, t, r, sigma, return_as='numpy') array([-0.04589963, -0.00533543]) >>> py_vollib_vectorized.vectorized_theta(flag, S, K, t, r, sigma, model='black_scholes', return_as='numpy') # equivalent array([-0.04589963, -0.00533543])
-
py_vollib_vectorized.greeks.
vega
(flag, S, K, t, r, sigma, q=None, *, model='black_scholes', return_as='dataframe', dtype=<class 'numpy.float64'>)¶ Return the vega of a contract, as specified by the pricing model 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 price of the underlying asset.
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.
q – The annualized continuous dividend yield.
model – Must be one of ‘black’, ‘black_scholes’ or ‘black_scholes_merton’.
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
pd.Series
,pd.DataFrame
ornumpy.array
object containing the vega for each contract.
>>> import py_vollib.black_scholes.greeks.numerical >>> import py_vollib_vectorized >>> flag = ['c', 'p'] >>> S = 95 >>> K = [100, 90] >>> t = .2 >>> r = .2 >>> sigma = .2 >>> py_vollib.black_scholes.greeks.numerical.vega(flag, S, K, t, r, sigma, return_as='numpy') array([0.16892575, 0.0928379 ]) >>> py_vollib_vectorized.vectorized_vega(flag, S, K, t, r, sigma, model='black_scholes', return_as='numpy') # equivalent array([0.16892575, 0.0928379 ])