LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Time Series Analysis in Python

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

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

# Compute correlation of percent changes
changes = ___
correlation2 = ___
print("Correlation of changes: ", correlation2)
Code bearbeiten und ausführen