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
/******************************************************************************
Author: Joaquín Béjar García
Email: jb@taunais.com
Date: 24/12/25
******************************************************************************/
//! # Stress Metrics Module
//!
//! Provides stress-testing metrics for options analysis, helping evaluate how
//! options behave under extreme market conditions such as large moves in
//! volatility, rapid time decay, or sudden price shocks.
//!
//! ## Core Features
//!
//! ### Volatility Sensitivity
//!
//! Analyzes portfolio sensitivity to volatility changes using Taylor expansion:
//! - First-order effect: Vega × Δσ
//! - Second-order effect: 0.5 × Vomma × Δσ²
//!
//! - **Curve representation by strike**: Shows vega exposure at each strike
//! - **Surface representation (price vs volatility)**: P&L across price-vol space
//!
//! ### Time Decay Profile
//!
//! Tracks how option value decays as time passes:
//! - Theta decay acceleration near expiration
//! - Time value erosion patterns
//!
//! - **Curve representation by strike**: Theta at each strike
//! - **Surface representation (price vs time)**: Value decay over time
//!
//! ### Price Shock Impact
//!
//! Evaluates impact of sudden price movements:
//! - Delta effect: First-order price sensitivity
//! - Gamma effect: Second-order price sensitivity
//! - Cross-effects with volatility (Vanna)
//!
//! - **Curve representation by strike**: P&L for price shock at each strike
//! - **Surface representation (price vs volatility)**: Combined shock scenarios
//!
//! ## Usage Examples
//!
//! ### Volatility Sensitivity
//!
//! ```rust
//! use std::collections::BTreeSet;
//! use rust_decimal::Decimal;
//! use optionstratlib::curves::Curve;
//! use optionstratlib::error::{CurveError, SurfaceError};
//! use optionstratlib::surfaces::Surface;
//! use optionstratlib::metrics::{VolatilitySensitivityCurve, VolatilitySensitivitySurface};
//! use positive::Positive;
//!
//! struct MyVolSensitivity;
//!
//! impl VolatilitySensitivityCurve for MyVolSensitivity {
//! fn volatility_sensitivity_curve(&self) -> Result<Curve, CurveError> {
//! // Custom logic to compute vega exposure by strike
//! Ok(Curve { points: BTreeSet::new(), x_range: (Decimal::ZERO, Decimal::ZERO) })
//! }
//! }
//!
//! impl VolatilitySensitivitySurface for MyVolSensitivity {
//! fn volatility_sensitivity_surface(
//! &self,
//! _price_range: (Positive, Positive),
//! _vol_range: (Positive, Positive),
//! _price_steps: usize,
//! _vol_steps: usize,
//! ) -> Result<Surface, SurfaceError> {
//! // Custom logic to compute P&L surface across price-vol space
//! Ok(Surface::new(BTreeSet::new()))
//! }
//! }
//! ```
//!
//! ### Time Decay Profile
//!
//! ```rust
//! use std::collections::BTreeSet;
//! use rust_decimal::Decimal;
//! use optionstratlib::curves::Curve;
//! use optionstratlib::error::{CurveError, SurfaceError};
//! use optionstratlib::surfaces::Surface;
//! use optionstratlib::metrics::{TimeDecayCurve, TimeDecaySurface};
//! use positive::Positive;
//!
//! struct MyTimeDecay;
//!
//! impl TimeDecayCurve for MyTimeDecay {
//! fn time_decay_curve(&self) -> Result<Curve, CurveError> {
//! // Custom logic to compute theta by strike
//! Ok(Curve { points: BTreeSet::new(), x_range: (Decimal::ZERO, Decimal::ZERO) })
//! }
//! }
//!
//! impl TimeDecaySurface for MyTimeDecay {
//! fn time_decay_surface(
//! &self,
//! _price_range: (Positive, Positive),
//! _days_to_expiry: Vec<Positive>,
//! _price_steps: usize,
//! ) -> Result<Surface, SurfaceError> {
//! // Custom logic to compute value decay surface
//! Ok(Surface::new(BTreeSet::new()))
//! }
//! }
//! ```
//!
//! ### Price Shock Impact
//!
//! ```rust
//! use std::collections::BTreeSet;
//! use rust_decimal::Decimal;
//! use optionstratlib::curves::Curve;
//! use optionstratlib::error::{CurveError, SurfaceError};
//! use optionstratlib::surfaces::Surface;
//! use optionstratlib::metrics::{PriceShockCurve, PriceShockSurface};
//! use positive::Positive;
//!
//! struct MyPriceShock;
//!
//! impl PriceShockCurve for MyPriceShock {
//! fn price_shock_curve(&self, _shock_pct: Decimal) -> Result<Curve, CurveError> {
//! // Custom logic to compute P&L impact by strike
//! Ok(Curve { points: BTreeSet::new(), x_range: (Decimal::ZERO, Decimal::ZERO) })
//! }
//! }
//!
//! impl PriceShockSurface for MyPriceShock {
//! fn price_shock_surface(
//! &self,
//! _price_range: (Positive, Positive),
//! _vol_range: (Positive, Positive),
//! _price_steps: usize,
//! _vol_steps: usize,
//! ) -> Result<Surface, SurfaceError> {
//! // Custom logic to compute shock impact surface
//! Ok(Surface::new(BTreeSet::new()))
//! }
//! }
//! ```
pub use ;
pub use ;
pub use ;