Random walk III
In this exercise, you'll complete your random walk simulation using Facebook stock returns over the last five years. You'll start off with a random sample of returns like the one you've generated during the last exercise and use it to create a random stock price path.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have already imported pandas
as pd
, choice
and seed
from numpy.random
, and matplotlib.pyplot
as plt
. We have loaded the Facebook price as a pd.DataFrame
in the variable fb
and a random sample of daily FB returns as pd.Series
in the variable random_walk
.
- Select the first Facebook price by applying
.first('D')
tofb.price
, and assign tostart
. - Add 1 to
random_walk
and reassign it to itself, then.append()
random_walk
tostart
and assign this torandom_price
. - Apply
.cumprod()
torandom_price
and reassign it to itself. - Insert
random_price
as new column labeledrandom
intofb
and plot the result.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Select fb start price here
start = ____
# Add 1 to random walk and append to start
random_walk = ____
random_price = ____
# Calculate cumulative product here
random_price = ____
# Insert into fb and plot
fb['random'] = ____