Plotting multi-period returns
The last time series method you have learned about in the video was .pct_change()
. Let's use this function to calculate returns for various calendar day periods, and plot the result to compare the different patterns.
We'll be using Google stock prices from 2014-2016.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have already imported pandas
as pd
, and matplotlib.pyplot
as plt
. We have also loaded 'GOOG'
stock prices for the years 2014-2016, set the frequency to calendar daily, and assigned the result to google
.
- Create the columns
'daily_return'
,'monthly_return'
, and'annual_return'
that contain thepct_change()
of'Close'
for 1, 30 and 360 calendar days, respectively, and multiply each by 100. - Plot the result using
subplots=True
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create daily_return
google['daily_return'] = ____
# Create monthly_return
google['monthly_return'] = ____
# Create annual_return
google['annual_return'] = ____
# Plot the result