CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Time Series Analysis in Python

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Compute correlation of levels
correlation1 = ___
print("Correlation of levels: ", correlation1)

# Compute correlation of percent changes
changes = ___
correlation2 = ___
print("Correlation of changes: ", correlation2)
Modifier et exécuter le code