pub enum StrategyError {
PriceError(PriceErrorKind),
BreakEvenError(BreakEvenErrorKind),
ProfitLossError(ProfitLossErrorKind),
OperationError(OperationErrorKind),
NotImplemented,
Simulation(Box<SimulationError>),
GreeksError(GreeksError),
PositiveError(PositiveError),
NumericConversion {
value: f64,
},
MissingGreek {
name: &'static str,
},
EmptyCollection {
context: String,
},
}Expand description
Represents the different types of errors that can occur in options trading strategies.
This enum acts as a comprehensive error type for the options strategy module, grouping more specific error categories for better error handling. Each variant corresponds to a different domain of potential failures within options strategy operations.
§Variants
PriceError- Errors related to pricing operations such as invalid prices or rangesBreakEvenError- Errors encountered when calculating strategy break-even pointsProfitLossError- Errors related to profit/loss calculations including maximum valuesOperationError- General strategy operation errors including unsupported operationsNotImplemented- For features or operations that are not yet implementedSimulation- Simulation-layer errors surfaced while evaluating a strategy
§Usage
This error type is designed to be returned from functions that perform operations on options trading strategies, providing structured and detailed error information to facilitate debugging and error handling.
Variants§
PriceError(PriceErrorKind)
Errors related to price calculations
BreakEvenError(BreakEvenErrorKind)
Errors related to break-even points
ProfitLossError(ProfitLossErrorKind)
Errors related to profit/loss calculations
OperationError(OperationErrorKind)
Errors related to strategy operations
NotImplemented
Indicates a feature or operation that has not been implemented yet
Simulation(Box<SimulationError>)
A simulation-layer error surfaced while evaluating a strategy.
GreeksError(GreeksError)
Greeks errors
PositiveError(PositiveError)
Positive value errors
NumericConversion
Numeric conversion failed at the f64 ↔ Decimal boundary.
Raised when a non-finite (NaN / ±Inf) f64 cannot be represented
as a Decimal, or when a representation overflow occurs.
MissingGreek
A required greek value was missing from an option.
Raised when a strategy expects a greek (delta, gamma, vega, theta,
rho) to be present on an option (e.g., for delta-neutral validation)
but the option’s greek calculation returned None.
EmptyCollection
A required collection was empty when at least one element was expected.
Raised when a strategy operation needs to pick an element out of a collection (option chain, break-even points, profit ranges) and the collection turned out to be empty.
Implementations§
Source§impl StrategyError
impl StrategyError
Sourcepub fn operation_not_supported(operation: &str, strategy_type: &str) -> Self
pub fn operation_not_supported(operation: &str, strategy_type: &str) -> Self
Creates a StrategyError for an unsupported operation on a specific strategy type.
This helper method creates a structured error describing an operation that cannot be performed on a particular strategy type, encapsulating both the attempted operation name and the strategy type that doesn’t support it.
§Parameters
operation- The name of the operation that was attempted but is not supportedstrategy_type- The type of strategy for which the operation is not supported
§Returns
A StrategyError::OperationError variant with the NotSupported kind
§Example
use optionstratlib::error::strategies::StrategyError;
// Creating an error when trying to calculate butterfly spread adjustment on an iron condor
let error = StrategyError::operation_not_supported("butterfly_adjustment", "IronCondor");Sourcepub fn invalid_parameters(operation: &str, reason: &str) -> Self
pub fn invalid_parameters(operation: &str, reason: &str) -> Self
Creates a StrategyError for invalid parameters provided to an operation.
This helper method builds a structured error for cases when an operation fails due to invalid or insufficient parameters, providing context about both the operation and the specific validation issue.
§Parameters
operation- The name of the operation that failed due to invalid parametersreason- A descriptive explanation of why the parameters are invalid
§Returns
A StrategyError::OperationError variant with the InvalidParameters kind
§Example
use optionstratlib::error::strategies::StrategyError;
// Creating an error when strike prices are invalid for a strategy
let error = StrategyError::invalid_parameters(
"create_vertical_spread",
"Short strike must be higher than long strike for call spreads"
);Sourcepub fn numeric_conversion(value: f64) -> Self
pub fn numeric_conversion(value: f64) -> Self
Builds a NumericConversion error for an f64 that could not be
converted to a Decimal (typically NaN / Inf or overflow).
§Errors
This is an error constructor — it always returns the variant.
Sourcepub fn missing_greek(name: &'static str) -> Self
pub fn missing_greek(name: &'static str) -> Self
Builds a MissingGreek error for an option missing a required greek.
§Errors
This is an error constructor — it always returns the variant.
Sourcepub fn empty_collection(context: impl Into<String>) -> Self
pub fn empty_collection(context: impl Into<String>) -> Self
Builds an EmptyCollection error for an unexpectedly empty collection.
§Errors
This is an error constructor — it always returns the variant.
Trait Implementations§
Source§impl Debug for StrategyError
impl Debug for StrategyError
Source§impl Display for StrategyError
impl Display for StrategyError
Source§impl Error for StrategyError
impl Error for StrategyError
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<GreeksError> for StrategyError
impl From<GreeksError> for StrategyError
Source§fn from(source: GreeksError) -> Self
fn from(source: GreeksError) -> Self
Source§impl From<OptionsError> for StrategyError
impl From<OptionsError> for StrategyError
Source§fn from(err: OptionsError) -> Self
fn from(err: OptionsError) -> Self
Source§impl From<PositionError> for StrategyError
impl From<PositionError> for StrategyError
Source§fn from(err: PositionError) -> Self
fn from(err: PositionError) -> Self
Source§impl From<PositiveError> for StrategyError
impl From<PositiveError> for StrategyError
Source§fn from(source: PositiveError) -> Self
fn from(source: PositiveError) -> Self
Source§impl From<PricingError> for StrategyError
impl From<PricingError> for StrategyError
Source§fn from(err: PricingError) -> Self
fn from(err: PricingError) -> Self
Source§impl From<SimulationError> for StrategyError
impl From<SimulationError> for StrategyError
Source§fn from(err: SimulationError) -> Self
fn from(err: SimulationError) -> Self
Source§impl From<StrategyError> for PositionError
impl From<StrategyError> for PositionError
Source§fn from(error: StrategyError) -> Self
fn from(error: StrategyError) -> Self
Source§impl From<StrategyError> for ProbabilityError
impl From<StrategyError> for ProbabilityError
Source§fn from(error: StrategyError) -> Self
fn from(error: StrategyError) -> Self
Source§impl From<StrategyError> for SimulationError
impl From<StrategyError> for SimulationError
Source§fn from(err: StrategyError) -> Self
fn from(err: StrategyError) -> Self
Source§impl From<StrategyError> for Error
impl From<StrategyError> for Error
Source§fn from(source: StrategyError) -> Self
fn from(source: StrategyError) -> Self
Source§impl From<TradeError> for StrategyError
impl From<TradeError> for StrategyError
Source§fn from(value: TradeError) -> Self
fn from(value: TradeError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for StrategyError
impl !UnwindSafe for StrategyError
impl Freeze for StrategyError
impl Send for StrategyError
impl Sync for StrategyError
impl Unpin for StrategyError
impl UnsafeUnpin for StrategyError
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.