CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Manipulating Time Series Data in Python

Afficher le cours

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 the pct_change() of 'Close' for 1, 30 and 360 calendar days, respectively, and multiply each by 100.
  • Plot the result using subplots=True.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Create daily_return
google['daily_return'] = ____

# Create monthly_return
google['monthly_return'] = ____

# Create annual_return
google['annual_return'] = ____

# Plot the result

Modifier et exécuter le code