Skip to main content

BlackInputs

Struct BlackInputs 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§f: f64

Forward / futures price.

§k: f64

Strike.

§t: f64

Time to expiry, in years.

§sigma: f64

Volatility (annualized).

§r: f64

Risk-free rate (annualized, continuously compounded).

Implementations§

Source§

impl BlackInputs

Source

pub const fn new(f: f64, k: f64, t: f64, sigma: f64, r: f64) -> Self

Construct inputs from forward, strike, time (years), volatility, rate.

Source

pub fn d1_d2(&self) -> (f64, f64)

(d1, d2) for these inputs (independent of r).

Source

pub fn call_price(&self) -> f64

Black-76 call price.

Source

pub fn put_price(&self) -> f64

Black-76 put price.

Source

pub fn price(&self, is_call: bool) -> f64

Call or put price, selected by is_call.

Source

pub fn vega(&self) -> f64

Vega (price change per 1.0 absolute change in volatility).

Source

pub fn greeks(&self, is_call: bool) -> InstrumentGreeks

First-order Greeks (delta, gamma, vega-per-1%, theta-per-day, rho-per-1%).

Source

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

Source§

fn clone(&self) -> BlackInputs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlackInputs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BlackInputs

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for BlackInputs

Source§

fn eq(&self, other: &BlackInputs) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for BlackInputs

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for BlackInputs

Source§

impl StructuralPartialEq for BlackInputs

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,