optionstratlib 0.17.3

OptionStratLib is a comprehensive Rust library for options trading and strategy development across multiple asset classes.
Documentation
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/******************************************************************************
   Author: Joaquín Béjar García
   Email: jb@taunais.com
   Date: 20/12/24
******************************************************************************/

//! # Position Error Module
//!
//! This module provides error handling for position-related operations in option trading strategies.
//! It defines error types to handle various scenarios related to position validation, strategy
//! operations, and position limits.
//!
//! ## Error Types
//!
//! ### Position Error (`PositionError`)
//! The main error type with four variants:
//! * `StrategyError` - For strategy operation failures
//! * `ValidationError` - For position validation failures
//! * `LimitError` - For position limit violations
//! * `UpdateError` - For position update failures
//!
//! ### Strategy Errors (`StrategyErrorKind`)
//! Handles specific strategy-related errors:
//! * Unsupported operations
//! * Strategy capacity limits
//! * Invalid configurations
//!
//! ### Validation Errors (`PositionValidationErrorKind`)
//! Handles position validation failures:
//! * Invalid position sizes
//! * Invalid prices
//! * Incompatible sides (Long/Short)
//! * Incompatible styles (Call/Put)
//! * General position invalidity
//!
//! ### Limit Errors (`PositionLimitErrorKind`)
//! Handles position limit violations:
//! * Maximum positions reached
//! * Maximum exposure reached
//!
//! ## Usage Example
//!
//! ```rust
//! use optionstratlib::error::position::PositionError;
//!
//! fn validate_position_size(size: f64) -> Result<(), PositionError> {
//!     if size <= 0.0 {
//!         return Err(PositionError::invalid_position_size(
//!             size,
//!             "Position size must be positive"
//!         ));
//!     }
//!     Ok(())
//! }
//! ```
//!
//! ## Helper Methods
//!
//! The module provides several helper methods for creating common errors:
//! * `unsupported_operation` - Creates an error for unsupported strategy operations
//! * `strategy_full` - Creates an error when strategy capacity is reached
//! * `invalid_position_size` - Creates an error for invalid position sizes
//! * `invalid_position_type` - Creates an error for incompatible position sides
//! * `invalid_position_style` - Creates an error for incompatible option styles
//! * `invalid_position` - Creates a general position validation error
//!
//! All error types implement `std::error::Error` and `std::fmt::Display` for proper
//! error handling and formatting capabilities.

use crate::error::StrategyError;
use crate::model::types::{OptionStyle, Side};
use thiserror::Error;

/// Represents errors that can occur when managing positions in strategies
///
/// This enum provides a top-level categorization of position-related errors,
/// grouping them by their source or nature. It helps with routing errors to
/// appropriate handlers and providing context-aware error messages.
///
/// # Variants
///
/// * `StrategyError` - Errors related to strategy operations such as configuration
///   issues or capacity limitations.
///
/// * `ValidationError` - Errors related to position validation including issues
///   with size, price, or compatibility with strategy requirements.
///
/// * `LimitError` - Errors related to position limits such as maximum number of
///   positions or maximum exposure thresholds.
///
/// # Usage
///
/// This error type is typically used in trading systems where positions need to
/// be validated, managed, and executed within the context of trading strategies.
#[derive(Error, Debug)]
pub enum PositionError {
    /// Errors related to strategy operations
    #[error("Strategy error: {0}")]
    StrategyError(StrategyErrorKind),

    /// Errors related to position validation
    #[error("Validation error: {0}")]
    ValidationError(PositionValidationErrorKind),

    /// Errors related to position limits
    #[error("Limit error: {0}")]
    LimitError(PositionLimitErrorKind),

    /// Error during position update
    ///
    /// This variant is triggered when attempts to update option position parameters or data fail.
    // #[error("Position update error for field '{field}': {reason}")]
    // UpdateError {
    //     /// The position field that failed to update
    //     field: String,
    //     /// Detailed explanation of the position update failure
    //     reason: String,
    // },
    /// Errors related to position update
    #[error("Update error: {0}")]
    UpdateError(PositionUpdateErrorKind),

