#[non_exhaustive]pub struct BlackInputs {
pub f: f64,
pub k: f64,
pub t: f64,
pub sigma: f64,
pub r: f64,
}Expand description
Named inputs for Black-76 pricing and Greeks: forward f, strike k,
time-to-expiry t (in years), volatility sigma, and rate r.
A typo-resistant alternative to the positional free functions: every field
is named, so f/k and t/r cannot be silently swapped.
use black_76::{BlackInputs, call_price};
let inputs = BlackInputs::new(100.0, 100.0, 1.0, 0.20, 0.0);
let c = inputs.call_price();
assert!((c - call_price(100.0, 100.0, 1.0, 0.20, 0.0)).abs() < 1e-12);
let g = inputs.greeks(true);
assert!(g.delta > 0.0 && g.gamma > 0.0);New fields may be added in future minor versions; construct via
new (the type is #[non_exhaustive], so struct-literal
construction is unavailable to downstream crates). The public fields
remain readable and serde-serializable.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.f: f64Forward / futures price.
k: f64Strike.
t: f64Time to expiry, in years.
sigma: f64Volatility (annualized).
r: f64Risk-free rate (annualized, continuously compounded).
Implementations§
Source§impl BlackInputs
impl BlackInputs
Sourcepub const fn new(f: f64, k: f64, t: f64, sigma: f64, r: f64) -> Self
pub const fn new(f: f64, k: f64, t: f64, sigma: f64, r: f64) -> Self
Construct inputs from forward, strike, time (years), volatility, rate.
Sourcepub fn call_price(&self) -> f64
pub fn call_price(&self) -> f64
Black-76 call price.
Sourcepub fn greeks(&self, is_call: bool) -> InstrumentGreeks
pub fn greeks(&self, is_call: bool) -> InstrumentGreeks
First-order Greeks (delta, gamma, vega-per-1%, theta-per-day, rho-per-1%).
Sourcepub fn intrinsic_value(&self, is_call: bool) -> f64
pub fn intrinsic_value(&self, is_call: bool) -> f64
Intrinsic value: max(F - K, 0) (call) or max(K - F, 0) (put).
Trait Implementations§
Source§impl Clone for BlackInputs
impl Clone for BlackInputs
Source§fn clone(&self) -> BlackInputs
fn clone(&self) -> BlackInputs
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlackInputs
impl Debug for BlackInputs
Source§impl<'de> Deserialize<'de> for BlackInputs
impl<'de> Deserialize<'de> for BlackInputs
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for BlackInputs
impl PartialEq for BlackInputs
Source§fn eq(&self, other: &BlackInputs) -> bool
fn eq(&self, other: &BlackInputs) -> bool
self and other values to be equal, and is used by ==.