optionstratlib 0.16.2

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
/******************************************************************************
   Author: Joaquín Béjar García
   Email: jb@taunais.com
   Date: 16/2/25
******************************************************************************/

use crate::error::StrategyError;
use crate::model::Position;
use crate::strategies::base::StrategyType;
use crate::strategies::custom::CustomStrategy;
use crate::strategies::{
    BearCallSpread, BearPutSpread, BullCallSpread, BullPutSpread, CallButterfly, IronButterfly,
    IronCondor, LongButterflySpread, LongStraddle, LongStrangle, PoorMansCoveredCall,
    ShortButterflySpread, ShortStraddle, ShortStrangle, Strategable, StrategyConstructor,
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// A request structure for creating and analyzing options trading strategies.
///
/// This structure encapsulates all necessary information to construct and evaluate
/// a specific options trading strategy. It contains the strategy type (such as
/// Bull Call Spread, Iron Condor, etc.) and the collection of financial positions
/// that make up the strategy.
///
/// `StrategyRequest` is typically used as an input to strategy analysis services
/// or functions that construct, validate, and evaluate option strategies based
/// on their positions.
///
#[derive(Clone, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct StrategyRequest {
    /// The type of options trading strategy to construct or analyze.
    /// This determines the expected structure and validation rules
    /// for the provided positions.
    pub strategy_type: StrategyType,

    /// A collection of financial positions that make up the strategy.
    /// These positions typically include various options contracts
    /// (calls and puts) with different strike prices and expiration dates,
    /// arranged according to the selected strategy type.
    pub positions: Vec<Position>,
}

/// Request handler for options trading strategies.
///
/// This implementation provides functionality to create new strategy requests
/// and instantiate concrete strategy objects based on the specified strategy type
/// and positions.
impl StrategyRequest {
    /// Creates a new strategy request with the specified strategy type and positions.
    ///
    /// # Parameters
    /// * `strategy_type` - The type of options trading strategy to construct.
    /// * `positions` - A collection of financial positions that make up the strategy.
    ///
    /// # Returns
    /// A new `StrategyRequest` instance containing the provided strategy type and positions.
    #[inline]
    #[must_use]
    pub fn new(strategy_type: StrategyType, positions: Vec<Position>) -> Self {
        Self {
            strategy_type,
            positions,
        }
    }

    /// Creates and returns a concrete strategy instance based on the strategy type
    /// and positions specified in this request.
    ///
    /// This method acts as a factory that constructs the appropriate strategy object
    /// by delegating to the corresponding strategy implementation's `get_strategy` method.
    ///
    /// # Returns
    /// * `Ok(Box<dyn Strategable>)` - A boxed trait object implementing the `Strategable`
    ///   trait if the strategy creation was successful.
    /// * `Err(StrategyError)` - An error indicating why the strategy could not be created.
    ///   Returns `StrategyError::NotImplemented` for strategies that are not yet implemented.
    ///
    /// # Errors
    /// This method can return errors from the underlying strategy constructors or
    /// `StrategyError::NotImplemented` for strategies that are defined but not yet implemented.
    #[inline(never)]
    pub fn get_strategy(&self) -> Result<Box<dyn Strategable>, StrategyError> {
        match self.strategy_type {
            StrategyType::BullCallSpread => {
                Ok(Box::new(BullCallSpread::get_strategy(&self.positions)?))
            }
            StrategyType::BearCallSpread => {
                Ok(Box::new(BearCallSpread::get_strategy(&self.positions)?))
            }
            StrategyType::BullPutSpread => {
                Ok(Box::new(BullPutSpread::get_strategy(&self.positions)?))
            }
            StrategyType::BearPutSpread => {
                Ok(Box::new(BearPutSpread::get_strategy(&self.positions)?))
            }
            StrategyType::LongButterflySpread => Ok(Box::new(LongButterflySpread::get_strategy(
                &self.positions,
            )?)),
            StrategyType::ShortButterflySpread => Ok(Box::new(ShortButterflySpread::get_strategy(
                &self.positions,
            )?)),
            StrategyType::IronCondor => Ok(Box::new(IronCondor::get_strategy(&self.positions)?)),
            StrategyType::IronButterfly => {
                Ok(Box::new(IronButterfly::get_strategy(&self.positions)?))
            }
            StrategyType::LongStraddle => {
                Ok(Box::new(LongStraddle::get_strategy(&self.positions)?))
            }
            StrategyType::ShortStraddle => {
                Ok(Box::new(ShortStraddle::get_strategy(&self.positions)?))
            }
            StrategyType::LongStrangle => {
                Ok(Box::new(LongStrangle::get_strategy(&self.positions)?))
            }
            StrategyType::ShortStrangle => {
                Ok(Box::new(ShortStrangle::get_strategy(&self.positions)?))
            }
            StrategyType::CoveredCall => Err(StrategyError::NotImplemented),
            StrategyType::ProtectivePut => Err(StrategyError::NotImplemented),
            StrategyType::Collar => Err(StrategyError::NotImplemented),
            StrategyType::LongCall => Err(StrategyError::NotImplemented),
            StrategyType::LongPut => Err(StrategyError::NotImplemented),
            StrategyType::ShortCall => Err(StrategyError::NotImplemented),
            StrategyType::ShortPut => Err(StrategyError::NotImplemented),
            StrategyType::PoorMansCoveredCall => Ok(Box::new(PoorMansCoveredCall::get_strategy(
                &self.positions,
            )?)),
            StrategyType::CallButterfly => {
                Ok(Box::new(CallButterfly::get_strategy(&self.positions)?))
            }
            StrategyType::Custom => Ok(Box::new(CustomStrategy::get_strategy(&self.positions)?)),
        }
    }
}

