A random walk is a statistical model which describes the behavior of a variable such that its value today is equal to: (a) the value that it had yesterday, plus (b) a random and unpredictable change. Such models are often used to describe the evolution over time of financial asset prices or the evolution of a particle submerged in a liquid.
The random walk model is also termed “drunkard walk” because it nicely describes the way that a drunkard walks: if the foot is in the position \(p\) in the next moment it will be in the same position plus a random change. If he/she walks with a drift, then is able to keep a certain fixed directionality.
Real-life scenarios that could be modeled as random walks could be:
The movements of an animal e.g. frog
In finance to model the price of a stock
require(forecast)
## Loading required package: forecast
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
TT <- 100
xx <- ww <- rnorm(n = TT, mean = 0, sd = 0.002)
for (t in 2:TT)
{ xx[t] <- xx[t - 1] + ww[t] }
head(xx,n=50)
## [1] -1.694400e-03 -2.153609e-03 1.882873e-03 1.963958e-03 3.370690e-03
## [6] 3.110834e-04 9.887306e-06 1.396245e-03 1.120899e-03 -3.350970e-03
## [11] -4.238047e-03 -3.524206e-03 -6.220939e-04 -4.995214e-03 -5.408993e-03
## [16] -2.504186e-03 -8.728569e-05 2.867112e-03 2.933386e-03 -7.114693e-04
## [21] 1.713701e-04 -1.369106e-03 -1.273675e-03 -6.726676e-04 -1.998898e-03
## [26] -2.531421e-03 -2.196073e-03 -2.824640e-03 -4.677166e-04 -1.435909e-04
## [31] -1.330631e-03 -2.118398e-03 1.155877e-03 7.970617e-04 2.916925e-03
## [36] 2.390941e-03 4.737867e-03 3.472330e-03 3.964227e-03 -2.977196e-04
## [41] -2.266647e-03 -2.117960e-03 -3.099472e-03 -2.986480e-03 -6.222658e-05
## [46] 3.919433e-04 -9.341453e-04 4.987387e-04 -2.081875e-03 -2.519145e-03
hist(xx, probability = T,main = "Random Walk using Normal", col = "sky blue")
tsdisplay(xx, lag.max = 100, main = "Time-series plot", points = F, col="red")
summary(xx)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.0054090 -0.0006347 0.0040610 0.0057296 0.0124537 0.0191597
plot.ts(xx,xlab=t,ylab = expression(italic(x[t])),
main="Random Walk using Normal",type='l',col='green')
# par(mfrow=c(2,1))
TT <- 100;xx <- rbinom(n = TT, 1,0.5)
ww<-replace(xx,xx==0,-1)
for (t in 2:TT)
{
xx[t] <- xx[t - 1] + ww[t]
}
plot.ts(xx,xlab=t,ylab = expression(italic(x[t])),main="Random Walk using Binomial"
,type='l', col='red')
hist(xx, probability = T, col = "sky blue")
summary(xx)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -22.00 -12.25 -8.00 -8.60 -3.00 0.00
head(xx,n=100)
## [1] 0 -1 0 -1 -2 -1 -2 -1 -2 -3 -2 -3 -2 -1 0 -1 -2 -3
## [19] -4 -3 -2 -3 -2 -1 0 -1 -2 -3 -4 -3 -4 -5 -6 -7 -8 -7
## [37] -6 -7 -8 -9 -10 -9 -8 -7 -6 -5 -4 -5 -6 -7 -8 -9 -8 -9
## [55] -10 -11 -12 -11 -10 -9 -10 -9 -8 -7 -8 -7 -8 -9 -8 -9 -8 -9
## [73] -10 -11 -12 -13 -14 -13 -14 -13 -14 -15 -16 -17 -18 -17 -18 -19 -20 -19
## [91] -20 -19 -20 -21 -22 -21 -20 -19 -20 -19
tsdisplay(xx, lag.max = 100, main = "Time-series plot", points = F,col="red")