The transition density of the diffusion process is :
$$P(x|x') = \exp\left[-\frac12\frac{(x-x')^2}{D(t-t')}\right] $$Recall that this process was first constructed by Bachelier in the context of market price fluctuations and then rederived by Einstein (1905) as a model for Brownian motion. In the stochastic process literature this process is known as the Wiener process.
The defining features of this process are that it is
These properties make it very simple to generate sample paths. Increments can be chosen independently from a Gaussian distribution and then added together, cumulatively, to generate the path.
The code below generates sample paths of the diffusion process, sampled with time increments $\Delta t = 1$ and diffusion coefficient $D = 1$. The increments, then, are standard normal variates.
In [3]:
import numpy as np
import scipy as sp
import scipy.signal as sig
import matplotlib.pyplot as plt
In [28]:
N = 128 # number of paths
Nt = 1024 # T = Nt * dt is the duration of each path
for i in range(N):
dx = np.random.randn(Nt) # independent increments
x = np.cumsum(dx) # cumulative sum
t = np.arange(Nt) # times
plt.plot(t, x)