vollib.black.greeks package¶
Submodules¶
vollib.black.greeks.analytical module¶
vollib.black.greeks.analytical¶
A library for option pricing, implied volatility, and greek calculation. vollib is based on lets_be_rational, a Python wrapper for LetsBeRational by Peter Jaeckel as described below.
copyright: | © 2015 Iota Technologies Pte Ltd |
---|---|
license: | MIT, see LICENSE for more details. |
About LetsBeRational:¶
The source code of LetsBeRational resides at www.jaeckel.org/LetsBeRational.7z .
======================================================================================
Copyright © 2013-2014 Peter Jäckel.
Permission to use, copy, modify, and distribute this software is freely granted,
provided that this notice is preserved.
WARRANTY DISCLAIMER
The Software is provided "as is" without warranty of any kind, either express or implied,
including without limitation any implied warranties of condition, uninterrupted use,
merchantability, fitness for a particular purpose, or non-infringement.
======================================================================================
-
vollib.black.greeks.analytical.
delta
(flag, F, K, t, r, sigma)[source]¶ Returns the Black delta of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
>>> F = 49 >>> K = 50 >>> r = .05 >>> t = 0.3846 >>> sigma = 0.2 >>> flag = 'c' >>> v1 = delta(flag, F, K, t, r, sigma) >>> v2 = 0.45107017482201828 >>> abs(v1-v2) < .000001 True
-
vollib.black.greeks.analytical.
gamma
(flag, F, K, t, r, sigma)[source]¶ Returns the Black gamma of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
>>> F = 49 >>> K = 50 >>> r = .05 >>> t = 0.3846 >>> sigma = 0.2 >>> flag = 'c' >>> v1 = gamma(flag, F, K, t, r, sigma) >>> # 0.0640646705882 >>> v2 = 0.0640646705882 >>> abs(v1-v2) < .000001 True
-
vollib.black.greeks.analytical.
rho
(flag, F, K, t, r, sigma)[source]¶ Returns the Black rho of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
========================================================== The text book analytical formula does not multiply by .01, but in practice rho is defined as the change in price for each 1 percent change in r, hence we multiply by 0.01. ==========================================================
>>> F = 49 >>> K = 50 >>> r = .05 >>> t = 0.3846 >>> sigma = 0.2 >>> flag = 'c' >>> v1 = rho(flag, F, K, t, r, sigma) >>> v2 = -0.0074705380059582258 >>> abs(v1-v2) < .000001 True >>> flag = 'p' >>> v1 = rho(flag, F, K, t, r, sigma) >>> v2 = -0.011243286001308292 >>> abs(v1-v2) < .000001 True
-
vollib.black.greeks.analytical.
theta
(flag, F, K, t, r, sigma)[source]¶ Returns the Black theta of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
>>> F = 49 >>> K = 50 >>> r = .05 >>> t = 0.3846 >>> sigma = 0.2 >>> flag = 'c' >>> v1 = theta(flag, F, K, t, r, sigma) >>> v2 = -0.00816236877462 >>> abs(v1-v2) < .000001 True >>> flag = 'p' >>> v1 = theta(flag, F, K, t, r, sigma) >>> v2 = -0.00802799155312 >>> abs(v1-v2) < .000001 True
-
vollib.black.greeks.analytical.
vega
(flag, F, K, t, r, sigma)[source]¶ Returns the Black vega of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
========================================================== Note: The text book analytical formula does not multiply by .01, but in practice vega is defined as the change in price for each 1 percent change in IV, hence we multiply by 0.01. ==========================================================
>>> F = 49 >>> K = 50 >>> r = .05 >>> t = 0.3846 >>> sigma = 0.2 >>> flag = 'c' >>> v1 = vega(flag, F, K, t, r, sigma) >>> # 0.118317785624 >>> v2 = 0.118317785624 >>> abs(v1-v2) < .000001 True
vollib.black.greeks.numerical module¶
vollib.black.greeks.numerical¶
A library for option pricing, implied volatility, and greek calculation. vollib is based on lets_be_rational, a Python wrapper for LetsBeRational by Peter Jaeckel as described below.
copyright: | © 2015 Iota Technologies Pte Ltd |
---|---|
license: | MIT, see LICENSE for more details. |
About LetsBeRational:¶
The source code of LetsBeRational resides at www.jaeckel.org/LetsBeRational.7z .
======================================================================================
Copyright © 2013-2014 Peter Jäckel.
Permission to use, copy, modify, and distribute this software is freely granted,
provided that this notice is preserved.
WARRANTY DISCLAIMER
The Software is provided "as is" without warranty of any kind, either express or implied,
including without limitation any implied warranties of condition, uninterrupted use,
merchantability, fitness for a particular purpose, or non-infringement.
======================================================================================
-
vollib.black.greeks.numerical.
delta
(flag, F, K, t, r, sigma)[source]¶ Returns the Black delta of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
-
vollib.black.greeks.numerical.
f
(flag, F, K, t, r, sigma, b)¶
-
vollib.black.greeks.numerical.
gamma
(flag, F, K, t, r, sigma)[source]¶ Returns the Black gamma of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
-
vollib.black.greeks.numerical.
rho
(flag, F, K, t, r, sigma)[source]¶ Returns the Black rho of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
-
vollib.black.greeks.numerical.
test
()[source]¶ Tests by comparing the analytical and numerical greek values.
>>> S = 49 >>> K = 50 >>> r = .05 >>> t = 0.3846 >>> sigma = 0.2 >>> flag = 'c'
>>> epsilon = .0001
>>> v1 = delta(flag, S, K, t, r, sigma) >>> v2 = adelta(flag, S, K, t, r, sigma) >>> abs(v1-v2)<epsilon True
>>> v1 = gamma(flag, S, K, t, r, sigma) >>> v2 = agamma(flag, S, K, t, r, sigma) >>> abs(v1-v2)<epsilon True
>>> v1 = rho(flag, S, K, t, r, sigma) >>> v2 = arho(flag, S, K, t, r, sigma) >>> abs(v1-v2)<epsilon True
>>> v1 = vega(flag, S, K, t, r, sigma) >>> v2 = avega(flag, S, K, t, r, sigma) >>> abs(v1-v2)<epsilon True
>>> v1 = theta(flag, S, K, t, r, sigma) >>> v2 = atheta(flag, S, K, t, r, sigma) >>> abs(v1-v2)<epsilon True
-
vollib.black.greeks.numerical.
theta
(flag, F, K, t, r, sigma)[source]¶ Returns the Black theta of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float
-
vollib.black.greeks.numerical.
vega
(flag, F, K, t, r, sigma)[source]¶ Returns the Black vega of an option.
Parameters: - flag (str) – ‘c’ or ‘p’ for call or put.
- F (float) – underlying futures price
- K (float) – strike price
- t (float) – time to expiration in years
- r (float) – annual risk-free interest rate
- sigma (float) – volatility
Returns: float