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.
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 created the variables components
and stock_prices
that you worked with in the last exercises.
- Select the
'Number of Shares'
fromcomponents
, assign tono_shares
, and print the result, sorted in the default (ascending) order. - Multiply
stock_prices
byno_shares
to create a time series of market cap per ticker, and assign it tomarket_cap
. - Select the first and the last row of
market_cap
and assign these tofirst_value
andlast_value
. - Use
pd.concat()
to concatenatefirst_value
andlast_value
alongaxis=1
and plot the result as horizontal bar chart.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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