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

Exercise

Flying Saucers Aren't Correlated to Flying Markets

Two trending series may show a strong correlation even if they are completely unrelated. This is referred to as "spurious correlation". That's why when you look at the correlation of say, two stocks, you should look at the correlation of their returns and not their levels.

To illustrate this point, calculate the correlation between the levels of the stock market and the annual sightings of UFOs. Both of those time series have trended up over the last several decades, and the correlation of their levels is very high. Then calculate the correlation of their percent changes. This will be close to zero, since there is no relationship between those two series.

The DataFrame levels contains the levels of DJI and UFO. UFO data was downloaded from www.nuforc.org.

Instructions

100 XP
  • Calculate the correlation of the columns DJI and UFO.
  • Create a new DataFrame of changes using the .pct_change() method.
  • Re-calculate the correlation of the columns DJI and UFO on the changes.