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.
Diese Übung ist Teil des Kurses
Manipulating Time Series Data in Python
Anleitung zur Übung
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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Create daily_return
google['daily_return'] = ____
# Create monthly_return
google['monthly_return'] = ____
# Create annual_return
google['annual_return'] = ____
# Plot the result