Skip to main content

PnLRange

Struct PnLRange 

Source
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: i32

Lower bound of this PnL bucket (inclusive)

§upper: i32

Upper bound of this PnL bucket (exclusive)

Implementations§

Source§

impl PnLRange

Source

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 range
  • upper - 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)
Source

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 value
  • upper - 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 Clone for PnLRange

Source§

fn clone(&self) -> PnLRange

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PnLRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for PnLRange

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for PnLRange

Source§

impl Hash for PnLRange

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PnLRange

Source§

fn eq(&self, other: &PnLRange) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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:

  • lower is the inclusive lower bound of the range
  • upper is 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.

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for PnLRange

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more