LoslegenKostenlos loslegen

Create time series of market value

You can now use the number of shares to calculate the total market capitalization for each component and trading date from the historical price series.

The result will be the key input to construct the value-weighted stock index, which you will complete in the next exercise.

Diese Übung ist Teil des Kurses

Manipulating Time Series Data in Python

Kurs anzeigen

Anleitung zur Übung

We have already imported pandas as pd and matplotlib.pyplot as plt for you. We have also created the variables components and stock_prices that you worked with in the last exercises.

  • Select the 'Number of Shares' from components, assign to no_shares, and print the result, sorted in the default (ascending) order.
  • Multiply stock_prices by no_shares to create a time series of market cap per ticker, and assign it to market_cap.
  • Select the first and the last row of market_cap and assign these to first_value and last_value.
  • Use pd.concat() to concatenate first_value and last_value along axis=1 and plot the result as horizontal bar chart.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Select the number of shares
no_shares = ____
print(____)

# Create the series of market cap per ticker
market_cap = ____

# Select first and last market cap here
first_value = ____
last_value = ____


# Concatenate and plot first and last market cap here


Code bearbeiten und ausführen