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
//! # Options Pricing Module
//!
//! This module provides implementations for various financial models and utilities
//! to calculate and simulate option pricing. The module includes support for several
//! well-known mathematical models such as the Binomial Tree Model, Black-Scholes Model,
//! Monte Carlo Simulations, and Telegraph Process.
//!
//! ## Core Models
//!
//! ### Binomial Model (`binomial_model`)
//! Contains the implementation of the Binomial Tree Model for option pricing. This model
//! supports both European and American style options and allows for customization of steps
//! and parameters like volatility, interest rates, and time increments.
//!
//! ### Black-Scholes Model (`black_scholes_model`)
//! Implements the Black-Scholes option pricing model, a widely used formula for pricing
//! European-style options. This module provides tools to calculate option prices and
//! associated Greek values.
//!
//! ### Monte Carlo Simulations (`monte_carlo`)
//! Provides Monte Carlo simulation capabilities for option pricing. This module
//! supports simulation of stock price paths and uses statistical methods to estimate
//! option values under various stochastic processes.
//!
//! ### Telegraph Process (`telegraph`)
//! Implements the Telegraph process, a two-state stochastic process for modeling price movements.
//! Key features include:
//! - State transitions between +1 and -1 based on transition rates
//! - Parameter estimation from historical data
//! - Support for asymmetric transition rates
//! - Applications in regime-switching scenarios
//!
//! The Telegraph Process is particularly useful for:
//! - Modeling regime changes in volatility
//! - Capturing market sentiment switches
//! - Simulating discrete state transitions
//!
//! ## Supporting Modules
//!
//! ### Payoff Calculations (`payoff`)
//! Defines payoff structures and calculations for:
//! - Standard options (calls and puts)
//! - Exotic options
//! - Custom payoff functions
//!
//! ### Utility Functions (`utils`)
//! Provides essential mathematical and financial utilities:
//! - Probability calculations
//! - Discount factor computations
//! - Statistical functions
//! - Parameter estimation tools
//!
//! ### Constants (`constants`)
//! Defines model parameters and limits used across the pricing implementations:
//! - Numerical bounds
//! - Default values
//! - Calculation constraints
//!
//! ## Usage Examples
//!
//! ### Using the Telegraph Process
//!
//! ```rust
//! use rust_decimal_macros::dec;
//! use optionstratlib::pricing::telegraph::{TelegraphProcess, telegraph};
//! use optionstratlib::{ExpirationDate, Options};
//! use optionstratlib::model::types::{ OptionStyle, OptionType, Side};
//! use positive::Positive;
//! use positive::pos_or_panic;
//!
//! // Create a Telegraph Process with transition rates
//! let process = TelegraphProcess::new(dec!(0.5), dec!(0.3));
//!
//! // Price an option using the Telegraph Process
//! 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 price = telegraph(&option, optionstratlib::nz!(1000), Some(dec!(0.5)), Some(dec!(0.3)));
//! ```
//!
//! ### Combined Model Analysis
//!
//! ```rust
//! use rust_decimal_macros::dec;
//! use optionstratlib::{ExpirationDate, Options};
//! use optionstratlib::model::types::{ OptionStyle, OptionType, Side};
//! use positive::Positive;
//! use positive::pos_or_panic;
//! use optionstratlib::pricing::{
//! black_scholes_model::black_scholes,
//! monte_carlo::monte_carlo_option_pricing,
//! telegraph::telegraph
//! };
//! 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,
//! };
//! // Compare prices across different models
//! let bs_price = black_scholes(&option);
//! let mc_price = monte_carlo_option_pricing(&option, optionstratlib::nz!(2), optionstratlib::nz!(2));
//! let tp_price = telegraph(&option, optionstratlib::nz!(1000), Some(dec!(0.5)), Some(dec!(0.3)));
//! ```
//!
//! ## Implementation Notes
//!
//! - All models support standard market conventions for option pricing
//! - Parameter validation and bounds checking are implemented
//! - Error handling follows Rust's Result pattern
//! - Performance optimizations are included for numerical calculations
//!
//! ## Model Selection Guidelines
//!
//! Choose the appropriate model based on your needs:
//! - Black-Scholes: Quick pricing of European options
//! - Binomial: American options and early exercise
//! - Monte Carlo: Complex path-dependent options
//! - Telegraph: Regime-switching and discrete state transitions
//!
//! ## Performance Considerations
//!
//! - Telegraph Process: O(n) complexity where n is the number of steps
//! - Monte Carlo: O(m*n) where m is the number of simulations
//! - Binomial: O(n²) where n is the number of steps
//! - Black-Scholes: O(1) constant time calculation
//!
//! For high-frequency calculations, consider using the Black-Scholes model
//! when applicable, as it provides the fastest computation times.
/// American option pricing using analytical approximations.
///
/// This module provides fast analytical methods for pricing American options,
/// including the Barone-Adesi-Whaley (BAW) approximation which offers O(1)
/// complexity compared to O(n²) for binomial tree methods.
///
/// American options can be exercised at any time before expiration, making them
/// more valuable than European options but also more complex to price.
/// Binomial Tree model for option pricing.
/// Barrier option pricing using analytical extensions.
/// Asian option pricing with geometric and arithmetic averaging.
/// Binary option pricing (cash-or-nothing, asset-or-nothing, gap).
/// Lookback option pricing (floating and fixed strike).
/// Compound option pricing (options on options).
/// Chooser option pricing (choice between call and put).
/// Cliquet option pricing (periodic strike resets).
/// Rainbow option pricing (multi-asset options).
/// Spread option pricing (price differential options).
/// Quanto option pricing (currency-protected options).
/// Exchange option pricing (Margrabe options).
/// Power option pricing (non-linear payoffs).
/// Black-Scholes model for option pricing and analysis.
///
/// This module implements the Black-Scholes-Merton model for European option pricing
/// and related calculations such as the Greeks (delta, gamma, theta, vega, rho).
///
/// The Black-Scholes model provides closed-form solutions for European option prices
/// under specific assumptions about market behavior and asset price dynamics.
/// Constants used throughout the financial models.
///
/// Contains mathematical and financial constants required by various pricing models,
/// such as day count conventions, numerical approximation parameters, and defaults.
pub
/// Monte Carlo simulation methods for financial modeling.
///
/// This module provides tools for pricing options and other derivatives using
/// Monte Carlo simulations, which generate random paths for underlying asset prices
/// to estimate expected payoffs.
///
/// Monte Carlo methods are particularly valuable for complex derivatives where
/// closed-form solutions don't exist.
/// Payoff functions for different option types and derivatives.
///
/// Defines payoff calculations for various financial instruments, including
/// standard calls and puts, as well as more exotic payoff structures.
///
/// These payoff functions are used by the pricing models to determine the value
/// of options at expiration or exercise.
pub
/// Telegraph process model for asset price movement.
///
/// Implements a telegraph process model which can be used as an alternative to
/// geometric Brownian motion for modeling asset price movements with specific
/// jump characteristics.
///
/// The telegraph model is particularly useful for capturing market regimes with
/// distinct volatility states.
/// Utility functions for financial calculations.
///
/// Provides helper functions and common utilities used across the library,
/// including numerical methods, date handling, and data transformation tools.
pub
/// Unified pricing system for options.
///
/// This module provides a single, consistent API for pricing options using different models.
/// It includes the `PricingEngine` enum for selecting pricing methods, the `price_option`
/// function as the main entry point, and the `Priceable` trait for trait-based pricing.
///
/// ## Features
/// - Black-Scholes closed-form pricing
/// - Monte Carlo simulation with various stochastic models
/// - Unified error handling via `PricingError`
/// - Extensible design for adding new pricing models
///
/// ## Example
/// ```rust
/// use optionstratlib::pricing::{PricingEngine, Priceable};
/// use optionstratlib::{Options, ExpirationDate};
/// use positive::{Positive, pos_or_panic};
/// 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 = option.price(&engine)?;
/// # Ok::<(), optionstratlib::error::PricingError>(())
/// ```
pub use barone_adesi_whaley;
pub use asian_black_scholes;
pub use barrier_black_scholes;
pub use binary_black_scholes;
pub use ;
pub use ;
pub use chooser_black_scholes;
pub use cliquet_black_scholes;
pub use compound_black_scholes;
pub use exchange_black_scholes;
pub use lookback_black_scholes;
pub use monte_carlo_option_pricing;
pub use ;
pub use power_black_scholes;
pub use quanto_black_scholes;
pub use rainbow_black_scholes;
pub use spread_black_scholes;
pub use ;
pub use ;
pub use ;