Compare index performance against benchmark I

The next step in analyzing the performance of your index is to compare it against a benchmark.

In the video, we used the S&P 500 as benchmark. You can also use the Dow Jones Industrial Average, which contains the 30 largest stocks, and would also be a reasonable benchmark for the largest stocks from all sectors across the three exchanges.

This exercise is part of the course

Manipulating Time Series Data in Python

View Course

Exercise instructions

We have already imported pandas as pd, matplotlib.pyplot as plt for you. We have also loaded your index and the DJIA data into variables index and djia, respectively, both as a pd.Series().

  • Convert index to a pd.DataFrame with the column name 'Index' and assign the result to data.
  • Normalize djia to start at 100 and add it as new column to data.
  • Show the total return for both index and djia by dividing the last row of data by the first, subtracting 1 and multiplying by 100.
  • Show a plot of both of the series in data.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Convert index series to dataframe here
data = ____

# Normalize djia series and add as new column to data
djia = ____
data['DJIA'] = ____

# Show total return for both index and djia
print(____)

# Plot both series