diff --git a/R/auto-rw30.R b/R/auto-rw30.R index 8d0e2b4..96c011b 100644 --- a/R/auto-rw30.R +++ b/R/auto-rw30.R @@ -80,7 +80,7 @@ rw30 <- function() { attr(walks_long, "mu") <- mu attr(walks_long, "sd") <- sd attr(walks_long, "fns") <- "rw30" - attr(res, "dimension") <- 1 + attr(walks_long, "dimension") <- 1 return(walks_long) } diff --git a/R/gen-brown-motion.R b/R/gen-brown-motion.R index 4ef90ca..92f6b0b 100644 --- a/R/gen-brown-motion.R +++ b/R/gen-brown-motion.R @@ -84,11 +84,11 @@ brownian_motion <- function(.num_walks = 10, .n = 100, .delta_time = 1, colnames(rand_matrix) <- 1:num_sims # Get the Brownian Motion and convert to price paths - ret <- apply(rbind(rep(initial_value, num_sims), rand_matrix), 2, cumsum) + res <- apply(rbind(rep(initial_value, num_sims), rand_matrix), 2, cumsum) # Return if (return_tibble){ - ret <- ret |> + res <- res |> dplyr::as_tibble() |> dplyr::mutate(t = 1:(t+1)) |> tidyr::pivot_longer(-t) |> @@ -99,13 +99,13 @@ brownian_motion <- function(.num_walks = 10, .n = 100, .delta_time = 1, } # Return ---- - attr(ret, "n") <- .n - attr(ret, "num_walks") <- .num_walks - attr(ret, "delta_time") <- .delta_time - attr(ret, "initial_value") <- .initial_value - attr(ret, "return_tibble") <- .return_tibble - attr(ret, "fns") <- "brownian_motion" + attr(res, "n") <- .n + attr(res, "num_walks") <- .num_walks + attr(res, "delta_time") <- .delta_time + attr(res, "initial_value") <- .initial_value + attr(res, "return_tibble") <- .return_tibble + attr(res, "fns") <- "brownian_motion" attr(res, "dimension") <- 1 - return(ret) + return(res) } diff --git a/R/gen-geom-brown-motion.R b/R/gen-geom-brown-motion.R index 8280fca..d762cff 100644 --- a/R/gen-geom-brown-motion.R +++ b/R/gen-geom-brown-motion.R @@ -106,7 +106,7 @@ geometric_brownian_motion <- function(.num_walks = 25, .n = 100, # Return if (return_tibble){ - ret <- ret |> + res <- res |> dplyr::as_tibble() |> dplyr::mutate(t = 1:(t+1)) |> tidyr::pivot_longer(-t) |> @@ -116,15 +116,15 @@ geometric_brownian_motion <- function(.num_walks = 25, .n = 100, dplyr::arrange(walk_number, x) } - attr(ret, "n") <- .n - attr(ret, "num_walks") <- .num_walks - attr(ret, "mean") <- .mu - attr(ret, "sigma") <- .sigma - attr(ret, "initial_value") <- .initial_value - attr(ret, "delta_time") <- .delta_time - attr(ret, "return_tibble") <- .return_tibble - attr(ret, "fns") <- "geometric_brownian_motion" + attr(res, "n") <- .n + attr(res, "num_walks") <- .num_walks + attr(res, "mean") <- .mu + attr(res, "sigma") <- .sigma + attr(res, "initial_value") <- .initial_value + attr(res, "delta_time") <- .delta_time + attr(res, "return_tibble") <- .return_tibble + attr(res, "fns") <- "geometric_brownian_motion" attr(res, "dimension") <- 1 - return(ret) + return(res) } diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 0790f2a..2f132bb 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.0 pkgdown_sha: ~ articles: getting-started: getting-started.html -last_built: 2024-07-19T21:36Z +last_built: 2024-07-19T21:52Z urls: reference: https://www.spsanderson.com/RandomWalker/reference article: https://www.spsanderson.com/RandomWalker/articles diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png index 17a3580..e620dfd 100644 Binary files a/docs/reference/Rplot001.png and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/brownian_motion.html b/docs/reference/brownian_motion.html index ff38a39..5583882 100644 --- a/docs/reference/brownian_motion.html +++ b/docs/reference/brownian_motion.html @@ -41,8 +41,8 @@
brownian_motion(
- .n = 100,
.num_walks = 10,
+ .n = 100,
.delta_time = 1,
.initial_value = 0,
.return_tibble = TRUE
@@ -53,12 +53,12 @@ Usage
Arguments
-- .n
-Total time of the simulation.
+- .num_walks
+Total number of simulations.
-- .num_walks
-Total number of simulations.
+- .n
+Total time of the simulation.
- .delta_time
@@ -112,7 +112,20 @@ Exampleslibrary(ggplot2)
brownian_motion()
-#> Error: object 'res' not found
+#> # A tibble: 1,010 × 3
+#> walk_number x y
+#> <fct> <int> <dbl>
+#> 1 1 1 0
+#> 2 1 2 -1.40
+#> 3 1 3 -1.14
+#> 4 1 4 -3.58
+#> 5 1 5 -3.59
+#> 6 1 6 -2.97
+#> 7 1 7 -1.82
+#> 8 1 8 -3.64
+#> 9 1 9 -3.89
+#> 10 1 10 -4.13
+#> # ℹ 1,000 more rows
brownian_motion() |>
ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) +
@@ -120,7 +133,7 @@ Examples labs(title = "Brownian Motion", x = "Time", y = "Value") +
theme_minimal() +
theme(legend.position = "none")
-#> Error: object 'res' not found
+
library(ggplot2)
geometric_brownian_motion()
-#> Error: object 'res' not found
+#> Error in geometric_brownian_motion(): object 'res' not found
geometric_brownian_motion() |>
ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) +
@@ -137,7 +137,7 @@ Examples labs(title = "Geometric Brownian Motion", x = "Time", y = "Value") +
theme_minimal() +
theme(legend.position = "none")
-#> Error: object 'res' not found
+#> Error in geometric_brownian_motion(): object 'res' not found
diff --git a/docs/reference/random_normal_drift_walk-1.png b/docs/reference/random_normal_drift_walk-1.png
index 219bdf3..2f94703 100644
Binary files a/docs/reference/random_normal_drift_walk-1.png and b/docs/reference/random_normal_drift_walk-1.png differ
diff --git a/docs/reference/random_normal_drift_walk.html b/docs/reference/random_normal_drift_walk.html
index bdb9a25..ceffb86 100644
--- a/docs/reference/random_normal_drift_walk.html
+++ b/docs/reference/random_normal_drift_walk.html
@@ -116,13 +116,12 @@