Comparing stock prices with a benchmark

You also learned in the video how to compare the performance of various stocks against a benchmark. Now you'll learn more about the stock market by comparing the three largest stocks on the NYSE to the Dow Jones Industrial Average, which contains the 30 largest US companies.

The three largest companies on the NYSE are:

Company Stock Ticker
Johnson & Johnson JNJ
Exxon Mobil XOM
JP Morgan Chase JPM

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.

  • Use pd.read_csv() to import 'nyse.csv' and 'dow_jones.csv', creating a DatetimeIndex for each from the 'date' column using parse_dates and index_col, and assign the result to stocks and dow_jones, respectively.
  • Use pd.concat() along axis=1 to combine stocks and dow_jones and assign the result to data. Inspect the .info() of data.
  • Divide data by the first value for each series, multiply by 100 and plot the result.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import stock prices and index here
stocks = ____
dow_jones = ____

# Concatenate data and inspect result here
data = ____
print(____)

# Normalize and plot your data here