Skip to main content

OptionsError

Enum OptionsError 

Source
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 former OtherError).

  • 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

§field: String

The field name that failed validation

§reason: String

Detailed explanation of the validation failure

§

PricingError

Error during price calculation

Used when an option pricing algorithm encounters problems.

Fields

§method: String

The pricing method that failed (e.g., “Black-Scholes”, “Binomial”)

§reason: String

Detailed explanation of the pricing calculation failure

§

GreeksCalculationError

Error when calculating greeks

Used when calculations for option sensitivities (Greeks) fail.

Fields

§greek: String

The specific Greek that failed to calculate (delta, gamma, theta, etc.)

§reason: String

Detailed explanation of the Greek calculation failure

§

TimeError

Error when dealing with time calculations

Used for failures in time-related calculations like time to expiry.

Fields

§operation: String

The time-related operation that failed

§reason: String

Detailed explanation of the time calculation failure

§

PayoffError

Error when performing payoff calculations

Used when potential profit/loss calculations for options fail.

Fields

§reason: String

Detailed explanation of the payoff calculation failure

§

UpdateError

Error during option data updates

Used when attempts to update option parameters or data fail.

Fields

§field: String

The field that failed to update

§reason: String

Detailed explanation of the update failure

§

InvalidStepCount

The caller requested a pricing operation with zero tree steps, which is structurally invalid.

Fields

§operation: &'static str

Name of the operation that rejected the step count (e.g. "binomial").

§

ImpliedVolatilityInvariant

A numerical invariant was breached while constructing a valid implied volatility value from two non-negative bounds.

Fields

§reason: String

Detailed explanation of which invariant was breached.

§

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.

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 failures
  • pricing_error - Creates an error for pricing calculation issues
  • greeks_error - Creates an error for problems with Greeks calculations
  • time_error - Creates an error for time-related calculations
  • payoff_error - Creates an error for payoff calculation problems
  • update_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");
Source

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 validation
  • reason - The reason why validation failed
§Returns

An OptionsError::ValidationError variant with formatted fields

Source

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 error
  • reason - The description of what went wrong
§Returns

An OptionsError::PricingError variant with formatted fields

Source

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 failed
  • reason - The description of what went wrong
§Returns

An OptionsError::GreeksCalculationError variant with formatted fields

Source

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 failed
  • reason - The description of what went wrong
§Returns

An OptionsError::TimeError variant with formatted fields

Source

pub fn payoff_error(reason: &str) -> Self

Creates a payoff calculation error with the specified reason.

This method is used when an error occurs during the calculation of option payoffs.

§Parameters
  • reason - The description of what went wrong
§Returns

An OptionsError::PayoffError variant with formatted reason

Source

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 update
  • reason - The description of what went wrong
§Returns

An OptionsError::UpdateError variant with formatted fields

Trait Implementations§

Source§

impl Debug for OptionsError

Source§

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

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

impl Display for OptionsError

Source§

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

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

impl Error for OptionsError

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<DecimalError> for OptionsError

Source§

fn from(source: DecimalError) -> Self

Converts to this type from the input type.
Source§

impl From<ExpirationDateError> for OptionsError

Source§

fn from(source: ExpirationDateError) -> Self

Converts to this type from the input type.
Source§

impl From<OptionsError> for PositionError

Source§

fn from(source: OptionsError) -> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<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