Struct ImpliedBlackVolatility

Source
pub struct ImpliedBlackVolatility { /* private fields */ }
Expand description

Builder-backed container that represents the inputs required to compute the implied Black volatility for an undiscounted European option.

Use the generated ImpliedBlackVolatility::builder() to construct this type. The builder performs input validation when you call .build(). Or use .build_unchecked() to skip validation.

Fields:

  • forward: forward price of the underlying (F). Must be finite and > 0.
  • strike: strike price (K). Must be finite and > 0.
  • expiry: time to expiry (T). Must be finite and >= 0.
  • is_call: true for a call option, false for a put option.
  • option_price: observed undiscounted option price (P). Must be finite and >= 0.

This struct is consumed by calculate::<SpFn>() which performs the numerical inversion BS(F, K, T, σ) = P to find the implied volatility σ.

Implementations§

Source§

impl ImpliedBlackVolatility

Source

pub const fn builder() -> ImpliedBlackVolatilityBuilder

Create an instance of ImpliedBlackVolatility using the builder syntax

Source§

impl ImpliedBlackVolatility

Source

pub fn calculate<SpFn: SpecialFn>(&self) -> Option<f64>

Compute the implied Black volatility σ for the stored inputs.

Returns:

  • Some(σ) if an implied volatility consistent with BS(F, K, T, σ) = P exists, and the numerical routine converges to a finite value.
  • None if the given option_price is outside the attainable range for the supplied model parameters.
§Type parameter
  • SpFn: SpecialFn — implementation of the SpecialFn trait used for internal special-function computations. Use DefaultSpecialFn for the crate-provided default behavior, or supply your own implementation to change numerical characteristics.
§Examples
use implied_vol::{DefaultSpecialFn, ImpliedBlackVolatility};

let iv = ImpliedBlackVolatility::builder()
    .option_price(10.0)
    .forward(100.0)
    .strike(100.0)
    .expiry(1.0)
    .is_call(true)
    .build().unwrap();

let sigma = iv.calculate::<DefaultSpecialFn>().unwrap();
assert!(sigma.is_finite());

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> 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, 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.