Random walk

set.seed(1234)
n=1000
p = rep(0,n)
a = rep(0,n)
p[1] = 0
a[1] = 1
for (t in 2:n){
  a[t] = sample(c(-1,1),size=1)
  p[t] = p[t-1] + a[t]
}

par(mfrow=c(2,2))
ts.plot(p[1:50],ylab="");abline(h=0,lty=2)
ts.plot(p[1:100],ylab="");abline(h=0,lty=2)
ts.plot(p[1:200],ylab="");abline(h=0,lty=2)
ts.plot(p[1:1000],ylab="");abline(h=0,lty=2)

Autocorrelation function

par(mfrow=c(1,1))
acf(p,main="",lag=200)

Random walk with drift

set.seed(1234)
n     = 10000
a     = rnorm(n,0,0.0637)
p     = rep(0,n)
p2    = rep(0,n)
p[1]  = 0
p2[1] = 0
for (t in 2:n){
  p[t]  = 0.0103 + p[t-1] + a[t]
  p2[t] = p2[t-1] + a[t]
}
par(mfrow=c(2,2))
for (t in c(100,500,1000,10000)){
  ts.plot(p[1:t],ylab="",ylim=range(p[1:t],p2[1:t]))
  lines(p2[1:t],col=2)
  abline(h=0,lty=2)
}