pub struct PnLRange {
pub lower: i32,
pub upper: i32,
}Expand description
Represents a range of Profit and Loss (PnL) values for bucketing or categorizing financial results.
This structure defines a discrete interval of PnL values that can be used for:
- Creating histograms of trading results
- Defining profit/loss categories for analysis
- Setting up thresholds for performance metrics
- Grouping trading outcomes for statistical analysis
The range is defined as [lower, upper) where lower is inclusive and upper is exclusive. PnL values are represented as integer values (i32) rather than decimals for efficient bucketing and categorization.
Fields§
§lower: i32Lower bound of this PnL bucket (inclusive)
upper: i32Upper bound of this PnL bucket (exclusive)
Implementations§
Source§impl PnLRange
impl PnLRange
Sourcepub fn new(lower: i32, upper: i32) -> Self
pub fn new(lower: i32, upper: i32) -> Self
Creates a new PnL range with the specified lower and upper bounds.
This constructor creates a range where the lower bound is inclusive and the upper bound is exclusive, following the conventional [lower, upper) interval notation.
§Parameters
lower- The inclusive lower bound of the rangeupper- The exclusive upper bound of the range
§Returns
A new PnLRange instance with the specified bounds.
§Example
use optionstratlib::pnl::model::PnLRange;
let range = PnLRange::new(-100, 100);
// Creates a PnL range from -100 (inclusive) to 100 (exclusive)Sourcepub fn new_decimal(lower: Decimal, upper: Decimal) -> Result<Self, DecimalError>
pub fn new_decimal(lower: Decimal, upper: Decimal) -> Result<Self, DecimalError>
Creates a new PnL range from Decimal values by converting them to i32.
This constructor provides a convenient way to create a PnLRange from decimal values, automatically converting them to integers for efficient bucketing and categorization.
§Parameters
lower- The inclusive lower bound as a Decimal valueupper- The exclusive upper bound as a Decimal value
§Returns
A new PnLRange instance with the bounds converted to integers.
§Errors
Returns a DecimalError::ConversionError if either bound is
outside the i32 range or cannot be represented as an integer.
§Example
use rust_decimal_macros::dec;
use optionstratlib::pnl::model::PnLRange;
let range = PnLRange::new_decimal(dec!(-50.5), dec!(75.25))?;
// Creates a PnL range from -50 (inclusive) to 75 (exclusive)Trait Implementations§
Source§impl<'de> Deserialize<'de> for PnLRange
impl<'de> Deserialize<'de> for PnLRange
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for PnLRange
Source§impl Serialize for PnLRange
Implements serialization for PnLRange using a custom string format.
impl Serialize for PnLRange
Implements serialization for PnLRange using a custom string format.
This implementation serializes a PnLRange instance as a string in the format
“[lower, upper)” where:
loweris the inclusive lower bound of the rangeupperis the exclusive upper bound of the range
This format provides a clear, human-readable representation of the profit and loss range that preserves the mathematical half-open interval notation, making it ideal for display in reports, logs, or API responses.
§Example
A PnLRange with lower = 100 and upper = 200 will be serialized as “[100, 200)”.
§Implementation Details
This custom serialization is needed because the default derived implementation would serialize the struct as a JSON object with separate fields, while this implementation provides a more compact string representation.
impl StructuralPartialEq for PnLRange
Auto Trait Implementations§
impl Freeze for PnLRange
impl RefUnwindSafe for PnLRange
impl Send for PnLRange
impl Sync for PnLRange
impl Unpin for PnLRange
impl UnsafeUnpin for PnLRange
impl UnwindSafe for PnLRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.