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
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 aDatetimeIndex
for each from the'date'
column usingparse_dates
andindex_col
, and assign the result tostocks
anddow_jones
, respectively. - Use
pd.concat()
alongaxis=1
to combinestocks
anddow_jones
and assign the result todata
. Inspect the.info()
ofdata
. - 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