optionstratlib/error/metrics.rs
1/******************************************************************************
2 Author: Joaquín Béjar García
3 Email: jb@taunais.com
4 Date: 22/1/25
5******************************************************************************/
6use crate::error::{CurveError, SurfaceError};
7use thiserror::Error;
8
9/// Error types specifically related to financial and statistical metrics calculations.
10///
11/// This enum represents various error conditions that can occur during metrics
12/// processing, analysis, and validation within the library's metrics module.
13/// Each variant provides context about the specific type of error encountered.
14///
15/// # Variants
16///
17/// * `BasicError` - General metrics calculation errors
18/// * `ShapeError` - Errors related to data shape mismatches or incompatible dimensions
19/// * `RangeError` - Errors when data falls outside of expected/valid ranges
20/// * `TrendError` - Errors in trend analysis, regression, or pattern detection
21/// * `RiskError` - Errors in risk metrics calculations (like VaR, Sharpe ratio, etc.)
22/// * `Curve` - Errors related to curve-fitting or curve-based calculations
23/// * `Surface` - Errors in surface modeling or multi-dimensional metrics
24///
25/// # Examples
26///
27/// ```
28/// use optionstratlib::error::MetricsError;
29///
30/// // Creating different error types
31/// let basic_err = MetricsError::BasicError("Calculation failed".to_string());
32/// let range_err = MetricsError::RangeError("Value outside expected bounds".to_string());
33/// ```
34#[derive(Error, Debug)]
35pub enum MetricsError {
36 /// General errors in metrics calculations.
37 #[error("Basic Error: {0}")]
38 BasicError(String),
39
40 /// Errors related to data shape mismatches or dimensional incompatibility.
41 /// This typically occurs when input data has an unexpected structure.
42 #[error("Shape Error: {0}")]
43 ShapeError(String),
44
45 /// Errors when data falls outside expected or valid ranges.
46 /// This can indicate outliers or invalid input values.
47 #[error("Range Error: {0}")]
48 RangeError(String),
49
50 /// Errors in trend analysis, regression, or pattern detection algorithms.
51 #[error("Trend Error: {0}")]
52 TrendError(String),
53
54 /// Errors specifically related to financial risk metrics calculations,
55 /// such as Value at Risk (VaR), Conditional VaR, or Sharpe ratio.
56 #[error("Risk Error: {0}")]
57 RiskError(String),
58
59 /// Errors encountered during curve-fitting or curve-based calculations,
60 /// such as yield curves or volatility curves.
61 #[error(transparent)]
62 Curve(#[from] CurveError),
63
64 /// Errors in surface modeling or multi-dimensional metrics,
65 /// such as volatility surfaces or correlation matrices.
66 #[error(transparent)]
67 Surface(#[from] SurfaceError),
68}