Random walk I

In the last video, you have seen how to generate a random walk of returns, and how to convert this random return series into a random stock price path.

In this exercise, you'll build your own random walk by drawing random numbers from the normal distribution with the help of numpy.

This exercise is part of the course

Manipulating Time Series Data in Python

View Course

Exercise instructions

We have already imported pandas as pd, functions normal and seed from numpy.random, and matplotlib.pyplot as plt.

  • Set seed to 42.
  • Use normal to generate 2,500 random returns with the parameters loc=.001, scale=.01 and assign this to random_walk.
  • Convert random_walk to a pd.Series object and reassign it to random_walk.
  • Create random_prices by adding 1 to random_walk and calculating the cumulative product.
  • Multiply random_prices by 1,000 and plot the result for a price series starting at 1,000.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Set seed here


# Create random_walk
random_walk = ____

# Convert random_walk to pd.series
random_walk = ____

# Create random_prices
random_prices = ____

# Plot random_prices here