Skip to main content

RandomWalk

Struct RandomWalk 

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

  • Y - The type for y-axis values (typically representing price, value, or position), which must implement AddAssign, be convertible to Positive, be Copy, and implement the Walktypable trait for additional functionality.

Implementations§

Source§

impl<X, Y> RandomWalk<X, Y>

Source

pub fn new<F, E>( title: String, params: &WalkParams<X, Y>, generator: F, ) -> Result<Self, E>
where F: FnOnce(&WalkParams<X, Y>) -> Result<Vec<Step<X, Y>>, E>, X: Copy + TryInto<Positive> + AddAssign + Display, Y: TryInto<Positive> + Display + Clone,

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 walk
  • params - Parameters that define the properties of the random walk
  • generator - 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.

Source

pub fn get_title(&self) -> &str

Returns the title of the random walk.

§Returns

A string slice containing the title of the random walk.

Source

pub fn set_title(&mut self, title: String)

Updates the title of the random walk.

§Parameters
  • title - The new title to set
Source

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.

Source

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 at index.
  • None - If index is 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.

Source

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 at index.
  • None - If index is out of bounds.

Mutable counterpart of RandomWalk::get_step, with the same out-of-bounds contract.

Source

pub fn first(&self) -> Option<&Step<X, Y>>

Returns a reference to the first step in the random walk, if any.

§Returns
  • Some(&Step<X, Y>) - A reference to the first step if the random walk is not empty
  • None - If the random walk has no steps
Source

pub fn last(&self) -> Option<&Step<X, Y>>

Returns a reference to the last step in the random walk, if any.

§Returns
  • Some(&Step<X, Y>) - A reference to the last step if the random walk is not empty
  • None - If the random walk has no steps

Trait Implementations§

Source§

impl<X, Y> Clone for RandomWalk<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 RandomWalk<X, Y>

Source§

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

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

impl<X, Y> Default for RandomWalk<X, Y>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Source§

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

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

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§

type Output = Step<X, Y>

The type returned when indexing the random walk.

Source§

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

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

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

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 implement AddAssign, be convertible to Positive, and be Copy.

  • Y - The type for y-axis values (typically price or value), which must implement AddAssign, be convertible to Positive, be Copy, and implement the Walktypable trait.

Source§

fn len(&self) -> usize

Returns the number of steps in the random walk.

§Returns

A usize representing the number of steps.

Source§

fn is_empty(&self) -> bool

Determines whether the random walk contains any steps.

§Returns

true if the random walk has no steps, false otherwise.

Source§

impl<X, Y> Profit for RandomWalk<X, Y>

Source§

fn calculate_profit_at( &self, _price: &Positive, ) -> Result<Decimal, PricingError>

Calculates the profit at a specified price. Read more
Source§

fn get_point_at_price( &self, _price: &Positive, ) -> Result<(Decimal, Decimal), PricingError>

Creates a chart point representation of the profit at the given price. Read more

Auto Trait Implementations§

§

impl<X, Y> Freeze for RandomWalk<X, Y>
where Vec<Step<X, Y>>: Freeze,

§

impl<X, Y> RefUnwindSafe for RandomWalk<X, Y>
where Vec<Step<X, Y>>: RefUnwindSafe,

§

impl<X, Y> Send for RandomWalk<X, Y>
where Vec<Step<X, Y>>: Send,

§

impl<X, Y> Sync for RandomWalk<X, Y>
where Vec<Step<X, Y>>: Sync,

§

impl<X, Y> Unpin for RandomWalk<X, Y>
where Vec<Step<X, Y>>: Unpin,

§

impl<X, Y> UnsafeUnpin for RandomWalk<X, Y>
where Vec<Step<X, Y>>: UnsafeUnpin,

§

impl<X, Y> UnwindSafe for RandomWalk<X, Y>
where Vec<Step<X, Y>>: UnwindSafe,

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