    /// Decimal arithmetic failures propagated from monetary-flow
    /// computations (overflow, division by zero, conversion).
    ///
    /// Produced when a checked Decimal helper in `model::decimal`
    /// surfaces a [`crate::error::DecimalError`] from inside a
    /// `Position` method (for example `pnl_at_expiration` or
    /// `unrealized_pnl`). Propagated transparently via the
    /// `#[from]` cascade so callers keep matching `PositionError`.
    #[error(transparent)]
    DecimalError(#[from] crate::error::DecimalError),
}

/// Specific errors that can occur in strategy operations
///
/// This enum captures detailed error types related to strategy operations,
/// providing specific information about why a strategy operation failed.
/// These errors typically occur during strategy management operations
/// such as adding positions, updating configurations, or executing trades.
///
/// # Variants
///
/// * `UnsupportedOperation` - Indicates that the attempted operation is not
///   supported by the particular strategy type.
///
/// * `StrategyFull` - Indicates that the strategy has reached its maximum
///   capacity for positions.
///
/// * `InvalidConfiguration` - Indicates that the strategy configuration is
///   invalid or inconsistent.
///
/// # Usage
///
/// Used when validating and executing strategy operations to provide detailed
/// error information about why an operation could not be completed.
#[derive(Error, Debug)]
pub enum StrategyErrorKind {
    /// Operation is not supported by this strategy
    ///
    /// Occurs when attempting to perform an operation that is not compatible
    /// with the current strategy type.
    #[error("Operation '{operation}' not supported by strategy '{strategy_type}'")]
    UnsupportedOperation {
        /// The type of strategy that doesn't support the operation
        strategy_type: String,

        /// The name of the operation that was attempted
        operation: String,
    },

    /// Strategy has reached its maximum capacity
    ///
    /// Occurs when attempting to add more positions than a strategy can handle.
    #[error("Strategy '{strategy_type}' is full (max positions: {max_positions})")]
    StrategyFull {
        /// The type of strategy that reached its capacity
        strategy_type: String,

        /// The maximum number of positions the strategy can hold
        max_positions: usize,
    },

    /// Invalid strategy configuration
    ///
    /// Occurs when the strategy's configuration parameters are invalid or inconsistent.
    #[error("Invalid strategy configuration: {0}")]
    InvalidConfiguration(String),
}

/// Errors related to position validation
///
/// This enum represents errors that can occur during position validation checks.
/// These errors typically happen when attempting to create or modify a position
/// with invalid or incompatible parameters.
///
/// # Variants
///
/// * `InvalidSize` - The position size is invalid (e.g., zero, negative, or too large).
///
/// * `InvalidPrice` - The position price is invalid (e.g., negative or unrealistic).
///
/// * `IncompatibleSide` - The position side (long/short) is incompatible with the strategy.
///
/// * `IncompatibleStyle` - The option style is incompatible with the strategy.
///
/// * `InvalidPosition` - The position is invalid for other specific reasons.
///
///
/// # Usage
///
/// Used when validating positions to ensure they meet all requirements before
/// being added to a strategy or executed in a trading system.
#[derive(Error, Debug)]
pub enum PositionValidationErrorKind {
    /// Position size is invalid
    ///
    /// Occurs when the specified position size violates size constraints.
    #[error("Invalid position size {size}: {reason}")]
    InvalidSize {
        /// The invalid size value
        size: f64,

        /// Explanation of why the size is invalid
        reason: String,
    },

    /// Position price is invalid
    ///
    /// Occurs when the specified price violates price constraints or is unrealistic.
    #[error("Invalid position price {price}: {reason}")]
    InvalidPrice {
        /// The invalid price value
        price: f64,

        /// Explanation of why the price is invalid
        reason: String,
    },

    /// Position type is incompatible with strategy
    ///
    /// Occurs when the position side (long/short) conflicts with strategy requirements.
    #[error("Incompatible position side {position_side:?}: {reason}")]
    IncompatibleSide {
        /// The incompatible position side
        position_side: Side,

        /// Explanation of why the side is incompatible
        reason: String,
    },

    /// Option style is incompatible with strategy
    ///
    /// Occurs when the option style (American/European) conflicts with strategy requirements.
    #[error("Incompatible option style {style:?}: {reason}")]
    IncompatibleStyle {
        /// The incompatible option style
        style: OptionStyle,

        /// Explanation of why the style is incompatible
        reason: String,
    },