#[cfg(test)]
mod tests_serialization {
    use super::*;
    use crate::model::utils::create_sample_option_with_date;
    use crate::{OptionStyle, Side};
    use chrono::{DateTime, NaiveDateTime, Utc};
    use positive::{Positive, pos_or_panic};
    use serde_json;

    fn sample_date() -> NaiveDateTime {
        DateTime::from_timestamp(1672531200, 0).unwrap().naive_utc()
    }

    #[test]
    fn test_strategy_request_serialization() {
        let strategy_request = StrategyRequest {
            strategy_type: StrategyType::BearCallSpread,
            positions: vec![
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Short,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(900.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(4.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Long,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(910.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(3.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
            ],
        };

        let serialized = serde_json::to_string(&strategy_request).unwrap();

        // Verify structure
        assert!(serialized.contains("\"strategy_type\":\"BearCallSpread\""));
        assert!(serialized.contains("\"positions\":["));
        assert!(serialized.contains("\"underlying_symbol\":\"AAPL\""));
        assert!(serialized.contains("\"premium\":4.5"));
        assert!(serialized.contains("\"open_fee\":1"));
        assert!(serialized.contains("\"close_fee\":1.2"));
    }

    #[test]
    fn test_strategy_request_deserialization() {
        let json_data = r#"{
            "strategy_type": "BearCallSpread",
            "positions": [
                {
                    "option": {
                        "option_type": "European",
                        "side": "Short",
                        "underlying_symbol": "AAPL",
                        "strike_price": 900.0,
                        "expiration_date": {"days": 30},
                        "implied_volatility": 0.35,
                        "quantity": 1.0,
                        "underlying_price": 920.0,
                        "risk_free_rate": 0.02,
                        "option_style": "Call",
                        "dividend_yield": 0.01,
                        "exotic_params": null
                    },
                    "premium": 4.5,
                    "date": "2024-01-01T00:00:00Z",
                    "open_fee": 1.0,
                    "close_fee": 1.2
                },
                {
                    "option": {
                        "option_type": "European",
                        "side": "Long",
                        "underlying_symbol": "AAPL",
                        "strike_price": 910.0,
                        "expiration_date": {"days": 30},
                        "implied_volatility": 0.35,
                        "quantity": 1.0,
                        "underlying_price": 920.0,
                        "risk_free_rate": 0.02,
                        "option_style": "Call",
                        "dividend_yield": 0.01,
                        "exotic_params": null
                    },
                    "premium": 3.5,
                    "date": "2024-01-01T00:00:00Z",
                    "open_fee": 1.0,
                    "close_fee": 1.2
                }
            ]
        }"#;

        let deserialized: StrategyRequest = serde_json::from_str(json_data).unwrap();

        // Verify deserialized data
        assert_eq!(deserialized.strategy_type, StrategyType::BearCallSpread);
        assert_eq!(deserialized.positions.len(), 2);

        // Verify first option (Short Call)
        let short_call = &deserialized.positions[0];
        assert_eq!(short_call.option.side, Side::Short);
        assert_eq!(short_call.option.strike_price, pos_or_panic!(900.0));
        assert_eq!(short_call.premium, pos_or_panic!(4.5));
        assert_eq!(short_call.open_fee, Positive::ONE);
        assert_eq!(short_call.close_fee, pos_or_panic!(1.2));

        // Verify second option (Long Call)
        let long_call = &deserialized.positions[1];
        assert_eq!(long_call.option.side, Side::Long);
        assert_eq!(long_call.option.strike_price, pos_or_panic!(910.0));
        assert_eq!(long_call.premium, pos_or_panic!(3.5));
        assert_eq!(long_call.open_fee, Positive::ONE);
        assert_eq!(long_call.close_fee, pos_or_panic!(1.2));
    }

    #[test]
    fn test_strategy_request_invalid_json() {
        let invalid_json = r#"{
            "strategy_type": "InvalidStrategy",
            "positions": []
        }"#;

        let result = serde_json::from_str::<StrategyRequest>(invalid_json);
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_request_empty_options() {
        let json_data = r#"{
            "strategy_type": "BearCallSpread",
            "positions": []
        }"#;

        let deserialized: StrategyRequest = serde_json::from_str(json_data).unwrap();
        assert_eq!(deserialized.strategy_type, StrategyType::BearCallSpread);
        assert!(deserialized.positions.is_empty());
    }
}

#[cfg(test)]
mod tests_strategies_build_model {
    use super::*;
    use crate::model::utils::create_sample_option_with_date;
    use crate::{OptionStyle, Side, assert_decimal_eq};
    use chrono::{DateTime, NaiveDateTime, Utc};
    use positive::{Positive, pos_or_panic};
    use rust_decimal_macros::dec;
    use serde_json;

    fn sample_date() -> NaiveDateTime {
        // Tomorrow plus an hour buffer so the integer day count in
        // `Actual365Fixed` resolves to 1 day reliably even with
        // sub-second clock drift between `Utc::now()` calls.
        let future_timestamp = Utc::now().timestamp() + 86400 + 3600;
        DateTime::from_timestamp(future_timestamp, 0)
            .unwrap()
            .naive_utc()
    }

    #[test]
    fn test_strategy_request() {
        let strategy_request = StrategyRequest::new(
            StrategyType::BearCallSpread,
            vec![
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Short,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(900.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(4.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Long,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(910.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(3.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
            ],
        );

        let serialized = serde_json::to_string(&strategy_request).unwrap();

        // Verify structure
        assert!(serialized.contains("\"strategy_type\":\"BearCallSpread\""));
        assert!(serialized.contains("\"positions\":["));
        assert!(serialized.contains("\"underlying_symbol\":\"AAPL\""));
        assert!(serialized.contains("\"premium\":4.5"));
        assert!(serialized.contains("\"open_fee\":1"));
        assert!(serialized.contains("\"close_fee\":1.2"));
    }

    #[test]
    fn test_strategy_bull_call_spread() {
        let strategy_request = StrategyRequest::new(
            StrategyType::BullCallSpread,
            vec![
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Long,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(900.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(4.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Short,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(910.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(3.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
            ],
        );

        let strategy = strategy_request.get_strategy().unwrap();
        let greeks_result = strategy.greeks();
        assert!(greeks_result.is_ok());
        let greeks = greeks_result.unwrap();
        assert_decimal_eq!(greeks.delta, dec!(0.1579), dec!(1e-4));
        assert_decimal_eq!(greeks.gamma, dec!(0.0309), dec!(1e-4));
        assert_decimal_eq!(greeks.theta, dec!(-4.5486), dec!(1e-4));
        assert_decimal_eq!(greeks.vega, dec!(0.2508), dec!(1e-4));
        assert_decimal_eq!(greeks.rho, dec!(0.0398), dec!(1e-4));
        assert_decimal_eq!(greeks.vanna, dec!(-1.2135), dec!(1e-4));
        assert_decimal_eq!(greeks.vomma, dec!(0.5476), dec!(1e-4));
        assert_decimal_eq!(greeks.veta, dec!(0.0031), dec!(1e-4));
        assert_decimal_eq!(greeks.charm, dec!(0.209293), dec!(1e-4));
        assert_decimal_eq!(greeks.color, dec!(-0.003801), dec!(1e-6));
    }

    #[test]
    fn test_strategy_bear_call_spread() {
        let strategy_request = StrategyRequest::new(
            StrategyType::BearCallSpread,
            vec![
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Short,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(900.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(4.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Call,
                        Side::Long,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(910.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(3.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
            ],
        );

        let strategy = strategy_request.get_strategy().unwrap();
        let greeks = strategy
            .greeks()
            .unwrap_or_else(|e| panic!("greeks err: {e:?}"));
        assert_decimal_eq!(greeks.delta, dec!(-0.1579), dec!(1e-4));
        assert_decimal_eq!(greeks.gamma, dec!(0.0309), dec!(1e-4));
        assert_decimal_eq!(greeks.theta, dec!(-4.5486), dec!(1e-4));
        assert_decimal_eq!(greeks.vega, dec!(0.2508), dec!(1e-4));
        assert_decimal_eq!(greeks.rho, dec!(0.0398), dec!(1e-4));
        assert_decimal_eq!(greeks.vanna, dec!(-1.2135), dec!(1e-4));
        assert_decimal_eq!(greeks.vomma, dec!(0.5476), dec!(1e-4));
        assert_decimal_eq!(greeks.veta, dec!(0.0031), dec!(1e-4));
        assert_decimal_eq!(greeks.charm, dec!(0.209293), dec!(1e-4));
        assert_decimal_eq!(greeks.color, dec!(-0.003801), dec!(1e-6));
    }

    #[test]
    fn test_strategy_bear_put_spread() {
        let strategy_request = StrategyRequest::new(
            StrategyType::BearPutSpread,
            vec![
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Put,
                        Side::Long,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(900.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(4.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Put,
                        Side::Short,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(910.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(3.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
            ],
        );

        let strategy = strategy_request.get_strategy().unwrap();
        let greeks_result = strategy.greeks();
        assert!(greeks_result.is_ok());
        let greeks = greeks_result.unwrap();
        assert_decimal_eq!(greeks.delta, dec!(0.1579), dec!(1e-4));
        assert_decimal_eq!(greeks.gamma, dec!(0.0309), dec!(1e-4));
        assert_decimal_eq!(greeks.theta, dec!(-4.3511), dec!(1e-4));
        assert_decimal_eq!(greeks.vega, dec!(0.2508), dec!(1e-4));
        assert_decimal_eq!(greeks.rho, dec!(-0.0097), dec!(1e-4));
        assert_decimal_eq!(greeks.vanna, dec!(-1.2135), dec!(1e-4));
        assert_decimal_eq!(greeks.vomma, dec!(0.5476), dec!(1e-4));
        assert_decimal_eq!(greeks.veta, dec!(0.0031), dec!(1e-4));
        assert_decimal_eq!(greeks.charm, dec!(0.209239), dec!(1e-4));
        assert_decimal_eq!(greeks.color, dec!(-0.003801), dec!(1e-6));
    }

    #[test]
    fn test_strategy_bull_put_spread() {
        let strategy_request = StrategyRequest::new(
            StrategyType::BullPutSpread,
            vec![
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Put,
                        Side::Short,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(900.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(4.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
                Position::new(
                    create_sample_option_with_date(
                        OptionStyle::Put,
                        Side::Long,
                        pos_or_panic!(920.0),
                        Positive::ONE,
                        pos_or_panic!(910.0),
                        pos_or_panic!(0.35),
                        sample_date(),
                    ),
                    pos_or_panic!(3.5),
                    Utc::now(),
                    Positive::ONE,
                    pos_or_panic!(1.2),
                    None,
                    None,
                ),
            ],
        );

        let strategy = strategy_request.get_strategy().unwrap();
        let greeks = strategy
            .greeks()
            .unwrap_or_else(|e| panic!("greeks err: {e:?}"));
        assert_decimal_eq!(greeks.delta, dec!(-0.1579), dec!(1e-4));
        assert_decimal_eq!(greeks.gamma, dec!(0.0309), dec!(1e-4));
        assert_decimal_eq!(greeks.theta, dec!(-4.3511), dec!(1e-4));
        assert_decimal_eq!(greeks.vega, dec!(0.2508), dec!(1e-4));
        assert_decimal_eq!(greeks.rho, dec!(-0.0097), dec!(1e-4));
        assert_decimal_eq!(greeks.vanna, dec!(-1.2135), dec!(1e-4));
        assert_decimal_eq!(greeks.vomma, dec!(0.5476), dec!(1e-4));
        assert_decimal_eq!(greeks.veta, dec!(0.0031), dec!(1e-4));
        assert_decimal_eq!(greeks.charm, dec!(0.209239), dec!(1e-5));
        assert_decimal_eq!(greeks.color, dec!(-0.003801), dec!(1e-5));
    }

    #[test]
    fn test_strategy_covered_call() {
        let strategy_request = StrategyRequest::new(StrategyType::CoveredCall, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_protective_put() {
        let strategy_request = StrategyRequest::new(StrategyType::ProtectivePut, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_collar() {
        let strategy_request = StrategyRequest::new(StrategyType::Collar, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_long_call() {
        let strategy_request = StrategyRequest::new(StrategyType::LongCall, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_long_put() {
        let strategy_request = StrategyRequest::new(StrategyType::LongPut, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_short_call() {
        let strategy_request = StrategyRequest::new(StrategyType::ShortCall, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }

    #[test]
    fn test_strategy_short_put() {
        let strategy_request = StrategyRequest::new(StrategyType::ShortPut, vec![]);
        let result = strategy_request.get_strategy();
        assert!(result.is_err());
    }
}