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
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
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.
OptionError
Error related to option calculations or parameters.
This represents issues with the underlying option model or parameters that prevent proper volatility 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
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).
The ATM implied volatility is unavailable; the boxed inner source describes the failing lookup.
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.
Implementations§
Source§impl VolatilityError
impl VolatilityError
Sourcepub fn non_finite(context: &'static str, value: f64) -> Self
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
impl Debug for VolatilityError
Source§impl Display for VolatilityError
impl Display for VolatilityError
Source§impl Error for VolatilityError
impl Error for VolatilityError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<DecimalError> for VolatilityError
impl From<DecimalError> for VolatilityError
Source§fn from(source: DecimalError) -> Self
fn from(source: DecimalError) -> Self
Source§impl From<OptionsError> for VolatilityError
impl From<OptionsError> for VolatilityError
Source§fn from(source: OptionsError) -> Self
fn from(source: OptionsError) -> Self
Source§impl From<PositiveError> for VolatilityError
impl From<PositiveError> for VolatilityError
Source§fn from(source: PositiveError) -> Self
fn from(source: PositiveError) -> Self
Source§impl From<VolatilityError> for GreeksError
Implements conversion from VolatilityError to GreeksError.
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
fn from(error: VolatilityError) -> Self
Auto Trait Implementations§
impl Freeze for VolatilityError
impl RefUnwindSafe for VolatilityError
impl Send for VolatilityError
impl Sync for VolatilityError
impl Unpin for VolatilityError
impl UnsafeUnpin for VolatilityError
impl UnwindSafe for VolatilityError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.