py_vollib.ref_python.black.greeks.analytical

A library for option pricing, implied volatility, and greek calculation. py_vollib is based on lets_be_rational, a Python wrapper for LetsBeRational by Peter Jaeckel as described below.

copyright:

© 2023 Larry Richards

license:

MIT, see LICENSE for more details.

Module Contents

Functions

delta(flag, F, K, t, r, sigma)

Returns the Black delta of an option.

theta(flag, F, K, t, r, sigma)

Returns the Black theta of an option.

gamma(flag, F, K, t, r, sigma)

Returns the Black gamma of an option.

vega(flag, F, K, t, r, sigma)

Returns the Black vega of an option.

rho(flag, F, K, t, r, sigma)

Returns the Black rho of an option.

Attributes

N

N
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
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
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
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
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