pub enum OptionsError {
ValidationError {
field: String,
reason: String,
},
PricingError {
method: String,
reason: String,
},
GreeksCalculationError {
greek: String,
reason: String,
},
TimeError {
operation: String,
reason: String,
},
PayoffError {
reason: String,
},
UpdateError {
field: String,
reason: String,
},
InvalidStepCount {
operation: &'static str,
},
ImpliedVolatilityInvariant {
reason: String,
},
Decimal(DecimalError),
ExpirationDate(ExpirationDateError),
}Expand description
Custom errors that can occur during Options operations
This enum provides a structured error system for handling various failure scenarios that may arise during option trading operations, calculations, and data management. Each variant represents a specific category of error with contextual information to help with debugging and error handling.
§Variants
-
ValidationError- Errors that occur when validating option parameters such as strike prices, expiration dates, or option styles. -
PricingError- Errors that occur during option price calculation using various pricing models like Black-Scholes, Binomial, etc. -
GreeksCalculationError- Errors that occur when calculating option Greeks (delta, gamma, theta, vega, rho, etc.) which measure option price sensitivities. -
TimeError- Errors related to time calculations, such as determining days to expiration, time decay, or handling calendar adjustments. -
PayoffError- Errors that occur when calculating potential payoffs for options at different price points or expiration scenarios. -
UpdateError- Errors that occur when attempting to update option data or parameters in an existing option object. -
InvalidStepCount- Invalid pricing step count (typed replacement for the formerOtherError). -
ImpliedVolatilityInvariant- Implied-volatility invariant breach.
§Usage
This error type is typically returned in Result objects from functions that perform operations on option contracts, pricing calculations, or option strategy analysis where various error conditions need to be handled.
Variants§
ValidationError
Error when validating option parameters
Used when input parameters for option contracts fail validation.
Fields
PricingError
Error during price calculation
Used when an option pricing algorithm encounters problems.
Fields
GreeksCalculationError
Error when calculating greeks
Used when calculations for option sensitivities (Greeks) fail.
Fields
TimeError
Error when dealing with time calculations
Used for failures in time-related calculations like time to expiry.
Fields
PayoffError
Error when performing payoff calculations
Used when potential profit/loss calculations for options fail.
UpdateError
Error during option data updates
Used when attempts to update option parameters or data fail.
Fields
InvalidStepCount
The caller requested a pricing operation with zero tree steps, which is structurally invalid.
ImpliedVolatilityInvariant
A numerical invariant was breached while constructing a valid implied volatility value from two non-negative bounds.
Decimal(DecimalError)
Error when DecimalError occurs
ExpirationDate(ExpirationDateError)
Expiration-date conversion error surfaced during options operations.
Implementations§
Source§impl OptionsError
Helper methods for creating common options errors.
impl OptionsError
Helper methods for creating common options errors.
This implementation provides convenient factory methods for creating different
variants of OptionsError without having to manually construct the enum variants.
Each method corresponds to a specific error type and properly formats the error fields.
§Methods
validation_error- Creates an error for parameter validation failurespricing_error- Creates an error for pricing calculation issuesgreeks_error- Creates an error for problems with Greeks calculationstime_error- Creates an error for time-related calculationspayoff_error- Creates an error for payoff calculation problemsupdate_error- Creates an error for option data update issues
§Examples
use optionstratlib_core::error::OptionsError;
let error = OptionsError::validation_error("strike_price", "must be positive");
// Create a pricing error
let error = OptionsError::pricing_error("black_scholes", "invalid volatility input");Sourcepub fn validation_error(field: &str, reason: &str) -> Self
pub fn validation_error(field: &str, reason: &str) -> Self
Creates a validation error with the specified field name and reason.
This method is used when option parameters fail validation checks.
§Parameters
field- The name of the field that failed validationreason- The reason why validation failed
§Returns
An OptionsError::ValidationError variant with formatted fields
Sourcepub fn pricing_error(method: &str, reason: &str) -> Self
pub fn pricing_error(method: &str, reason: &str) -> Self
Creates a pricing error with the specified pricing method and reason.
This method is used when an error occurs during option price calculation.
§Parameters
method- The name of the pricing method that encountered an errorreason- The description of what went wrong
§Returns
An OptionsError::PricingError variant with formatted fields
Sourcepub fn greeks_error(greek: &str, reason: &str) -> Self
pub fn greeks_error(greek: &str, reason: &str) -> Self
Creates a Greeks calculation error with the specified Greek name and reason.
This method is used when an error occurs during the calculation of option Greeks (delta, gamma, theta, vega, etc.).
§Parameters
greek- The name of the Greek calculation that failedreason- The description of what went wrong
§Returns
An OptionsError::GreeksCalculationError variant with formatted fields
Sourcepub fn time_error(operation: &str, reason: &str) -> Self
pub fn time_error(operation: &str, reason: &str) -> Self
Creates a time calculation error with the specified operation and reason.
This method is used when an error occurs during time-related calculations, such as time to expiration, day count conventions, or calendar adjustments.
§Parameters
operation- The name of the time operation that failedreason- The description of what went wrong
§Returns
An OptionsError::TimeError variant with formatted fields
Sourcepub fn payoff_error(reason: &str) -> Self
pub fn payoff_error(reason: &str) -> Self
Sourcepub fn update_error(field: &str, reason: &str) -> Self
pub fn update_error(field: &str, reason: &str) -> Self
Creates an update error with the specified field and reason.
This method is used when an error occurs during the update of option parameters or other option data.
§Parameters
field- The name of the field that failed to updatereason- The description of what went wrong
§Returns
An OptionsError::UpdateError variant with formatted fields
Trait Implementations§
Source§impl Debug for OptionsError
impl Debug for OptionsError
Source§impl Display for OptionsError
impl Display for OptionsError
Source§impl Error for OptionsError
impl Error for OptionsError
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()