pub struct Inputs {
pub option_type: OptionType,
pub f: f32,
pub k: f32,
pub p: Option<f32>,
pub r: f32,
pub q: f32,
pub t: f32,
pub sigma: Option<f32>,
}Expand description
The inputs to the Black-Scholes-Merton model.
Fields§
§option_type: OptionTypeThe type of the option (call or put)
f: f32Futures price
k: f32Strike price
p: Option<f32>Option price
r: f32Risk-free rate
q: f32Dividend yield
t: f32Time to maturity in years
sigma: Option<f32>Volatility
Implementations§
source§impl Inputs
impl Inputs
Methods for calculating the price, greeks, and implied volatility of an option.
sourcepub fn new(
option_type: OptionType,
f: f32,
k: f32,
p: Option<f32>,
r: f32,
q: f32,
t: f32,
sigma: Option<f32>
) -> Self
pub fn new( option_type: OptionType, f: f32, k: f32, p: Option<f32>, r: f32, q: f32, t: f32, sigma: Option<f32> ) -> Self
Creates instance ot the Inputs struct.
Arguments
option_type- The type of option to be priced.f- The current price of the underlying asset.k- The strike price of the option.p- The dividend yield of the underlying asset.r- The risk-free interest rate.q- The dividend yield of the underlying asset.t- The time to maturity of the option in years.sigma- The volatility of the underlying asset.
Example
use blackscholes::{Inputs, OptionType};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));Returns
An instance of the Inputs struct.
Trait Implementations§
source§impl Greeks<f32> for Inputs
impl Greeks<f32> for Inputs
Note:
The only verified formulas are for the delta, vega, theta, rho, gamma, vanna, and vomma, sourced from here. The remaining greeks were sourced from the same page, with r swapped for q. If you find that any of these formulas are incorrect, please open an issue on the github repo.
source§fn calc_theta(&self) -> Result<f32, String>
fn calc_theta(&self) -> Result<f32, String>
Calculates the theta of the option. Uses 365.25 days in a year for calculations.
Requires
f, k, r, t, sigma
Returns
f32 of theta per day (not per year).
Example
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let theta = inputs.calc_theta().unwrap();source§fn calc_epsilon(&self) -> Result<f32, String>
fn calc_epsilon(&self) -> Result<f32, String>
Calculates the epsilon of the option.
Requires
f, k, r, t, sigma
Returns
f32 of the epsilon of the option.
Example
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let epsilon = inputs.calc_epsilon().unwrap();source§fn calc_lambda(&self) -> Result<f32, String>
fn calc_lambda(&self) -> Result<f32, String>
Calculates the lambda of the option.
Requires
s, k, r, q, t, sigma
Returns
f32 of the lambda of the option.
Example
use blackscholes::{Inputs, OptionType, Greeks, Pricing};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let lambda = inputs.calc_lambda().unwrap();source§fn calc_charm(&self) -> Result<f32, String>
fn calc_charm(&self) -> Result<f32, String>
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let charm = inputs.calc_charm().unwrap();source§fn calc_ultima(&self) -> Result<f32, String>
fn calc_ultima(&self) -> Result<f32, String>
Calculates the ultima of the option.
Requires
f, k, r, t, sigma
Returns
f32 of the ultima of the option.
Example
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let ultima = inputs.calc_ultima().unwrap();source§fn calc_dual_delta(&self) -> Result<f32, String>
fn calc_dual_delta(&self) -> Result<f32, String>
Calculates the dual delta of the option.
Requires
f, k, r, t, sigma
Returns
f32 of the dual delta of the option.
Example
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let dual_delta = inputs.calc_dual_delta().unwrap();source§fn calc_dual_gamma(&self) -> Result<f32, String>
fn calc_dual_gamma(&self) -> Result<f32, String>
Calculates the dual gamma of the option.
Requires
f, k, r, t, sigma
Returns
f32 of the dual gamma of the option.
Example
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let dual_gamma = inputs.calc_dual_gamma().unwrap();source§fn calc_all_greeks(&self) -> Result<HashMap<String, f32>, String>
fn calc_all_greeks(&self) -> Result<HashMap<String, f32>, String>
Calculates all Greeks of the option.
Requires
f, k, r, t, sigma
Returns
HashMap of type <String, f32> of all Greeks of the option.
Example
use blackscholes::{Inputs, OptionType, Greeks};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let greeks = inputs.calc_all_greeks().unwrap();source§impl ImpliedVolatility<f32> for Inputs
impl ImpliedVolatility<f32> for Inputs
source§fn calc_iv(&self, tolerance: f32) -> Result<f32, String>
fn calc_iv(&self, tolerance: f32) -> Result<f32, String>
Calculates the implied volatility of the option. Tolerance is the max error allowed for the implied volatility, the lower the tolerance the more iterations will be required. Recommended to be a value between 0.001 - 0.0001 for highest efficiency/accuracy. Initializes estimation of sigma using Brenn and Subrahmanyam (1998) method of calculating initial iv estimation. Uses Newton Raphson algorithm to calculate implied volatility.
Requires
f, k, r, q, t, p
Returns
f32 of the implied volatility of the option.
Example:
use blackscholes::{Inputs, OptionType, ImpliedVolatility};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, Some(0.2), 0.05, 0.2, 20.0/365.25, None);
let iv = inputs.calc_iv(0.0001).unwrap();source§impl PartialEq<Inputs> for Inputs
impl PartialEq<Inputs> for Inputs
source§impl Pricing<f32> for Inputs
impl Pricing<f32> for Inputs
source§fn calc_price(&self) -> Result<f32, String>
fn calc_price(&self) -> Result<f32, String>
Calculates the price of the option.
Requires
f, k, r, q, t, sigma.
Returns
f32 of the price of the option.
Example
use blackscholes::{Inputs, OptionType, Pricing};
let inputs = Inputs::new(OptionType::Call, 100.0, 100.0, None, 0.05, 0.2, 20.0/365.25, Some(0.2));
let price = inputs.calc_price().unwrap();impl Copy for Inputs
impl StructuralPartialEq for Inputs
Auto Trait Implementations§
impl RefUnwindSafe for Inputs
impl Send for Inputs
impl Sync for Inputs
impl Unpin for Inputs
impl UnwindSafe for Inputs
Blanket Implementations§
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.