Generate a Random Walk in Python

Your goal

You need to generate a random walk time series in Python.

Step-by-step tutorial

You can use the random.normal and cumsum functions in NumPy to do this:

>>> import numpy as np
>>> white_noise = np.random.normal(0.0, 1.0, 1000)
>>> random_walk = np.cumsum(white_noise)

Here's a plot:

>>> import matplotlib.pyplot as plt
>>> plt.clf()
>>> plt.plot(random_walk)
[<matplotlib.lines.Line2D object at 0x125ca3e50>]
>>> plt.show()
A random walk
A random walk