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.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
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'.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Aggregate and print the market cap per trading day
raw_index = ____
print(____)
# Normalize the aggregate market cap here
index = ____
print(____)
# Plot the index here