Brownian motion or random walk
In this article I describe the random walk as important concept for understanding time series and plot Brownian motion
Random walk
Random walk is an important concept for understanding randomness in time series, or in any phenomena that is sequential. It should be differentiated from white noise which is basically pure random noise, sometimes from uniform, sometimes from normal distribution. When we, for example, remove any autocorrelation from time series, we are left with white noise. More formally, atime series is white noise if the variables are independent and identically distributed with a mean of zero.
Random walk includes the white noise but it also includes the memory of the last step. So random walk is not purely random because it remembers the last step(s) and is dependent from them. Random walk in informal way would look like:
Y(t) = Y(t-1) + wt
where wt is white noise.
Brownian motion
When we see the formal definition of the Brownian motion, we can conclude it is very similar with random walk.
The term “classical Brownian motion” describes the random movement of microscopic particles suspended in a liquid or gas. According to the theory, the temperature of a substance is proportional to the average kinetic energy with which the molecules of the substance are moving or vibrating.
Let’s generate an instance of Brownian motion (i.e. the Wiener process):
Y(t) = Y(t-1) + N (0, delta²*t; 0, t)
N is simply the normally distributed random variable with a mean 0 and variance delta²*t. The last two parameters are making explicit the statistical independence of N on different time intervals; that is, if [t0, t1] and [t2, t3] are disjoint intervals, then N(a, b; t0, t1) and N(a, b; t2, t3) are independent.
Visualisation as a tool of understanding
In order to get this clear, let’s plot several random walks. We will make two separate graphs, first for time series of random walks starting from same point, and the other starting for separated points. But before that, we must write actual function that creates random walk.
def brownian_motion(num_steps, initial_value):
x = np.zeros(num_steps)
for i in range(num_steps-1):
x[i+1]=x[i]+ np.cumsum(np.random.randn())/math.sqrt(num_steps)
return x
It is function that calculates, for some desired number of steps and for some initial value, numpy array which is random walk.
random_walks = 10
random.seed(123)
plt.figure(figsize=(8,8))
plt.xlabel('steps')
plt.ylabel('value')
plt.title('random walks from same initial value')
for walk in range(random_walks):
x = brownian_motion_optimised(1000, 0)
plt.plot(x);
random_walks = 4
plt.figure(figsize=(8,8))
plt.xlabel('steps')
plt.ylabel('value')
plt.title('random walks from same initial value')
for walk in range(random_walks):
for initial in [5,15,20,25]:
x = brownian_motion(1000, initial)
plt.plot(x);
Now, let’s ask ourselves why it is called Brownian motion and how it is related to particles. It is simple, Brownian motion just follows the pattern of random walk, having in memory the previous position. When we plot it, it looks like this:
Conclusion
Randomness seems as something that is in essence of nature. But at the same time, with our mind, we are in position to capture, play with it and control it. This is almost divine property of mind and can be seen even in this very easy and simple practise. That is way I have enjoyed in working it. In the moment I got the idea to plot the random motion of a particle. It is very simple practise but astonishing feeling. If you want to play with this, in the code here, you can easily change the number of particles, steps, etc. Play and enjoy.