This function takes in four arguments and returns a tibble of random walks.
Usage
ts_random_walk(
.mean = 0,
.sd = 0.1,
.num_walks = 100,
.periods = 100,
.initial_value = 1000
)
Arguments
- .mean
The desired mean of the random walks
- .sd
The standard deviation of the random walks
- .num_walks
The number of random walks you want generated
- .periods
The length of the random walk(s) you want generated
- .initial_value
The initial value where the random walks should start
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 (Generalized 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.
See also
Other Data Generator:
tidy_fft()
,
ts_brownian_motion_augment()
,
ts_brownian_motion()
,
ts_geometric_brownian_motion_augment()
,
ts_geometric_brownian_motion()
Examples
ts_random_walk(
.mean = 0,
.sd = 1,
.num_walks = 25,
.periods = 180,
.initial_value = 6
)
#> # A tibble: 4,500 × 4
#> run x y cum_y
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 -1.20 -1.20
#> 2 1 2 -0.134 -1.04
#> 3 1 3 -0.134 -0.898
#> 4 1 4 -0.946 -0.0486
#> 5 1 5 0.679 -0.0816
#> 6 1 6 -0.188 -0.0663
#> 7 1 7 0.581 -0.105
#> 8 1 8 0.553 -0.163
#> 9 1 9 0.161 -0.189
#> 10 1 10 0.0301 -0.195
#> # ℹ 4,490 more rows