py_vollib.ref_python.black_scholes_merton.implied_volatility
¶
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.
py_vollib.ref_python is a pure python version of py_vollib without any dependence on LetsBeRational. It is provided purely as a reference implementation for sanity checking. It is not recommended for industrial use.¶
Module Contents¶
Functions¶
|
Calculate the Black-Scholes-Merton implied volatility. |
- implied_volatility(price, S, K, t, r, q, flag)[source]¶
Calculate the Black-Scholes-Merton implied volatility.
- 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
q (float) – annualized continuous dividend rate
flag (str) – ‘c’ or ‘p’ for call or put.
>>> S = 100 >>> K = 100 >>> sigma = .2 >>> r = .01 >>> flag = 'c' >>> t = .5 >>> q = .02
>>> price = black_scholes_merton(flag, S, K, t, r, sigma, q) >>> implied_volatility(price, S, K, t, r, q, flag) 0.20000000000000018
>>> flac = 'p' >>> sigma = 0.3 >>> price = black_scholes_merton(flag, S, K, t, r, sigma, q) >>> price 8.138101080183894 >>> implied_volatility(price, S, K, t, r, q, flag) 0.30000000000000027