SIMULATION OF A RANDOM WALK IN R

Here is the code in R for simulation of Random walk :

x=NULL

x[1]=0

for( i in 2:10000) {

x[i]=x[i-1] + rnorm(1) }

print(x)


#converting it into a time series data

random_walk = ts(x)

plot(random_walk, main='visualization of a random work' , xlab='days', ylab=' ')






acf(random_walk)



As we see there is a high correlation in the correlogram, the random walk is a non-stationary process.
 # making the series stationary by differencing the values

z<-diff(random_walk)
plot(z)

 # we get white noise




acf(z)



Conclusion :  We observe that there is no lag and hence no correlation. Thus we obtained stationary series by differencing the time series.

Comments