pub struct RandomWalk<X, Y>{ /* private fields */ }Expand description
A struct that represents a two-dimensional random walk simulation.
RandomWalk stores a sequence of steps that describe a path in a two-dimensional space,
typically used for financial modeling, time series analysis, or statistical simulations.
It maintains both the steps of the random walk and a descriptive title.
§Type Parameters
-
X- The type for x-axis values (typically representing time or sequence position), which must implementAddAssign(allowing values to be accumulated), be convertible toPositive, and beCopy. -
Y- The type for y-axis values (typically representing price, value, or position), which must implementAddAssign, be convertible toPositive, beCopy, and implement theWalktypabletrait for additional functionality.
Implementations§
Source§impl<X, Y> RandomWalk<X, Y>
impl<X, Y> RandomWalk<X, Y>
Sourcepub fn new<F, E>(
title: String,
params: &WalkParams<X, Y>,
generator: F,
) -> Result<Self, E>
pub fn new<F, E>( title: String, params: &WalkParams<X, Y>, generator: F, ) -> Result<Self, E>
Creates a new random walk instance with the given title and steps.
This constructor takes a title, walk parameters, and a fallible generator function that produces the steps of the random walk from the provided parameters. Errors from the generator are propagated unchanged.
§Parameters
title- A descriptive title for the random walkparams- Parameters that define the properties of the random walkgenerator- A fallible function that generates the steps of the random walk
§Returns
Ok(RandomWalk) on success, or Err(E) when the generator fails.
§Errors
Returns the error type produced by the supplied generator. For
chain-backed generators (e.g. crate::simulation::generator_positive)
this is crate::error::SimulationError.
Sourcepub fn get_title(&self) -> &str
pub fn get_title(&self) -> &str
Returns the title of the random walk.
§Returns
A string slice containing the title of the random walk.
Sourcepub fn get_steps(&self) -> Vec<&Step<X, Y>>
pub fn get_steps(&self) -> Vec<&Step<X, Y>>
Returns a vector of references to all steps in the random walk.
§Returns
A vector containing references to all steps in the random walk.
Sourcepub fn get_step(&self, index: usize) -> Option<&Step<X, Y>>
pub fn get_step(&self, index: usize) -> Option<&Step<X, Y>>
Returns a reference to the step at the specified index.
§Parameters
index- The zero-based index of the step to retrieve
§Returns
Some(&Step<X, Y>)- The step atindex.None- Ifindexis out of bounds.
Named get_*, so it follows slice::get rather than
std::ops::Index: an out-of-bounds index is reported, not aborted
on. Use the walk[index] operator when the index is an invariant of
the caller and a panic is the wanted contract.
Sourcepub fn get_step_mut(&mut self, index: usize) -> Option<&mut Step<X, Y>>
pub fn get_step_mut(&mut self, index: usize) -> Option<&mut Step<X, Y>>
Returns a mutable reference to the step at the specified index.
§Parameters
index- The zero-based index of the step to retrieve
§Returns
Some(&mut Step<X, Y>)- The step atindex.None- Ifindexis out of bounds.
Mutable counterpart of RandomWalk::get_step, with the same
out-of-bounds contract.
Trait Implementations§
Source§impl<X, Y> Clone for RandomWalk<X, Y>
impl<X, Y> Clone for RandomWalk<X, Y>
Source§impl<X, Y> Debug for RandomWalk<X, Y>
impl<X, Y> Debug for RandomWalk<X, Y>
Source§impl<X, Y> Default for RandomWalk<X, Y>
impl<X, Y> Default for RandomWalk<X, Y>
Source§impl<X, Y> Display for RandomWalk<X, Y>
impl<X, Y> Display for RandomWalk<X, Y>
Source§impl<X, Y> Index<usize> for RandomWalk<X, Y>
Implementation of the Index trait for RandomWalk<X, Y>.
impl<X, Y> Index<usize> for RandomWalk<X, Y>
Implementation of the Index trait for RandomWalk<X, Y>.
This allows accessing the steps of a random walk using array indexing notation:
walk[index].
§Type Parameters
X- The type for x-axis values, with constraints as described above.Y- The type for y-axis values, with constraints as described above.
Source§fn index(&self, index: usize) -> &Self::Output
fn index(&self, index: usize) -> &Self::Output
Provides read access to a specific step in the random walk by index.
§Parameters
index- The zero-based index of the step to access.
§Returns
A reference to the Step<X, Y> at the specified index.
§Panics
Panics if the index is out of bounds, as indexing a Vec does. Use
RandomWalk::get_step for the checked form, which returns None
instead.
Source§impl<X, Y> IndexMut<usize> for RandomWalk<X, Y>
Implementation of the IndexMut trait for RandomWalk<X, Y>.
impl<X, Y> IndexMut<usize> for RandomWalk<X, Y>
Implementation of the IndexMut trait for RandomWalk<X, Y>.
This allows modifying steps in a random walk using array indexing notation:
walk[index] = new_step.
§Type Parameters
X- The type for x-axis values, with constraints as described above.Y- The type for y-axis values, with constraints as described above.
Source§fn index_mut(&mut self, index: usize) -> &mut Self::Output
fn index_mut(&mut self, index: usize) -> &mut Self::Output
Provides mutable access to a specific step in the random walk by index.
§Parameters
index- The zero-based index of the step to modify.
§Returns
A mutable reference to the Step<X, Y> at the specified index.
§Panics
Panics if the index is out of bounds, as indexing a Vec does. Use
RandomWalk::get_step_mut for the checked form, which returns None
instead.
Source§impl<X, Y> Len for RandomWalk<X, Y>
Implementation of the Len trait for RandomWalk<X, Y>.
impl<X, Y> Len for RandomWalk<X, Y>
Implementation of the Len trait for RandomWalk<X, Y>.
This implementation provides methods to determine the length and emptiness
of a random walk by delegating to the underlying steps collection.
§Type Parameters
-
X- The type for x-axis values (typically time or sequence position), which must implementAddAssign, be convertible toPositive, and beCopy. -
Y- The type for y-axis values (typically price or value), which must implementAddAssign, be convertible toPositive, beCopy, and implement theWalktypabletrait.
Source§impl<X, Y> Profit for RandomWalk<X, Y>
impl<X, Y> Profit for RandomWalk<X, Y>
Source§fn calculate_profit_at(
&self,
_price: &Positive,
) -> Result<Decimal, PricingError>
fn calculate_profit_at( &self, _price: &Positive, ) -> Result<Decimal, PricingError>
Source§fn get_point_at_price(
&self,
_price: &Positive,
) -> Result<(Decimal, Decimal), PricingError>
fn get_point_at_price( &self, _price: &Positive, ) -> Result<(Decimal, Decimal), PricingError>
Auto Trait Implementations§
impl<X, Y> Freeze for RandomWalk<X, Y>
impl<X, Y> RefUnwindSafe for RandomWalk<X, Y>
impl<X, Y> Send for RandomWalk<X, Y>
impl<X, Y> Sync for RandomWalk<X, Y>
impl<X, Y> Unpin for RandomWalk<X, Y>
impl<X, Y> UnsafeUnpin for RandomWalk<X, Y>
impl<X, Y> UnwindSafe for RandomWalk<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.