Skip to main content

WalkParams

Struct WalkParams 

Source
pub struct WalkParams<X, Y>{
    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 values
  • Y - The type for the y-axis values (typically price or rate), must support addition, conversion to positive values, and implement the Walktypable trait for traversal operations

§Fields

  • size - Number of steps or data points to generate in the simulation
  • init_step - Initial step values (starting point) for the random walk
  • walk_type - The specific stochastic process algorithm to use for the simulation
  • walker - Implementation of the walk algorithm that satisfies the WalkTypeAble trait
  • seed - Optional seed for the walk’s random stream; None draws 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: usize

Number 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: WalkType

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

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.

Source

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.

Source

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.

Source

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.

Source

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>

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 WalkParams<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 WalkParams<X, Y>

Source§

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

Formats the value using the given formatter. Read more

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>
where Step<X, Y>: Freeze, Box<dyn WalkTypeAble<X, Y>>: Freeze,

§

impl<X, Y> Send for WalkParams<X, Y>
where Step<X, Y>: Send, Box<dyn WalkTypeAble<X, Y>>: Send,

§

impl<X, Y> Sync for WalkParams<X, Y>
where Step<X, Y>: Sync, Box<dyn WalkTypeAble<X, Y>>: Sync,

§

impl<X, Y> Unpin for WalkParams<X, Y>
where Step<X, Y>: Unpin, Box<dyn WalkTypeAble<X, Y>>: Unpin,

§

impl<X, Y> UnsafeUnpin for WalkParams<X, Y>
where Step<X, Y>: UnsafeUnpin, Box<dyn WalkTypeAble<X, Y>>: UnsafeUnpin,

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