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
/******************************************************************************
Author: Joaquín Béjar García
Email: jb@taunais.com
Date: 24/12/25
******************************************************************************/
//! # Strike Concentration Metrics
//!
//! This module provides traits for computing Strike Concentration curves,
//! which are essential for understanding market positioning.
//!
//! ## Overview
//!
//! The Strike Concentration identifies specific strike prices with unusually high open
//! interest or trading volume. It looks for clusters of activity where a large number of
//! contracts are concentrated.
//! It is often used to understand which are the key price levels where market positioning
//! is the heaviest.
//!
//! ## Mathematical Background
//!
//! The following common Strike Concentration measures are provided:
//!
//! ### Premium Weighted Strike Concentration
//!
//! ```text
//! Strike Concentration = Strike premium / Mean average of all chain's strike premiums
//! where Strike premium = Put mid price + Call mid price
//! ```
//!
//! ## Curve Representation
//!
//! The curve shows Strike Concentration across strike prices:
//! - **X-axis**: Strike price
//! - **Y-axis**: Strike Concentration
use crateCurve;
use crateCurveError;
/// A trait defining a Strike Concentration representation.
///
/// # Overview
/// Implementors of this trait are required to provide the following methods:
/// - `premium_concentration`: computes and returns a `Curve` object representing
/// the strike concentration calculated based on option's premium.
///
/// The `Curve` struct is a mathematical representation of the strike concentration, where the
/// x-axis typically corresponds to the strike price, and the y-axis corresponds to
/// the strike concentration.
///
/// # Required Methods
/// - **`premium_concentration(&self) -> Result<Curve, CurveError>`**
/// - Computes and returns the premium-based strike concentration ratio as a `Curve`.
/// - The returned `Ok(Curve)` can be used for graphical representation, numerical
/// analysis, or further mathematical operations, such as interpolation or
/// transformations.
/// - Returns a `CurveError` if it is not possible to calculate the strike concentration.
///
/// # Integration with Other Modules
/// The `StrikeConcentrationCurve` trait makes use of the `Curve` struct, defined in the
/// `crate::curves` module. The `Curve` provides the mathematical framework
/// necessary for representing and manipulating the Strike Concentration data. High-quality
/// precision (via the use of `Decimal` and ordered points) ensures that the
/// output from the `premium_weighted_pcr` methods is reliable and suitable for scientific
/// or financial applications.
///
/// # See Also
/// - [`crate::curves::Curve`]: The fundamental mathematical representation of
/// the Put/Call ratio.
/// - [`crate::curves::Point2D`]: The structure representing individual points
/// in the `Curve`.
///
/// # Examples
/// Users can implement this trait and provide their specific logic for generating
/// a `Curve` corresponding to the strike concentration. The strike concentration can be implemented
/// as premium-weighted.
///
/// ```rust
/// use std::collections::BTreeSet;
/// use rust_decimal::Decimal;
/// use optionstratlib::curves::Curve;
/// use optionstratlib::error::CurveError;
/// use optionstratlib::metrics::StrikeConcentrationCurve;
///
/// struct MyStrikeConcentration;
///
/// impl StrikeConcentrationCurve for MyStrikeConcentration {
/// fn premium_concentration(&self) -> Result<Curve, CurveError> {
/// // Custom logic to build and return a Curve representing the premium
/// // weighted strike concentration
/// let curve = Curve { points: BTreeSet::new(), x_range: (Decimal::ZERO, Decimal::ZERO) };
/// Ok(curve)
/// }
/// }
/// ```
///
/// This enables integration of user-defined volatility models with the broader
/// ecosystem of mathematical and financial tools that utilize the `Curve` data type.