pub enum MetricsError {
BasicError(String),
ShapeError(String),
RangeError(String),
TrendError(String),
RiskError(String),
Curve(CurveError),
Surface(SurfaceError),
}Expand description
Error types specifically related to financial and statistical metrics calculations.
This enum represents various error conditions that can occur during metrics processing, analysis, and validation within the library’s metrics module. Each variant provides context about the specific type of error encountered.
§Variants
BasicError- General metrics calculation errorsShapeError- Errors related to data shape mismatches or incompatible dimensionsRangeError- Errors when data falls outside of expected/valid rangesTrendError- Errors in trend analysis, regression, or pattern detectionRiskError- Errors in risk metrics calculations (like VaR, Sharpe ratio, etc.)Curve- Errors related to curve-fitting or curve-based calculationsSurface- Errors in surface modeling or multi-dimensional metrics
§Examples
use optionstratlib::error::MetricsError;
// Creating different error types
let basic_err = MetricsError::BasicError("Calculation failed".to_string());
let range_err = MetricsError::RangeError("Value outside expected bounds".to_string());Variants§
BasicError(String)
General errors in metrics calculations.
ShapeError(String)
Errors related to data shape mismatches or dimensional incompatibility. This typically occurs when input data has an unexpected structure.
RangeError(String)
Errors when data falls outside expected or valid ranges. This can indicate outliers or invalid input values.
TrendError(String)
Errors in trend analysis, regression, or pattern detection algorithms.
RiskError(String)
Errors specifically related to financial risk metrics calculations, such as Value at Risk (VaR), Conditional VaR, or Sharpe ratio.
Curve(CurveError)
Errors encountered during curve-fitting or curve-based calculations, such as yield curves or volatility curves.
Surface(SurfaceError)
Errors in surface modeling or multi-dimensional metrics, such as volatility surfaces or correlation matrices.
Trait Implementations§
Source§impl Debug for MetricsError
impl Debug for MetricsError
Source§impl Display for MetricsError
impl Display for MetricsError
Source§impl Error for MetricsError
impl Error for MetricsError
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<CurveError> for MetricsError
impl From<CurveError> for MetricsError
Source§fn from(source: CurveError) -> Self
fn from(source: CurveError) -> Self
Source§impl From<MetricsError> for CurveError
Converts a PositionError into a CurvesError by mapping it to an
OperationError with the InvalidParameters variant.
impl From<MetricsError> for CurveError
Converts a PositionError into a CurvesError by mapping it to an
OperationError with the InvalidParameters variant.
This implementation ensures a smooth transition between error types
when a PositionError is encountered within a context that operates
on the curves module. The InvalidParameters variant is used to
provide detailed information about the failed operation and the reason
for its failure.
§Details:
- The
operationfield is hardcoded as"Position"to indicate the context of the error (i.e., relating to position management). - The
reasonfield is derived from theto_stringrepresentation of thePositionError, ensuring a human-readable explanation.
§Example Integration:
- If a
PositionErroris encountered during curve calculations, this implementation converts it into aCurvesErrorfor consistent error handling within thecurvesmodule. - The generated
CurvesErrorprovides detailed diagnostic information about the reason for the failure, enabling effective debugging.
§Implementation Notes:
- This conversion leverages the
OperationErrorKind::InvalidParametersvariant to communicate that invalid parameters (or settings) were the root cause of failure. - Use this implementation to handle interoperability between error types in modular design contexts.
§Example Use Case:
This conversion is frequently used in scenarios where:
- A position-related error (e.g., from validation or limits) occurs during a curve operation.
- Such errors need to be mapped into the
CurvesErrordomain to maintain consistent error handling across the library.
§Debugging:
The resulting CurvesError will include contextual details, making it
straightforward to trace and debug the underlying issue.
Source§fn from(err: MetricsError) -> Self
fn from(err: MetricsError) -> Self
Source§impl From<MetricsError> for Error
impl From<MetricsError> for Error
Source§fn from(source: MetricsError) -> Self
fn from(source: MetricsError) -> Self
Source§impl From<SurfaceError> for MetricsError
impl From<SurfaceError> for MetricsError
Source§fn from(source: SurfaceError) -> Self
fn from(source: SurfaceError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for MetricsError
impl !UnwindSafe for MetricsError
impl Freeze for MetricsError
impl Send for MetricsError
impl Sync for MetricsError
impl Unpin for MetricsError
impl UnsafeUnpin for MetricsError
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.