Comparing stocks to the S&P 500

The analyses until this point have been performed only between stocks. It is often useful to perform some of these against a market index such as the S&P 500. This will give a sense of how those stocks compare to movements in the overall market.

At the beginning of the chapter, we loaded the S&P 500 data for the same time period as the other stocks. To perform comparisons, we can perform the same calculations to derive the daily percentage change and cumulative returns on the index:

In [50]:
   sp_500_dpc = sp_500['Adj Close'].pct_change().fillna(0)

   2012-01-03    0.000
   2012-01-04    0.000
   2012-01-05    0.003
   2012-01-06   -0.003
   2012-01-09    0.002
   Name: Adj Close, dtype: float64

We can concatenate ...

Get Mastering pandas for Finance now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.