pub struct Step<X, Y>{
pub x: Xstep<X>,
pub y: Ystep<Y>,
}Expand description
Represents a combined x-y step in a two-dimensional simulation or analysis.
This struct pairs an x-direction step (typically representing time) with a y-direction step (typically representing price or value). It’s designed for financial simulations, data visualization, or any context requiring tracking of values across both a time dimension and a value dimension.
The generic parameters allow for flexibility in the types of values stored in both dimensions, while enforcing appropriate constraints to ensure mathematical operations can be performed safely.
§Type Parameters
-
X- The type for x-axis values, which must implementAddAssign(allowing values to be accumulated), be convertible toPositive, and beCopy. -
Y- The type for y-axis values, which must beCopyand convertible toPositive.
§Fields
-
x- AnXstep<X>instance representing the time dimension step with its associated temporal information and value. -
y- AYstep<Y>instance representing the value dimension step with its associated index and numeric value.
§Usage
Typically used in financial modeling, time series analysis, and visualization contexts where coordinated progression along both time and value axes is needed.
Fields§
§x: Xstep<X>The x-axis step containing temporal information and an associated value
y: Ystep<Y>The y-axis step containing an index and an associated positive value
Implementations§
Source§impl<X, Y> Step<X, Y>
Implementation of methods for the Step struct, which represents a point in a two-dimensional
sequential space with both X and Y coordinates.
impl<X, Y> Step<X, Y>
Implementation of methods for the Step struct, which represents a point in a two-dimensional
sequential space with both X and Y coordinates.
Step<X, Y> is designed to track position in simulations or financial models where both
dimensions have meaningful values that must remain positive. Each step maintains its position
in a sequence along with associated values.
§Type Parameters
X- The x-axis value type that must implementAddAssign, be convertible toPositive, and beCopy.Y- The y-axis value type that must beCopyand convertible toPositive.
Sourcepub fn new(
x_value: X,
time_unit: TimeFrame,
datetime: ExpirationDate,
y_value: Y,
) -> Self
pub fn new( x_value: X, time_unit: TimeFrame, datetime: ExpirationDate, y_value: Y, ) -> Self
Creates a new Step with the given X and Y coordinates
§Parameters
x_value- The initial x-axis valuetime_unit- The time frame unit to use for this stepdatetime- The expiration date informationy_value- The initial y-axis value
§Returns
A new Step<X, Y> instance with initialized x and y components
Sourcepub fn next(&self, new_y_value: Y) -> Result<Self, SimulationError>
pub fn next(&self, new_y_value: Y) -> Result<Self, SimulationError>
Move to the next step in the sequence
Creates a new step with incremented x-position and index, using the provided y-value. This is typically used to advance forward in a simulation or calculation sequence.
§Parameters
new_y_value- The y-axis value to use for the next step
§Returns
A new Step<X, Y> instance that represents the next step in the sequence
§Errors
Returns SimulationError::ExpirationReached when the
current step is already at the end of the sequence, or
SimulationError::IndexConversion when the step index would
overflow i32.
Sourcepub fn previous(&self, new_y_value: Y) -> Result<Self, SimulationError>
pub fn previous(&self, new_y_value: Y) -> Result<Self, SimulationError>
Move to the previous step in the sequence
Creates a new step with decremented x-position and index, using the provided y-value. This is typically used to move backward in a simulation or calculation sequence.
§Parameters
new_y_value- The y-axis value to use for the previous step
§Returns
A new Step<X, Y> instance that represents the previous step in the sequence
§Errors
Returns SimulationError::IndexConversion when the step
index would wrap below i32::MIN, or
SimulationError::ExpirationDate when the underlying
Xstep::previous datetime shift fails.
Sourcepub fn get_graph_x_value(&self) -> Result<Decimal, SimulationError>
pub fn get_graph_x_value(&self) -> Result<Decimal, SimulationError>
Returns the x-value prepared for graphing operations
Converts the current x-axis index to a Positive value that can be used
in graphing and visualization functions.
§Returns
A Positive representation of the x-axis index as a floating point value
§Errors
Returns SimulationError::IndexConversion when the step
index cannot be represented as a Decimal (practically
unreachable for i32 inputs but retained for forward
compatibility).
Sourcepub fn get_graph_x_in_days_left(&self) -> Positive
pub fn get_graph_x_in_days_left(&self) -> Positive
Returns the number of days left until expiration for the x-axis component of this step.
This method provides a convenient way to access the time-to-expiry value from the
x-component of the step without having to handle the potential error result that
the underlying days_left() method returns. It’s useful for graphing and visualization
contexts where the days remaining until expiration need to be accessed directly.
§Returns
Positive- A guaranteed positive decimal value representing the number of days until expiration. This value is extracted from the step’s x-component’s expiration date.
Sourcepub fn get_graph_y_value(&self) -> Result<Positive, SimulationError>
pub fn get_graph_y_value(&self) -> Result<Positive, SimulationError>
Returns the y-value prepared for graphing operations
Converts the current y-axis value to a Positive value that can be used
in graphing and visualization functions.
§Returns
A Positive representation of the y-axis value
§Errors
Propagates any SimulationError returned by
Ystep::positive (typically
SimulationError::PositiveError when the stored y value
violates the Positive invariant).
Sourcepub fn get_y_step(&self) -> &Ystep<Y>
pub fn get_y_step(&self) -> &Ystep<Y>
Returns a reference to the Ystep<Y> instance associated with the current object.
§Returns
A reference to the Ystep<Y> contained within the struct.
§Notes
This method provides a non-mutable reference to the Ystep<Y>. If you need
to modify the Ystep<Y>, consider using a different method or accessing it mutably.
Sourcepub fn get_x_step(&self) -> &Xstep<X>
pub fn get_x_step(&self) -> &Xstep<X>
Returns a reference to the Xstep<X> held within the struct.
§Return
A reference of type &Xstep<X> representing the internal x field.
Sourcepub fn get_value(&self) -> &Y
pub fn get_value(&self) -> &Y
Returns a reference to the value of type Y held by the self instance.
This method retrieves the value stored in the y field of the struct,
by calling the value() method on y, and returns a reference to it.
§Returns
A reference to the value of type Y.
Sourcepub fn get_index(&self) -> &X
pub fn get_index(&self) -> &X
Retrieves the index value associated with the instance.
§Returns
A reference to an object of type X, obtained by calling the
step_size_in_time method on the field x of the instance.
Note: The behavior of this method depends on the implementation of the
step_size_in_time method for the type of x.
Sourcepub fn get_positive_value(&self) -> Result<Positive, SimulationError>
pub fn get_positive_value(&self) -> Result<Positive, SimulationError>
Retrieves the positive value associated with the current instance.
§Returns
Positive- A positive value derived fromself.y.
This function internally calls the positive method on self.y
and returns the resulting value.
§Errors
Propagates any SimulationError returned by
Ystep::positive (typically
SimulationError::PositiveError when the stored y value
violates the Positive invariant).
Trait Implementations§
Auto Trait Implementations§
impl<X, Y> Freeze for Step<X, Y>
impl<X, Y> RefUnwindSafe for Step<X, Y>
impl<X, Y> Send for Step<X, Y>
impl<X, Y> Sync for Step<X, Y>
impl<X, Y> Unpin for Step<X, Y>
impl<X, Y> UnsafeUnpin for Step<X, Y>
impl<X, Y> UnwindSafe for Step<X, Y>
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,
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
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.