Generating a Random Walk in R is pretty easy. It's done by the following code:
x <- rnorm(100)
y <- cumsum(x)
But how do I generate/simulate a Random Walk with Trend and / or Drift?
Generating a Random Walk in R is pretty easy. It's done by the following code:
x <- rnorm(100)
y <- cumsum(x)
But how do I generate/simulate a Random Walk with Trend and / or Drift?
A slightly more compact/efficient version of the code from here:
cumsum(rnorm(n=100, mean=drift, sd=sqrt(variance)))
should give you a realization of a random walk with variance t*variance
and mean t*drift
, where t
is the index (starting from 1; prepend a zero or add a constant to the whole series if you like).