Simulating random walks

 Consider a discrete random walk \(X_n, n = 0, 1, \cdots\) defined by

\[X_n = \sum_{i=0}^{n}W_i\]

where \(W_i\)'s are i.i.d. random variables with the following probability:

\[\begin{eqnarray}\Pr(W_i = +1) &=& p, \\ \Pr(W_i = -1) &=& q = 1 - p.\end{eqnarray}\]

with \(0 \leq p \leq 1\). We set the initial condition as \(X_0 = 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 \(X_0 = 0\); \(i = 0\).
  2. Generate a uniformly distributed random number \(r \in [0, 1)\).
  3. If \(r < p\), then set \(X_{i+1} = X_{i} + 1\), else set \(X_{i+1} = X_{i} - 1\).
  4. Increment \(i := i + 1\), go to Step 2 and repeat.
To generate a uniformly distributed random number \(r \in [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 \in [0,1)\) is less than \(p\) with probability \(p\) if \(0 \leq p \leq 1\). This is how to realize an event with a specified probability in general.

Related videos



Comments

Popular posts from this blog

Open sets and closed sets in \(\mathbb{R}^n\)

Euclidean spaces

Applications of multiple integrals