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 validationsGreeksError- Errors in Greeks calculations (delta, gamma, etc.)VolatilityError- Errors in volatility calculations including implied volatility
§Trading and Analysis
ChainError- Option chain operations and data managementTradeError- Trade position opening and status managementPositionError- Position management and trading operationsStrategyError- Trading strategy validation and executionProbabilityError- Statistical analysis and probability calculations
§Mathematical and Data
CurveError- Curve fitting and mathematical operationsDecimalError- Decimal number handling and precisionInterpolationError- Errors in data interpolation operationsMetricsError- Performance and risk metrics calculation errorsSurfaceError- 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 operationsDecimalResult<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 errorsRe-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§
- Graph
Error - Represents errors that can occur during graph generation and rendering operations.
- Interpolation
Error - Represents errors that can occur during different interpolation operations.
- Metrics
Error - Error types specifically related to financial and statistical metrics calculations.
- Ohlcv
Error - Error type for OHLCV operations
- Operation
Error Kind - Represents the types of errors that can occur during operations related to trading strategies or other processes.
- Options
Error - Custom errors that can occur during Options operations
- Surface
Error - Error variants that can occur when working with surface-related operations.
- Transaction
Error - Transaction Error
- Volatility
Error - Represents errors that can occur during volatility-related calculations.
Type Aliases§
- Options
Result - A specialized result type for operations related to Options calculations and processing.