Simulating random walks

 Consider a discrete random walk Xn,n=0,1, defined by

Xn=i=0nWi

where Wi's are i.i.d. random variables with the following probability:

Pr(Wi=+1)=p,Pr(Wi=1)=q=1p.

with 0p1. We set the initial condition as X0=0.

A sample path (with p=0.5) is shown below:



We can simulate this random walk on a computer, or on Google Sheets in particular, in the following manner.

  1. Set X0=0; i=0.
  2. Generate a uniformly distributed random number r[0,1).
  3. If r<p, then set Xi+1=Xi+1, else set Xi+1=Xi1.
  4. Increment i:=i+1, go to Step 2 and repeat.
To generate a uniformly distributed random number r[0,1), we can use the built-in function RAND() in Google Sheets (as well as in Excel). Similar functions are available in most programming languages.

Such a random number r[0,1) is less than p with probability p if 0p1. This is how to realize an event with a specified probability in general.

Related videos



Comments

Popular posts from this blog

Birth process

Branching processes: Mean and variance

Informal introduction to formal logic