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

View Course

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() to market_cap_series with axis=1, assign to raw_index and print the result.
  • Normalize the aggregate market cap by dividing by the first value of raw_index and multiplying by 100. Assign this to index and print the 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