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
use crateOptions;
use crate;
use crateblack_scholes;
use crateSimulator;
use Positive;
/// Pricing engine selector for option pricing.
///
/// This enum allows selection between different pricing methods:
/// - `ClosedFormBS`: Uses the Black-Scholes closed-form formula
/// - `MonteCarlo`: Uses Monte Carlo simulation with a configured simulator
/// Prices an option using the specified pricing engine.
///
/// This is the unified entry point for option pricing that dispatches to
/// the appropriate pricing method based on the engine configuration.
///
/// # Arguments
///
/// * `option` - The option to price
/// * `engine` - The pricing engine to use
///
/// # Returns
///
/// Returns the option price as a `Positive` value, or a `PricingError` if pricing fails.
///
/// # Examples
///
/// ```rust
/// use optionstratlib::pricing::{PricingEngine, price_option};
/// use positive::{Positive, pos_or_panic};
/// use optionstratlib::{ExpirationDate, Options};
/// use optionstratlib::model::types::{OptionStyle, OptionType, Side};
/// use rust_decimal_macros::dec;
///
/// let option = Options {
/// option_type: OptionType::European,
/// side: Side::Long,
/// underlying_symbol: "AAPL".to_string(),
/// strike_price: Positive::HUNDRED,
/// expiration_date: ExpirationDate::Days(pos_or_panic!(30.0)),
/// implied_volatility: pos_or_panic!(0.2),
/// quantity: Positive::ONE,
/// underlying_price: pos_or_panic!(105.0),
/// risk_free_rate: dec!(0.05),
/// option_style: OptionStyle::Call,
/// dividend_yield: pos_or_panic!(0.01),
/// exotic_params: None,
/// };
/// let engine = PricingEngine::ClosedFormBS;
/// let price = price_option(&option, &engine)?;
/// Ok::<(), optionstratlib::error::PricingError>(())
/// ```
///
/// # Errors
///
/// Propagates any `PricingError` returned by the selected engine:
/// `PricingError::ExpirationDate` or `PricingError::MethodError`
/// from Black–Scholes, [`PricingError::BinomialNodeMissing`] or
/// [`PricingError::SqrtFailure`] from the binomial lattice, or the
/// equivalent failures from exotic engines (barrier, binary,
/// compound, chooser, cliquet, lookback, telegraph, Monte Carlo).
/// Trait for types that can be priced using a pricing engine.
///
/// This trait provides a unified interface for pricing financial instruments.
/// Implementation of `Priceable` for `Options`.
///
/// This allows options to be priced using the unified pricing API.