    /// Position is invalid for other reasons
    ///
    /// A general error for positions that fail validation for reasons not covered by other variants.
    #[error("Invalid position: {reason}")]
    InvalidPosition {
        /// Explanation of why the position is invalid
        reason: String,
    },
}

/// Represents errors related to position limits in trading operations.
///
/// This enum captures different types of limit violations that can occur when
/// managing trading positions, such as exceeding the maximum number of allowed
/// positions or reaching the maximum exposure threshold for a portfolio.
///
/// # Variants
///
/// * `MaxPositionsReached` - Error indicating that the maximum number of allowed
///   positions has been reached, preventing the creation of additional positions.
///
/// * `MaxExposureReached` - Error indicating that the maximum allowed financial
///   exposure has been reached, preventing positions that would increase exposure.
///
/// # Usage
///
/// This error type is typically used in position management systems, risk control
/// mechanisms, and trading platforms to enforce safety limits and prevent excessive
/// risk taking.
///
#[derive(Error, Debug)]
pub enum PositionLimitErrorKind {
    /// Error indicating the maximum number of positions has been reached
    ///
    /// This variant is triggered when attempting to create a new position would
    /// exceed the configured maximum number of positions allowed in a portfolio
    /// or trading account.
    #[error("Maximum positions reached: {current}/{maximum}")]
    MaxPositionsReached {
        /// The current number of positions in the portfolio
        current: usize,
        /// The maximum number of positions allowed
        maximum: usize,
    },

    /// Error indicating the maximum allowed exposure has been reached
    ///
    /// This variant is triggered when a new position or modification would cause
    /// the total portfolio exposure to exceed the configured maximum risk threshold.
    /// Exposure is typically measured in monetary terms based on position value or risk.
    #[error("Maximum exposure reached: {current_exposure}/{max_exposure}")]
    MaxExposureReached {
        /// The current financial exposure level of the portfolio
        current_exposure: f64,
        /// The maximum allowed exposure level
        max_exposure: f64,
    },
}

/// Represents errors related to position update in trading operations.
///
/// This enum captures a specific error in an option position update.
/// The specified field to be updated can return an error.
///
/// # Variants
///
/// * `PositionFieldUpdateFailure` - Error in the update of a specific positon field.
///
/// # Usage
///
/// This error type is typically used in position management systems and trading platforms to
/// prevent a wrong position update.
///
#[derive(Error, Debug)]
pub enum PositionUpdateErrorKind {
    /// Error during position update
    ///
    /// This variant is triggered when attempts to update option position parameters or data fail.
    #[error("Position update error for field '{field}': {reason}")]
    PositionFieldUpdateFailure {
        /// The position field that failed to update
        field: String,
        /// Detailed explanation of the position update failure reason
        reason: String,
    },
}

/// Factory methods for creating position-related errors
///
/// This implementation provides a set of convenience factory methods for creating
/// different types of position errors. These methods create properly structured
/// error instances with clear, descriptive information about what went wrong.
///
/// # Methods
///
/// These factory methods simplify error creation throughout the codebase and ensure
/// that errors have consistent formatting and information.
impl PositionError {
    /// Creates an error for operations not supported by a specific strategy type
    ///
    /// # Parameters
    ///
    /// * `strategy_type` - The name or identifier of the strategy that doesn't support the operation
    /// * `operation` - The name of the unsupported operation that was attempted
    ///
    /// # Returns
    ///
    /// A `PositionError::StrategyError` variant with UnsupportedOperation details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn unsupported_operation(strategy_type: &str, operation: &str) -> Self {
        PositionError::StrategyError(StrategyErrorKind::UnsupportedOperation {
            strategy_type: strategy_type.to_string(),
            operation: operation.to_string(),
        })
    }

