1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/******************************************************************************
Author: Joaquín Béjar García
Email: jb@taunais.com
Date: 20/12/24
******************************************************************************/
//! # 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
//!
//! ```rust
//! 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
//!
//! ```text
//! 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
//! ```
/// ### Chain Errors (`ChainError`)
/// Handles:
/// * Option data validation
/// * Chain construction
/// * File operations (CSV/JSON)
/// * Strategy validation
///
/// Provides a common set of error kinds used across various modules:
/// * Validation failures
/// * Mathematical errors
/// * Input/output errors
/// * Data consistency issues
/// ### Curve Errors (`CurveError`)
/// Handles:
/// * Yield curve construction
/// * Forward rate calculations
/// * Market data fitting issues
/// * Term structure consistency
/// ### Decimal Errors (`DecimalError`)
/// Handles:
/// * Decimal conversions
/// * Precision management
/// * Arithmetic operations
/// * Boundary validations
/// ### Greeks Errors (`GreeksError`)
/// Handles:
/// * Greeks calculations
/// * Mathematical validation
/// * Input parameter validation
/// * Numerical computations
/// ### Options Errors (`OptionsError`)
/// Core module handling:
/// * Option validation errors
/// * Pricing model failures
/// * Parameter boundary violations
/// * Contract specification issues
/// ### Position Errors (`PositionError`)
/// Manages:
/// * Position validation
/// * Strategy operations
/// * Position limits
/// * Option style/side compatibility
/// ### Probability Errors (`ProbabilityError`)
/// Manages:
/// * Statistical calculations
/// * Range analysis
/// * Probability distributions
/// * Market scenarios
/// ### Strategy Errors (`StrategyError`)
/// Covers:
/// * Price calculations
/// * Break-even analysis
/// * Profit/Loss calculations
/// * Operation validation
/// ### Trade Errors (`TradeError`)
/// Covers:
/// * Trade execution issues
/// * Trade parameter validation
/// ### Interpolation Errors (`InterpolationError`)
/// Manages:
/// * Data point validation
/// * Interpolation method errors
/// * Boundary conditions
/// * Mathematical approximation issues
/// ### Metrics Errors (`MetricsError`)
/// Handles:
/// * Performance calculation failures
/// * Risk metric validation
/// * Statistical measurement errors
/// * Benchmark comparison issues
/// ### Surface Errors (`SurfaceError`)
/// Covers:
/// * Surface construction failures
/// * Volatility skew/smile errors
/// * Surface calibration issues
/// * Dimensional and data completeness errors
/// ### Simulation Errors (`SimulationError`)
/// Handles:
/// * Random walk generation failures
/// * Monte Carlo simulation errors
/// * Stochastic process parameter validation
/// * Step calculation issues
/// ### Pricing Errors (`PricingError`)
/// Handles:
/// * Pricing method failures (Black-Scholes, Binomial, etc.)
/// * Monte Carlo simulation errors
/// * Invalid pricing engine configurations
/// * Generic pricing-related errors
/// ### Volatility Errors (`VolatilityError`)
/// Handles:
/// * Implied volatility calculation failures
/// * Historical volatility estimation issues
/// * Volatility model parameter validation
/// * Market data consistency checks
/// ### CSV/OHLCV Errors (`OhlcvError`)
/// Handles:
/// * CSV parsing errors
/// * ZIP file handling errors
/// * OHLCV data validation
/// * Date and decimal parsing issues
/// ### Unified Error Type
/// Top-level error type that encompasses all errors in the library.
/// Provides a single error type for unified error handling across modules.
pub use ChainError;
pub use OperationErrorKind;
pub use OhlcvError;
pub use CurveError;
pub use ;
pub use GraphError;
pub use GreeksError;
pub use InterpolationError;
pub use MetricsError;
pub use ;
pub use PositionError;
pub use ;
pub use ProbabilityError;
pub use ;
pub use StrategyError;
pub use SurfaceError;
pub use TradeError;
pub use TransactionError;
pub use Error;
pub use VolatilityError;