Skip to main content

StrategyError

Enum StrategyError 

Source
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 ranges
  • BreakEvenError - Errors encountered when calculating strategy break-even points
  • ProfitLossError - Errors related to profit/loss calculations including maximum values
  • OperationError - General strategy operation errors including unsupported operations
  • NotImplemented - For features or operations that are not yet implemented
  • Simulation - 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 f64Decimal boundary.

Raised when a non-finite (NaN / ±Inf) f64 cannot be represented as a Decimal, or when a representation overflow occurs.

Fields

§value: f64

The offending f64 value that could not be converted.

§

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.

Fields

§name: &'static str

Name of the greek ("delta", "gamma", "vega", "theta", "rho").

§

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.

Fields

§context: String

Description of where the empty collection was encountered.

Implementations§

Source§

impl StrategyError

Source

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 supported
  • strategy_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");
Source

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 parameters
  • reason - 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"
);
Source

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.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for StrategyError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for StrategyError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<GreeksError> for StrategyError

Source§

fn from(source: GreeksError) -> Self

Converts to this type from the input type.
Source§

impl From<OptionsError> for StrategyError

Source§

fn from(err: OptionsError) -> Self

Converts to this type from the input type.
Source§

impl From<PositionError> for StrategyError

Source§

fn from(err: PositionError) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveError> for StrategyError

Source§

fn from(source: PositiveError) -> Self

Converts to this type from the input type.
Source§

impl From<PricingError> for StrategyError

Source§

fn from(err: PricingError) -> Self

Converts to this type from the input type.
Source§

impl From<SimulationError> for StrategyError

Source§

fn from(err: SimulationError) -> Self

Converts to this type from the input type.
Source§

impl From<StrategyError> for PositionError

Source§

fn from(error: StrategyError) -> Self

Converts to this type from the input type.
Source§

impl From<StrategyError> for ProbabilityError

Source§

fn from(error: StrategyError) -> Self

Converts to this type from the input type.
Source§

impl From<StrategyError> for SimulationError

Source§

fn from(err: StrategyError) -> Self

Converts to this type from the input type.
Source§

impl From<StrategyError> for Error

Source§

fn from(source: StrategyError) -> Self

Converts to this type from the input type.
Source§

impl From<TradeError> for StrategyError

Source§

fn from(value: TradeError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more