Tidy Random Walk — tidy_random_walk • TidyDensity
Description: Takes in the data from a tidy_ distribution function and applies a random walk calculation of either cum_prod or cum_sum to y.

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.00660 -0.297 0.00291 0.474  -0.00660          -0.00660
    #>  2 1              2 -0.164   -0.284 0.00758 0.0507 -0.164            -0.169
    #>  3 1              3  0.0308  -0.272 0.0179  0.621   0.0308           -0.144
    #>  4 1              4  0.0565  -0.260 0.0387  0.714   0.0565           -0.0953
    #>  5 1              5  0.144   -0.247 0.0763  0.924   0.144             0.0345
    #>  6 1              6 -0.122   -0.235 0.138   0.111  -0.122            -0.0918
    #>  7 1              7  0.0972  -0.223 0.232   0.834   0.0972           -0.00353
    #>  8 1              8  0.192   -0.211 0.360   0.972   0.192             0.188
    #>  9 1              9  0.101   -0.198 0.524   0.843   0.101             0.307
    #> 10 1             10  0.104   -0.186 0.718   0.851   0.104             0.443
    #> # ℹ 1,240 more rows