1. Learn
  2. /
  3. Courses
  4. /
  5. Manipulating Time Series Data in Python

Exercise

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

Instructions

100 XP

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.