pub fn black(
forward_price: f64,
strike_price: f64,
sigma: f64,
time_to_maturity: f64,
option_type: OptionType,
) -> f64Expand description
Calculates the price of a European option using the Black model.
This function computes the theoretical price of a European call or put option based on the Black model, which is an extension of the Black-Scholes model for futures contracts. The model assumes that the price of the underlying asset follows a geometric Brownian motion and that markets are frictionless.
§Arguments
forward_price- The forward price of the underlying asset.strike_price- The strike price of the option.sigma- The volatility of the underlying asset’s returns.time_to_maturity- The time to maturity of the option, in years.option_type- The type of the option (call or put), represented byOptionType.
§Returns
The theoretical price of the option as a f64.
§Examples
use blackscholes::{OptionType, lets_be_rational::black};
let forward_price = 100.0;
let strike_price = 95.0;
let sigma = 0.2;
let time_to_maturity = 1.0;
let option_type = OptionType::Call; // For a call option
let price = black(forward_price, strike_price, sigma, time_to_maturity, option_type);
println!("The price of the option is: {}", price);§Note
The function uses the natural logarithm of the forward price over the strike price, multiplies it by the square root of time to maturity, and applies the option type to determine the final price. It’s suitable for European options only.