py_vollib.ref_python.black_scholes

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.

Subpackages

Submodules

Package Contents

Functions

d1(S, K, t, r, sigma)

Calculate the d1 component of the Black-Scholes PDE.

d2(S, K, t, r, sigma)

Calculate the d2 component of the Black-Scholes PDE.

black_scholes(flag, S, K, t, r, sigma)

Return the Black-Scholes option price implemented in

Attributes

N

N
d1(S, K, t, r, sigma)[source]

Calculate the d1 component of the Black-Scholes PDE.

Parameters:
  • S (float) – underlying asset price

  • K (float) – strike price

  • sigma (float) – annualized standard deviation, or volatility

  • t (float) – time to expiration in years

  • r (float) – risk-free interest rate

John C. Hull, “Options, Futures and Other Derivatives,” 7th edition, Example 13.6, page 294

>>> S = 42
>>> K = 40
>>> r = .10
>>> sigma = .20
>>> t = 0.5
>>> calculated_d1 = d1(S,K,t,r,sigma)
>>> text_book_d1 = 0.7693
>>> abs(calculated_d1 - text_book_d1) < 0.0001
True
d2(S, K, t, r, sigma)[source]

Calculate the d2 component of the Black-Scholes PDE.

Parameters:
  • S (float) – underlying asset price

  • K (float) – strike price

  • sigma (float) – annualized standard deviation, or volatility

  • t (float) – time to expiration in years

  • r (float) – risk-free interest rate

John C. Hull, “Options, Futures and Other Derivatives,” 7th edition, Example 13.6, page 294

>>> S = 42
>>> K = 40
>>> r = .10
>>> sigma = .20
>>> t = 0.5
>>> calculated_d2 = d2(S,K,t,r,sigma) #0.627841271869
>>> text_book_d2 = 0.6278
>>> abs(calculated_d2 - text_book_d2) < 0.0001
True
black_scholes(flag, S, K, t, r, sigma)[source]
Return the Black-Scholes option price implemented in

python (for reference).

Parameters:
  • S (float) – underlying asset price

  • K (float) – strike price

  • sigma (float) – annualized standard deviation, or volatility

  • t (float) – time to expiration in years

  • r (float) – risk-free interest rate

  • flag (str) – ‘c’ or ‘p’ for call or put.

>>> S,K,t,r,sigma = 60,65,.25,.08,.3
>>> expected = 2.13336844492
>>> actual = black_scholes('c',S,K,t,r,sigma)
>>> abs(expected-actual) < 1e-11
True