pub fn implied_volatility(
price: f64,
S: f64,
K: f64,
T: f64,
r: f64,
flag: TypeFlag,
) -> f64Expand description
Implied volatility function to calculate the implied volatility of an option given its market price. The method is based on lets be rational paper Let’s Be Rational by Peter Jaeckel with some modifications. If price is below intrinsic value, it returns -INF, if price is above intrinsic value, it returns INF.
use RustQuant::instruments::options::implied_volatility::*;
use RustQuant::instruments::options::TypeFlag;
use RustQuant::utils::assert_approx_equal;
let price = 12.3;
let S = 100.0;
let K = 110.0;
let T = 0.89;
let r = 0.03;
let option_type = TypeFlag::Call;
let iv = implied_volatility(price, S, K, T, r, option_type);
assert_approx_equal!(iv, 0.40269973285787297, 1e-15);