View source: R/gen-discrete-walk.R
discrete_walk | R Documentation |
The discrete_walk
function generates multiple random walks over discrete time periods.
Each step in the walk is determined by a probabilistic sample from specified upper and lower bounds.
This function is useful for simulating stochastic processes, such as stock price movements or
other scenarios where outcomes are determined by a random process.
discrete_walk(
.num_walks = 25,
.n = 100,
.upper_bound = 1,
.lower_bound = -1,
.upper_probability = 0.5,
.initial_value = 100
)
.num_walks |
Total number of simulations. |
.n |
Total time of the simulation. |
.upper_bound |
The upper bound of the random walk. |
.lower_bound |
The lower bound of the random walk. |
.upper_probability |
The probability of the upper bound. Default is 0.5. The lower bound is calculated as 1 - .upper_probability. |
.initial_value |
The initial value of the random walk. Default is 100. |
The function discrete_walk
simulates random walks for a specified number of simulations
(.num_walks
) over a given total time (.n
). Each step in the walk is either the upper
bound or the lower bound, determined by a probability (.upper_probability
). The initial
value of the walk is set by the user (.initial_value
), and the cumulative sum, product,
minimum, and maximum of the steps are calculated for each walk. The results are returned
in a tibble with detailed attributes, including the parameters used for the simulation.
A tibble containing the simulated walks, with columns for the walk number, time period, and various cumulative metrics (sum, product, min, max).
Steven P. Sanderson II, MPH
Other Generator Functions:
brownian_motion()
,
geometric_brownian_motion()
,
random_normal_drift_walk()
,
random_normal_walk()
library(ggplot2)
set.seed(123)
discrete_walk()
set.seed(123)
discrete_walk(.num_walks = 10, .n = 250, .upper_probability = 0.51,
.initial_value = 100) |>
visualize_walks()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.