    /// Creates an error when a strategy has reached its maximum position capacity
    ///
    /// # Parameters
    ///
    /// * `strategy_type` - The name or identifier of the strategy that is at capacity
    /// * `max_positions` - The maximum number of positions the strategy can hold
    ///
    /// # Returns
    ///
    /// A `PositionError::StrategyError` variant with StrategyFull details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn strategy_full(strategy_type: &str, max_positions: usize) -> Self {
        PositionError::StrategyError(StrategyErrorKind::StrategyFull {
            strategy_type: strategy_type.to_string(),
            max_positions,
        })
    }

    /// Creates an error for invalid position size values
    ///
    /// # Parameters
    ///
    /// * `size` - The invalid position size value
    /// * `reason` - A description of why the size is invalid
    ///
    /// # Returns
    ///
    /// A `PositionError::ValidationError` variant with InvalidSize details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn invalid_position_size(size: f64, reason: &str) -> Self {
        PositionError::ValidationError(PositionValidationErrorKind::InvalidSize {
            size,
            reason: reason.to_string(),
        })
    }

    /// Creates an error for incompatible position side/direction
    ///
    /// # Parameters
    ///
    /// * `position_side` - The position side (Long or Short) that is incompatible
    /// * `reason` - A description of why the position side is incompatible
    ///
    /// # Returns
    ///
    /// A `PositionError::ValidationError` variant with IncompatibleSide details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn invalid_position_type(position_side: Side, reason: String) -> Self {
        PositionError::ValidationError(PositionValidationErrorKind::IncompatibleSide {
            position_side,
            reason,
        })
    }

    /// Creates an error for incompatible option style
    ///
    /// # Parameters
    ///
    /// * `style` - The option style (Call or Put) that is incompatible
    /// * `reason` - A description of why the option style is incompatible
    ///
    /// # Returns
    ///
    /// A `PositionError::ValidationError` variant with IncompatibleStyle details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn invalid_position_style(style: OptionStyle, reason: String) -> Self {
        PositionError::ValidationError(PositionValidationErrorKind::IncompatibleStyle {
            style,
            reason,
        })
    }

    /// Creates a generic invalid position error
    ///
    /// # Parameters
    ///
    /// * `reason` - A description of why the position is invalid
    ///
    /// # Returns
    ///
    /// A `PositionError::ValidationError` variant with InvalidPosition details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn invalid_position(reason: &str) -> Self {
        PositionError::ValidationError(PositionValidationErrorKind::InvalidPosition {
            reason: reason.to_string(),
        })
    }

    /// Creates an error for invalid position update
    ///
    /// # Parameters
    ///
    /// * `field` - The option position field that failed to update
    /// * `reason` - A description of why the option position field failed to update
    ///
    /// # Returns
    ///
    /// A `PositionError::UpdateError` variant with PositionFieldUpdateFailure details
    #[must_use]
    #[cold]
    #[inline(never)]
    pub fn invalid_position_update(field: String, reason: String) -> Self {
        PositionError::UpdateError(PositionUpdateErrorKind::PositionFieldUpdateFailure {
            field,
            reason,
        })
    }
}

