Calculate & plot the composite index
By now you have all ingredients that you need to calculate the aggregate stock performance for your group of companies.
Use the time series of market capitalization that you created in the last exercise to aggregate the market value for each period, and then normalize this series to convert it to an index.
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 for you. We have also loaded components and market_cap_series, which you worked with in the last exercise.
- Aggregate the market cap per trading day by applying
.sum()tomarket_cap_serieswithaxis=1, assign toraw_indexandprintthe result. - Normalize the aggregate market cap by dividing by the first value of
raw_indexand multiplying by 100. Assign this toindexandprintthe result. - Plot the index with the title
'Market-Cap Weighted Index'.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Aggregate and print the market cap per trading day
raw_index = ____
print(____)
# Normalize the aggregate market cap here
index = ____
print(____)
# Plot the index here