Numerical experiments, Tips, Tricks and Gotchas

## Brownian Motion Simulation

### Introduction

In the earlier post Brownian Motion and Geometric Brownian Motion. I discussed that the simulation of geometric Brownian motion can be reduced to the simulation of Brownian motion or the random walk simulation [1]. There are discussions about particular forms of the simulation equations. In fact, many of them are equivalent.

### Simulation with Gaussian random variable

The Brownian motion is described by the following stochastic differential equation (SDE) [1, 2]: $$dX_{t}=\mu dt+\sigma dW_{t}\label{eq:BrMdr}$$ Here $W_{t}$ is the Wiener process, $\mu$ is the drift and $\sigma$ is the diffusion coefficient. The solution of (\ref{eq:BrMdr}) is well known [2]: $$X_{t}\sim\mathit{\mathcal{N}}(\mu t,\sigma^{2}t)\label{eq:gauss}$$ where $\mathit{\mathcal{N}}(m,v)$ is the Gaussian variable with mean $m$ and variance $v$. The simulation formula is $$\Delta X=\mu\Delta t+\sigma\Delta W\label{eq:simul}$$ There are several variants of simulation implementation.
• Standard Gaussian variable $$\Delta X=\mu\Delta t+\sigma\sqrt{\Delta t}\,\mathcal{N}(0,1)\label{eq:simul-1}$$
• Centered Gaussian variable $$\Delta X=\mu\Delta t+\mathit{\mathcal{N}}(0,\sigma^{2}\Delta t)\label{eq:simul-2}$$
• Drifting Gaussian variable $$\Delta X=\mathit{\mathcal{N}}(\mu\Delta t,\sigma^{2}\Delta t)\label{eq:simul-3}$$
All the above expressions are mathematically equivalent because $$\mathit{\mathcal{N}}(m,v)=m+\sqrt{v}\mathit{\mathcal{N}}(0,1)$$

### Simulation with random walk

We can also replace $\Delta W$ with a symmetric random walk with steps $h_{i}=\pm h$: $$\Delta X=\mu\Delta t+\sigma\sum_{i=1}^{n}h_{i}\label{eq:simul-4}$$ where $$\Delta t=n\tau\label{eq:Dt}$$ and $$h^{2}=\tau\label{eq:h2tau}$$ or with asymmetric random walk $$\Delta X=\sigma\sum_{i=1}^{n}\left(\varrho+h_{i}\right)$$ where $$\varrho=\frac{\mu\tau}{\sigma}=\frac{\mu h^{2}}{\sigma}$$

### Advantages of random walk simulation

Random walk simulation has some advantages. First, it is simple and less time consuming than (\ref{eq:simul-1} - \ref{eq:simul-3}) even with more steps ($n\sim10^{1}\div10^{2}$). Second, it can be easier generalized for the case when the drift and diffusion depend on time and coordinate: $$dX_{t}=\mu(X_{t},t)dt+\sigma(X_{t},t)dW_{t}\label{eq:non-homo}$$ because for sufficiently small steps (\ref{eq:non-homo}) can be modeled as $$\Delta X=\sum_{i=1}^{n}\left(\tau\mu_{i}+\sigma_{i}h_{i}\right)\label{eq:simul-5}$$

### Numerical experiments

Below are simple scripts implementing several variants of the Brownian motion simulation. The IPython HTML notebook was converted to HTML and the simulation session can be viewed at the link below.

Note that the numbers of random paths used in the simulations are relatively small. Therefore the simulated values of drifts and variances are not very accurate.

For more details:

### References

1. Nikolai Shokhirev, Brownian Motion and Geometric Brownian Motion. , www.numericalexpert.com, 2013
2. Gardiner C. W., Handbook of Stochastic Methods for Physics, Chemistry and the Natural Science, Berlin: Springer-Verlag, 1983.