Skip to main content

Module error

Module error 

Source
Expand description
  • error - Error types and handling functionality for the library.

Defines the error hierarchy used throughout the library, providing detailed error types for different categories of failures including validation errors, calculation errors, and input/output errors.

§Error Module

This module provides a comprehensive error handling system for options trading and financial calculations. It defines specialized error types for different aspects of the library, including options trading, pricing calculations, statistical analysis, and data management.

§Core Modules Overview

§Options and Pricing

  • OptionsError - Core errors for option operations and validations
  • GreeksError - Errors in Greeks calculations (delta, gamma, etc.)
  • VolatilityError - Errors in volatility calculations including implied volatility

§Trading and Analysis

  • ChainError - Option chain operations and data management
  • TradeError - Trade position opening and status management
  • PositionError - Position management and trading operations
  • StrategyError - Trading strategy validation and execution
  • ProbabilityError - Statistical analysis and probability calculations

§Mathematical and Data

  • CurveError - Curve fitting and mathematical operations
  • DecimalError - Decimal number handling and precision
  • InterpolationError - Errors in data interpolation operations
  • MetricsError - Performance and risk metrics calculation errors
  • SurfaceError - Volatility and pricing surface construction errors

§Usage Example

use optionstratlib::error::{OptionsError, GreeksError, ChainError};

// Options error handling
fn calculate_option_price() -> Result<f64, OptionsError> {
    // Implementation
    Ok(0.0)
}

// Greeks calculation error handling
fn calculate_delta() -> Result<f64, GreeksError> {
    // Implementation
    Ok(0.0)
}

// Chain operation error handling
fn process_option_chain() -> Result<(), ChainError> {
    // Implementation
    Ok(())
}

§Error Design Principles

  • All error types implement standard traits (Error, Display, Debug)
  • Structured error hierarchies for precise error handling
  • Detailed error messages for debugging
  • Clean error propagation through type conversions
  • Context preservation in error chains

§Type Aliases

  • OptionsResult<T> - Specialized result type for options operations
  • DecimalResult<T> - Specialized result type for decimal calculations

§Module Structure

error/
├── chains.rs       - Option chain errors
├── common.rs       - Shared error types
├── curves.rs       - Mathematical curve errors
├── decimal.rs      - Decimal computation errors
├── greeks.rs       - Greeks calculation errors
├── interpolation.rs - Interpolation errors
├── metrics.rs      - Performance metrics errors
├── options.rs      - Core options errors
├── position.rs     - Position management errors
├── probability.rs  - Statistical analysis errors
├── strategies.rs   - Trading strategy errors
├── surfaces.rs     - Surface construction errors
├── trade.rs        - Trade management errors
└── volatility.rs   - Volatility calculation errors

Re-exports§

pub use chains::ChainError;
pub use curves::CurveError;
pub use decimal::DecimalError;
pub use decimal::DecimalResult;
pub use greeks::GreeksError;
pub use position::PositionError;
pub use pricing::PricingError;
pub use pricing::PricingResult;
pub use probability::ProbabilityError;
pub use simulation::SimulationError;
pub use simulation::SimulationResult;
pub use strategies::StrategyError;
pub use trade::TradeError;
pub use unified::Error;

Modules§

chains
Chain Errors (ChainError)
curves
Curve Errors (CurveError)
decimal
Decimal Errors (DecimalError)
greeks
Greeks Errors (GreeksError)
position
Position Errors (PositionError)
pricing
Pricing Errors (PricingError)
probability
Probability Errors (ProbabilityError)
simulation
Simulation Errors (SimulationError)
strategies
Strategy Errors (StrategyError)
trade
Trade Errors (TradeError)
unified
Unified Error Type

Enums§

GraphError
Represents errors that can occur during graph generation and rendering operations.
InterpolationError
Represents errors that can occur during different interpolation operations.
MetricsError
Error types specifically related to financial and statistical metrics calculations.
OhlcvError
Error type for OHLCV operations
OperationErrorKind
Represents the types of errors that can occur during operations related to trading strategies or other processes.
OptionsError
Custom errors that can occur during Options operations
SurfaceError
Error variants that can occur when working with surface-related operations.
TransactionError
Transaction Error
VolatilityError
Represents errors that can occur during volatility-related calculations.

Type Aliases§

OptionsResult
A specialized result type for operations related to Options calculations and processing.