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
//! Financial derivatives pricing and risk management
//!
//! This module provides a comprehensive toolkit for quantitative finance, including:
//! - **Option pricing**: Black-Scholes, finite difference, Monte Carlo, binomial trees
//! - **Exotic derivatives**: Barriers, Asians, lookbacks, digitals, variance swaps
//! - **Greeks calculation**: Delta, Gamma, Vega, Theta, Rho with efficient batch computation
//! - **Implied volatility**: Newton-Raphson and binary search methods
//! - **Model calibration**: Volatility surfaces, Heston parameters, SABR interpolation
//! - **Path simulation**: Geometric Brownian motion with variance reduction
//! - **Risk metrics**: VaR (Historical, Parametric, Monte Carlo), Expected Shortfall
//!
//! # Quick Start
//!
//! ## Pricing a European Option
//!
//! ```
//! use scirs2_integrate::specialized::finance::{
//! derivatives::vanilla::EuropeanOption,
//! types::OptionType,
//! };
//!
//! // Create a European call option
//! let option = EuropeanOption::new(
//! 100.0, // spot price
//! 100.0, // strike
//! 0.05, // risk-free rate
//! 0.0, // dividend yield
//! 0.2, // volatility (20%)
//! 1.0, // maturity (1 year)
//! OptionType::Call,
//! );
//!
//! // Price the option
//! let price = option.price();
//! println!("Option price: ${:.2}", price);
//!
//! // Calculate Greeks
//! let greeks = option.greeks();
//! println!("Delta: {:.4}", greeks.delta);
//! println!("Gamma: {:.4}", greeks.gamma);
//! println!("Vega: {:.4}", greeks.vega);
//! ```
//!
//! ## Monte Carlo Simulation
//!
//! ```
//! use scirs2_integrate::specialized::finance::{
//! utils::{PathGenerator, PathConfig, VarianceReduction},
//! };
//!
//! // Configure path generation
//! let config = PathConfig::new(100.0, 0.05, 0.0, 0.2, 1.0)
//! .with_steps(252) // Daily steps
//! .with_variance_reduction(VarianceReduction::Antithetic);
//!
//! let generator = PathGenerator::new(config);
//!
//! // Generate 10,000 price paths
//! let paths = generator.generate_paths(10000).unwrap();
//! println!("Generated {} paths", paths.len());
//! ```
//!
//! ## Implied Volatility
//!
//! ```
//! use scirs2_integrate::specialized::finance::utils::{
//! black_scholes_call, implied_volatility_newton,
//! };
//!
//! // Market price of a call option
//! let market_price = 10.5;
//!
//! // Calculate implied volatility
//! let iv = implied_volatility_newton(
//! market_price,
//! 100.0, // spot
//! 100.0, // strike
//! 1.0, // time
//! 0.05, // rate
//! true, // is_call
//! ).unwrap();
//!
//! println!("Implied volatility: {:.2}%", iv * 100.0);
//! ```
//!
//! ## SABR Volatility Smile
//!
//! ```
//! use scirs2_integrate::specialized::finance::utils::SABRParameters;
//!
//! // Create SABR parameters
//! let sabr = SABRParameters::new(
//! 0.2, // alpha (initial vol)
//! 0.5, // beta (elasticity)
//! -0.3, // rho (correlation)
//! 0.4, // nu (vol of vol)
//! ).unwrap();
//!
//! // Calculate implied vol across strikes
//! let forward = 100.0;
//! let time = 1.0;
//!
//! for strike in [90.0, 95.0, 100.0, 105.0, 110.0] {
//! let vol = sabr.implied_volatility(forward, strike, time).unwrap();
//! println!("Strike {}: vol = {:.2}%", strike, vol * 100.0);
//! }
//! ```
//!
//! ## Calibrating to Market Data
//!
//! ```
//! use scirs2_integrate::specialized::finance::utils::{
//! ImpliedVolatilitySurface, HestonCalibrator, LossFunction,
//! };
//!
//! // Build volatility surface from market quotes
//! let mut surface = ImpliedVolatilitySurface::new(100.0, 0.05, 0.0);
//!
//! // Add market data (strike, maturity, implied vol, bid-ask spread)
//! surface.add_quote(95.0, 1.0, 0.22, Some(0.01));
//! surface.add_quote(100.0, 1.0, 0.20, Some(0.005));
//! surface.add_quote(105.0, 1.0, 0.21, Some(0.01));
//!
//! // Calibrate Heston model
//! let calibrator = HestonCalibrator::new(surface, LossFunction::WeightedMSE);
//! let result = calibrator.calibrate().unwrap();
//!
//! println!("Calibrated parameters: {:?}", result.parameters);
//! ```
//!
//! ## Exotic Options
//!
//! ```
//! use scirs2_integrate::specialized::finance::{
//! derivatives::exotic::{AsianOption, AveragingMethod},
//! types::OptionType,
//! };
//!
//! // Asian option with geometric averaging
//! let asian = AsianOption::new(
//! 100.0, // spot
//! 100.0, // strike
//! 0.05, // rate
//! 0.0, // dividend
//! 0.2, // volatility
//! 1.0, // maturity
//! OptionType::Call,
//! AveragingMethod::Geometric,
//! 252, // observation points
//! ).unwrap();
//!
//! // Price using closed-form formula
//! let price = asian.price_geometric_closed_form().unwrap();
//! println!("Asian option price: ${:.2}", price);
//! ```
//!
//! # Architecture
//!
//! The module is organized into several submodules:
//!
//! - [`derivatives`]: Option contracts (vanilla, exotic, variance swaps)
//! - [`pricing`]: Pricing methods (Black-Scholes, PDE, MC, trees, Fourier)
//! - [`models`]: Stochastic models (volatility, interest rates)
//! - [`risk`]: Risk measures (Greeks, VaR, stress testing)
//! - `utils`: Utilities (math functions, calibration, simulation)
//! - [`solvers`]: PDE solvers for stochastic processes
//!
//! # Performance Features
//!
//! - **SIMD acceleration**: Via scirs2-core for vector operations
//! - **Parallel execution**: Monte Carlo paths can be generated in parallel
//! - **Variance reduction**: Antithetic variates, control variates
//! - **Efficient Greeks**: Batch calculation using automatic differentiation
//! - **Numerical stability**: Safe math functions, domain validation
// Re-export commonly used types
pub use *;
pub use Greeks;
pub use StochasticPDESolver;
pub use *;
// Re-export pricing methods
pub use ;
// Re-export main solver for backwards compatibility
pub use StochasticPDESolver as FinancialPDESolver;