Skip to main content

VolatilityError

Enum VolatilityError 

Source
pub enum VolatilityError {
Show 14 variants InvalidPrice { price: Positive, reason: String, }, InvalidTime { time: Positive, reason: String, }, ZeroVega, Options(OptionsError), VegaError { reason: String, }, OptionError { reason: String, }, NoConvergence { iterations: u32, last_volatility: Positive, }, IvNotFound, NoValidVolatility, NumericalFailure { reason: String, }, AtmIvUnavailable { source: Box<VolatilityError>, }, PositiveError(PositiveError), DecimalError(DecimalError), NonFinite { context: &'static str, value: f64, },
}
Expand description

Represents errors that can occur during volatility-related calculations.

This enum encapsulates various error conditions that may arise during implied volatility calculations, volatility surface generation, or other volatility-related operations. It provides detailed context about what went wrong, including invalid inputs, numerical issues, and convergence failures.

VolatilityError is particularly useful for diagnosing problems in option pricing models that rely on volatility parameters, such as Black-Scholes or binomial models.

Variants§

§

InvalidPrice

Error indicating that a price value is invalid for volatility calculations.

This variant is used when a price input doesn’t meet the requirements for volatility calculation, such as being negative or outside valid bounds.

Fields

§price: Positive

The invalid price value that caused the error.

§reason: String

A description explaining why the price is invalid.

§

InvalidTime

Error indicating that a time value is invalid for volatility calculations.

This occurs when time parameters (such as time to expiration) are invalid for volatility calculations, for example being negative or too large.

Fields

§time: Positive

The invalid time value that caused the error.

§reason: String

A description explaining why the time value is invalid.

§

ZeroVega

Error indicating that the vega value is zero.

This occurs when attempting to calculate implied volatility using the Newton-Raphson method and vega is zero, making it impossible to converge.

§

Options(OptionsError)

Error related to option calculations.

§

VegaError

Error related to vega calculations or usage.

This represents more general issues with vega calculations beyond just zero values.

Fields

§reason: String

A description of what went wrong with the vega calculation.

§

OptionError

Error related to option calculations or parameters.

This represents issues with the underlying option model or parameters that prevent proper volatility calculation.

Fields

§reason: String

A description of what went wrong with the option calculation.

§

NoConvergence

Error indicating that an iterative volatility calculation failed to converge.

This typically occurs in numerical methods like Newton-Raphson or bisection when trying to solve for implied volatility.

Fields

§iterations: u32

The number of iterations that were performed before giving up.

§last_volatility: Positive

The last volatility value that was calculated before giving up.

§

IvNotFound

No implied-volatility candidate produced a price match after the grid search.

§

NoValidVolatility

None of the generated volatility samples produced a valid price.

§

NumericalFailure

A numerical precision or representation failure inside a Heston-style volatility simulation kernel (e.g. sqrt overflow, f64/Decimal bridge).

Fields

§reason: String

Human-readable description of which numerical step failed.

§

AtmIvUnavailable

The ATM implied volatility is unavailable; the boxed inner source describes the failing lookup.

Fields

§source: Box<VolatilityError>

Underlying error that explains why the ATM IV could not be retrieved.

§

PositiveError(PositiveError)

Positive value errors

§

DecimalError(DecimalError)

Decimal arithmetic failures propagated from monetary-flow computations in volatility kernels (overflow, division by zero, conversion).

Produced when a checked Decimal helper in model::decimal surfaces a optionstratlib_core::error::DecimalError from inside a volatility routine (for example constant_volatility, ewma_volatility, or garch_volatility). Propagated transparently via the #[from] cascade so callers keep matching VolatilityError.

§

NonFinite

A volatility kernel produced a non-finite f64 value (NaN / ±∞) at an f64 → Decimal boundary.

Emitted by the Newton-Raphson implied-volatility solver, the bisection fallback, Heston simulation discretisations, and any other volatility routine that bridges f64 sqrt/ln/exp results back into Decimal. context is a static call-site tag following the same convention as optionstratlib_core::error::DecimalError::Overflow.

Fields

§context: &'static str

Static tag identifying the kernel and step that produced the non-finite value.

§value: f64

The offending f64 value (NaN, +∞, or -∞).

Implementations§

Source§

impl VolatilityError

Source

pub fn non_finite(context: &'static str, value: f64) -> Self

Creates a VolatilityError::NonFinite from a static call-site tag and the offending f64 value.

Trait Implementations§

Source§

impl Debug for VolatilityError

Source§

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

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

impl Display for VolatilityError

Source§

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

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

impl Error for VolatilityError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecimalError> for VolatilityError

Source§

fn from(source: DecimalError) -> Self

Converts to this type from the input type.
Source§

impl From<OptionsError> for VolatilityError

Source§

fn from(source: OptionsError) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveError> for VolatilityError

Source§

fn from(source: PositiveError) -> Self

Converts to this type from the input type.
Source§

impl From<VolatilityError> for GreeksError

Implements conversion from VolatilityError to GreeksError.

This implementation allows volatility-related errors to be automatically converted into appropriate InputErrorKind::InvalidVolatility errors, providing consistent error handling for invalid volatility values.

Source§

fn from(error: VolatilityError) -> Self

Converts to this type from the input type.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more