Skip to contents

# Tidy Random Walk

Source: `R/tidy-random-walk.R`
`tidy_random_walk.Rd`

Takes in the data from a `tidy_` distribution function and applies a random walk calculation of either `cum_prod` or `cum_sum` to `y`.

## Usage

    tidy_random_walk(
      .data,
      .initial_value = 0,
      .sample = FALSE,
      .replace = FALSE,
      .value_type = "cum_prod"
    )

## Arguments

.data

  The data that is being passed from a `tidy_` distribution function.

.initial_value

  The default is 0, this can be set to whatever you want.

.sample

  This is a boolean value TRUE/FALSE. The default is FALSE. If set to TRUE then the `y` value from the `tidy_` distribution function is sampled.

.replace

  This is a boolean value TRUE/FALSE. The default is FALSE. If set to TRUE AND `.sample` is set to TRUE then the replace parameter of the sample function will be set to TRUE.

.value_type

  This can take one of three different values for now. These are the following:

  - "cum_prod" - This will take the cumprod of y

  - "cum_sum" - This will take the cumsum of y

## Value

An ungrouped tibble.

## Details

Monte Carlo simulations were first formally designed in the 1940’s while developing nuclear weapons, and since have been heavily used in various fields to use randomness solve problems that are potentially deterministic in nature. In finance, Monte Carlo simulations can be a useful tool to give a sense of how assets with certain characteristics might behave in the future. While there are more complex and sophisticated financial forecasting methods such as ARIMA (Auto-Regressive Integrated Moving Average) and GARCH (Generalised Auto-Regressive Conditional Heteroskedasticity) which attempt to model not only the randomness but underlying macro factors such as seasonality and volatility clustering, Monte Carlo random walks work surprisingly well in illustrating market volatility as long as the results are not taken too seriously.

## Author

Steven P. Sanderson II, MPH

## Examples

    tidy_normal(.sd = .1, .num_sims = 25) %>%
      tidy_random_walk()
    #> # A tibble: 1,250 × 8
    #>    sim_number     x        y     dx      dy     p        q random_walk_value
    #>    <fct>      <int>    <dbl>  <dbl>   <dbl> <dbl>    <dbl>             <dbl>
    #>  1 1              1  0.154   -0.284 0.00334 0.938  0.154              0.154
    #>  2 1              2 -0.0944  -0.273 0.0101  0.173 -0.0944             0.0449
    #>  3 1              3  0.0158  -0.262 0.0260  0.563  0.0158             0.0615
    #>  4 1              4  0.00829 -0.252 0.0579  0.533  0.00829            0.0703
    #>  5 1              5 -0.0554  -0.241 0.112   0.290 -0.0554             0.0110
    #>  6 1              6  0.114   -0.231 0.188   0.874  0.114              0.127
    #>  7 1              7 -0.0802  -0.220 0.281   0.211 -0.0802             0.0363
    #>  8 1              8  0.0608  -0.210 0.381   0.728  0.0608             0.0993
    #>  9 1              9  0.00935 -0.199 0.488   0.537  0.00935            0.110
    #> 10 1             10  0.0642  -0.188 0.611   0.739  0.0642             0.181
    #> # ℹ 1,240 more rows