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
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
normalto generate 2,500 random returns with the parametersloc=.001,scale=.01and assign this torandom_walk. - Convert
random_walkto apd.Seriesobject and reassign it torandom_walk. - Create
random_pricesby adding 1 torandom_walkand calculating the cumulative product. - Multiply
random_pricesby 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