Skip to main content

Step

Struct Step 

Source
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 implement AddAssign (allowing values to be accumulated), be convertible to Positive, and be Copy.

  • Y - The type for y-axis values, which must be Copy and convertible to Positive.

§Fields

  • x - An Xstep<X> instance representing the time dimension step with its associated temporal information and value.

  • y - A Ystep<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.

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 implement AddAssign, be convertible to Positive, and be Copy.
  • Y - The y-axis value type that must be Copy and convertible to Positive.
Source

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 value
  • time_unit - The time frame unit to use for this step
  • datetime - The expiration date information
  • y_value - The initial y-axis value
§Returns

A new Step<X, Y> instance with initialized x and y components

Source

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.

Source

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.

Source

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).

Source

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.
Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_positive_value(&self) -> Result<Positive, SimulationError>

Retrieves the positive value associated with the current instance.

§Returns
  • Positive - A positive value derived from self.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§

Source§

impl<X, Y> Clone for Step<X, Y>

Source§

fn clone(&self) -> Self

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<X, Y> Debug for Step<X, Y>

Source§

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

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

impl<X, Y> Display for Step<X, Y>

Source§

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

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

impl<X, Y> Serialize for Step<X, Y>

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

Auto Trait Implementations§

§

impl<X, Y> Freeze for Step<X, Y>
where Xstep<X>: Freeze, Ystep<Y>: Freeze,

§

impl<X, Y> RefUnwindSafe for Step<X, Y>

§

impl<X, Y> Send for Step<X, Y>
where Xstep<X>: Send, Ystep<Y>: Send,

§

impl<X, Y> Sync for Step<X, Y>
where Xstep<X>: Sync, Ystep<Y>: Sync,

§

impl<X, Y> Unpin for Step<X, Y>
where Xstep<X>: Unpin, Ystep<Y>: Unpin,

§

impl<X, Y> UnsafeUnpin for Step<X, Y>

§

impl<X, Y> UnwindSafe for Step<X, Y>

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> 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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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