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.
Diese Übung ist Teil des Kurses
Manipulating Time Series Data in Python
Anleitung zur Übung
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
indexto apd.DataFramewith the column name'Index'and assign the result todata. - Normalize
djiato start at 100 and add it as new column todata. - Show the total return for both
indexanddjiaby dividing the last row ofdataby the first, subtracting 1 and multiplying by 100. - Show a plot of both of the series in
data.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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