pub struct WalkParams<X, Y>where
X: Copy + TryInto<Positive> + AddAssign + Display + Sized,
Y: TryInto<Positive> + Display + Sized + Clone,{
pub size: usize,
pub init_step: Step<X, Y>,
pub walk_type: WalkType,
pub walker: Box<dyn WalkTypeAble<X, Y>>,
pub seed: Option<u64>,
}Expand description
Parameters for stochastic process simulations (random walks).
This struct defines the configuration for generating random walks or price path simulations, particularly useful in financial modeling, option pricing, and risk analysis contexts.
The generic parameters allow flexibility in the types of steps and values used in the walk, with appropriate trait bounds to ensure mathematical operations can be performed correctly.
§Type Parameters
X- The type for the x-axis steps (typically time), must support addition and conversion to positive valuesY- The type for the y-axis values (typically price or rate), must support addition, conversion to positive values, and implement theWalktypabletrait for traversal operations
§Fields
size- Number of steps or data points to generate in the simulationinit_step- Initial step values (starting point) for the random walkwalk_type- The specific stochastic process algorithm to use for the simulationwalker- Implementation of the walk algorithm that satisfies theWalkTypeAbletraitseed- Optional seed for the walk’s random stream;Nonedraws from the thread RNG
§Seeding
With seed: None every stochastic walk draws its normal samples from the
thread-local RNG (rand::rng()), so two runs differ. With
seed: Some(s) the built-in walk kernels draw from
optionstratlib_core::utils::deterministic_rng(s) instead, one
generator per generated path, so the same parameters and seed produce the
same path bit for bit on every run with a given version of rand and
rand_distr. That is the scope of the promise: StdRng and
StandardNormal may change their streams across releases, and a
dependency bump that does so is a reviewed change of the pinned fixtures,
not a silent one. WalkType::Historical replays its
prices and ignores the seed. A walker that overrides a walk method owns
its own randomness and decides whether to honour seed.
crate::simulation::simulator::Simulator::new derives a distinct seed
for each of its walks from this one, so a seeded simulator is reproducible
without every walk repeating the same path.
§Usage
This struct is typically instantiated at the beginning of a simulation process to configure how random walks will be generated. It provides the foundation for various financial simulations including price path forecasting, Monte Carlo simulations for options pricing, and risk analysis models.
Fields§
§size: usizeNumber of steps or data points to generate in the simulation Determines the resolution and length of the resulting random walk
init_step: Step<X, Y>Initial step values (starting point) for the random walk Typically represents initial time and price/rate values
walk_type: WalkTypeThe specific stochastic process to use for generating the random walk Determines the mathematical properties and behavior of the simulated path
walker: Box<dyn WalkTypeAble<X, Y>>Implementation of the walk algorithm that satisfies the WalkTypeAble trait Provides the concrete logic for generating steps according to the selected walk_type
seed: Option<u64>Seed of the walk’s random stream. None draws from the thread RNG
(non-reproducible); Some(seed) makes every stochastic built-in walk
reproducible bit for bit for a given rand / rand_distr version.
See the struct-level “Seeding” section.
Implementations§
Source§impl<X, Y> WalkParams<X, Y>
Access methods for the initial y-axis step value.
impl<X, Y> WalkParams<X, Y>
Access methods for the initial y-axis step value.
These methods provide different ways to access and utilize the initial
value of the y-axis step, which is typically associated with the starting
price or other relevant metric in a financial simulation. The y value
is wrapped in a Ystep<Y> which keeps track of the step index and
ensures the value can be converted to a positive number.
Sourcepub fn y(&self) -> &Y
pub fn y(&self) -> &Y
Returns an immutable reference to the initial y-axis value.
This provides direct access to the underlying value without copying.
§Returns
An immutable reference to the initial y-axis value of type &Y.
Sourcepub fn ystep_ref(&self) -> &Ystep<Y>
pub fn ystep_ref(&self) -> &Ystep<Y>
Returns an immutable reference to the Ystep<Y> object.
This allows access to the full Ystep functionality, including
the step index.
§Returns
An immutable reference to the initial Ystep<Y> object.
Sourcepub fn ystep(&self) -> Ystep<Y>
pub fn ystep(&self) -> Ystep<Y>
Returns a copy of the Ystep<Y> object.
This creates a new independent copy of the Ystep.
§Returns
A copy of the initial Ystep<Y> object.
Sourcepub fn ystep_as_positive(&self) -> Result<Positive, SimulationError>
pub fn ystep_as_positive(&self) -> Result<Positive, SimulationError>
Returns the initial y-axis step value as a Positive number.
This ensures the value is positive, which is often a requirement in financial calculations.
§Returns
The initial y-axis value as a Positive number.
§Errors
Propagates any SimulationError returned by
Ystep::positive (typically
SimulationError::PositiveError when the current y value
breaches the Positive invariant).
Trait Implementations§
Source§impl<X, Y> Clone for WalkParams<X, Y>
impl<X, Y> Clone for WalkParams<X, Y>
Source§impl<X, Y> Debug for WalkParams<X, Y>
impl<X, Y> Debug for WalkParams<X, Y>
Auto Trait Implementations§
impl<X, Y> !RefUnwindSafe for WalkParams<X, Y>
impl<X, Y> !UnwindSafe for WalkParams<X, Y>
impl<X, Y> Freeze for WalkParams<X, Y>
impl<X, Y> Send for WalkParams<X, Y>
impl<X, Y> Sync for WalkParams<X, Y>
impl<X, Y> Unpin for WalkParams<X, Y>
impl<X, Y> UnsafeUnpin for WalkParams<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.