// Implement conversion from StrategyError to PositionError
impl From<StrategyError> for PositionError {
    fn from(error: StrategyError) -> Self {
        PositionError::StrategyError(StrategyErrorKind::UnsupportedOperation {
            operation: "".to_string(),
            strategy_type: error.to_string(),
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::strategies::base::Positionable;

    struct DummyStrategy;
    impl Positionable for DummyStrategy {}

    #[test]
    fn test_unsupported_operation() {
        let strategy = DummyStrategy;
        let result = strategy.get_positions();
        assert!(matches!(
            result,
            Err(PositionError::StrategyError(
                StrategyErrorKind::UnsupportedOperation { .. }
            ))
        ));
    }

    #[test]
    fn test_error_messages() {
        let error = PositionError::unsupported_operation("TestStrategy", "add_position");
        assert!(error.to_string().contains("TestStrategy"));
        assert!(error.to_string().contains("add_position"));
    }

    #[test]
    fn test_invalid_position_size() {
        let error = PositionError::invalid_position_size(-1.0, "Size cannot be negative");
        assert!(matches!(
            error,
            PositionError::ValidationError(PositionValidationErrorKind::InvalidSize { .. })
        ));
    }
}

#[cfg(test)]
mod tests_extended {
    use super::*;

    #[test]
    fn test_validation_error_display() {
        let error = PositionValidationErrorKind::InvalidSize {
            size: -1.0,
            reason: "Size must be positive".to_string(),
        };

        assert!(error.to_string().contains("-1"));
        assert!(error.to_string().contains("Size must be positive"));

        let error = PositionValidationErrorKind::IncompatibleSide {
            position_side: Side::Long,
            reason: "Strategy requires short positions".to_string(),
        };
        assert!(error.to_string().contains("Long"));
        assert!(error.to_string().contains("Strategy requires short"));
    }

    #[test]
    fn test_limit_error_display() {
        let error = PositionLimitErrorKind::MaxPositionsReached {
            current: 5,
            maximum: 4,
        };
        assert!(error.to_string().contains("5"));
        assert!(error.to_string().contains("4"));

        let error = PositionLimitErrorKind::MaxExposureReached {
            current_exposure: 1000.0,
            max_exposure: 500.0,
        };
        assert!(error.to_string().contains("1000"));
        assert!(error.to_string().contains("500"));
    }

    #[test]
    fn test_invalid_position_constructor() {
        let error = PositionError::invalid_position("bad position");
        assert!(matches!(
            error,
            PositionError::ValidationError(PositionValidationErrorKind::InvalidPosition { .. })
        ));
    }

    #[test]
    fn test_position_error_helper_methods() {
        let error = PositionError::invalid_position_size(-1.0, "Must be positive");
        assert!(matches!(
            error,
            PositionError::ValidationError(PositionValidationErrorKind::InvalidSize { .. })
        ));

        let error = PositionError::invalid_position_type(
            Side::Long,
            "Strategy requires short positions".to_string(),
        );
        assert!(matches!(
            error,
            PositionError::ValidationError(PositionValidationErrorKind::IncompatibleSide { .. })
        ));
    }

    #[test]
    fn test_strategy_error_helper_methods() {
        let error = PositionError::strategy_full("Iron Condor", 4);
        assert!(matches!(
            error,
            PositionError::StrategyError(StrategyErrorKind::StrategyFull { .. })
        ));

        let error = PositionError::unsupported_operation("Iron Condor", "add_leg");
        assert!(matches!(
            error,
            PositionError::StrategyError(StrategyErrorKind::UnsupportedOperation { .. })
        ));
    }

    #[test]
    fn test_position_error_validation_error() {
        let error = PositionError::ValidationError(PositionValidationErrorKind::InvalidSize {
            size: -1.0,
            reason: "Size must be positive".to_string(),
        });
        assert_eq!(
            format!("{error}"),
            "Validation error: Invalid position size -1: Size must be positive"
        );
    }

    #[test]
    fn test_position_error_limit_error() {
        let error = PositionError::LimitError(PositionLimitErrorKind::MaxPositionsReached {
            current: 10,
            maximum: 5,
        });
        assert_eq!(
            format!("{error}"),
            "Limit error: Maximum positions reached: 10/5"
        );
    }

    #[test]
    fn test_strategy_error_strategy_full() {
        let error = StrategyErrorKind::StrategyFull {
            strategy_type: "Iron Condor".to_string(),
            max_positions: 10,
        };
        assert_eq!(
            format!("{error}"),
            "Strategy 'Iron Condor' is full (max positions: 10)"
        );
    }

    #[test]
    fn test_strategy_error_invalid_configuration() {
        let error = StrategyErrorKind::InvalidConfiguration("Invalid risk parameters".to_string());
        assert_eq!(
            format!("{error}"),
            "Invalid strategy configuration: Invalid risk parameters"
        );
    }

    #[test]
    fn test_position_validation_error_invalid_price() {
        let error = PositionValidationErrorKind::InvalidPrice {
            price: 105.5,
            reason: "Outside allowable range".to_string(),
        };
        assert_eq!(
            format!("{error}"),
            "Invalid position price 105.5: Outside allowable range"
        );
    }

    #[test]
    fn test_position_validation_error_invalid_position() {
        let error = PositionValidationErrorKind::InvalidPosition {
            reason: "Position size exceeds margin".to_string(),
        };
        assert_eq!(
            format!("{error}"),
            "Invalid position: Position size exceeds margin"
        );
    }

    #[test]
    fn test_position_validation_error_incompatible_style() {
        let error = PositionValidationErrorKind::IncompatibleStyle {
            style: OptionStyle::Call,
            reason: "Unsupported for Call options".to_string(),
        };
        assert_eq!(
            format!("{error}"),
            "Incompatible option style OptionStyle::Call: Unsupported for Call options"
        );
    }

    #[test]
    fn test_position_update_error() {
        let error = PositionUpdateErrorKind::PositionFieldUpdateFailure {
            field: "premium".to_string(),
            reason: "Missing call ask price for long call position".to_string(),
        };
        assert_eq!(
            format!("{error}"),
            "Position update error for field 'premium': Missing call ask price for long call position"
        );
    }

    #[test]
    fn test_position_update_error_helper_method() {
        let error = PositionError::invalid_position_update(
            "premium".to_string(),
            "Missing call ask price for long call position".to_string(),
        );
        assert_eq!(
            format!("{error}"),
            "Update error: Position update error for field 'premium': Missing call ask price for long call position"
        );
    }
}