Crate implied_vol
source ·Expand description
This module provides a Rust implementation of Peter Jäckel’s original C++ code for calculating implied volatilities in financial derivatives. To learn more about the algorithms, please refer to Peter Jäckel’s papers Let’s Be Rational and Implied Normal Volatility.
§Features
- Calculation of implied Black volatility
- Calculation of the price of a European option using the Black-Scholes model
- Calculation of implied normal volatility
- Calculation of the price of an option using Bachelier’s model
All models support both call and put options.
§Examples
Check out the documentation for each function for practical examples.
§Usage
Import the crate in your Rust project by adding the following to your Cargo.toml
[dependencies]
implied-vol = "1.0.0"
Then, in your code, bring the functions you need into scope with:
let black_vol = implied_vol::implied_black_volatility(20.0, 100.0, 90.0, 30.0, true);
assert_eq!(black_vol, 0.07011701801482094);
let price = implied_vol::calculate_european_option_price_by_black_scholes(100.0, 90.0, 0.07011701801482094, 30.0, true);
assert!(((price - 20.0) / price).abs() <= 2.0 * f64::EPSILON);
let normal_vol = implied_vol::implied_normal_volatility(20.0, 100.0, 90.0, 30.0, true);
assert_eq!(normal_vol, 6.614292466299764);
let price = implied_vol::calculate_european_option_price_by_bachelier(100.0, 90.0, 6.614292466299764, 30.0, true);
assert!(((price - 20.0) / price).abs()<= 2.0 * f64::EPSILON);
Moreover, you can use some internal functions if you specify feature flags:
[dependencies]
implied-vol = { versions = "1.0.0", features = ["normal-distribution", "error-function"] }
For detailed explanations of each feature, please refer to the README.md file.
Functions§
- Calculates the price of an option using Bachelier’s model.
- Calculates the price of a European option using the Black-Scholes formula.
- Calculates the implied black volatility using a transformed rational guess with limited iterations.
- Calculates the implied normal volatility.