Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Manipulating Time Series Data in Python

Cursus bekijken

Oefeninstructies

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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create daily_return
google['daily_return'] = ____

# Create monthly_return
google['monthly_return'] = ____

# Create annual_return
google['annual_return'] = ____

# Plot the result

Code bewerken en uitvoeren