vollib.black_scholes package

Subpackages

Submodules

vollib.black_scholes.implied_volatility module

vollib.black_scholes.implied_volatility

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:

© 2017 Gammon Capital LLC

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_scholes.implied_volatility.implied_volatility(price, S, K, t, r, flag)[source]

Calculate the Black-Scholes implied volatility.

Parameters:
  • price (float) – the Black-Scholes option price

  • S (float) – underlying asset price

  • K (float) – strike price

  • t (float) – time to expiration in years

  • r (float) – risk-free interest rate

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

>>> S = 100
>>> K = 100
>>> sigma = .2
>>> r = .01
>>> flag = 'c'
>>> t = .5
>>> price = black_scholes(flag, S, K, t, r, sigma)
>>> iv = implied_volatility(price, S, K, t, r, flag)
>>> expected_price = 5.87602423383
>>> expected_iv = 0.2
>>> abs(expected_price - price) < 0.00001
True
>>> abs(expected_iv - iv) < 0.00001
True

Module contents

vollib.black_scholes

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:

© 2017 Gammon Capital LLC

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_scholes.black_scholes(flag, S, K, t, r, sigma)[source]

Return the Black-Scholes option price.

Parameters:
  • S (float) – underlying asset price

  • K (float) – strike price; must be strictly positive.

  • 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.

>>> c = black_scholes('c',100,90,.5,.01,.2) 
>>> abs(c - 12.111581435) < .000001
True
>>> p = black_scholes('p',100,90,.5,.01,.2) 
>>> abs(p - 1.66270456231) < .000001
True