Article 71BGK Rolling correlation

Rolling correlation

by
John
from John D. Cook on (#71BGK)

Suppose you have data on the closing prices of two stocks over 1,000 days and you want to look at the correlation between the two asset prices over time in rolling 30 day windows.

rolling_correlation1.png

It seems that the rolling correlation is periodic. peaking about every 50 days.

But this is an artifact of the rolling window, not a feature of the data. I created the two simulated stock time series by creating random walks. The price of the stock each day is the price the previous day plus a sample from a normal random variable with mean zero and variance 1.

rolling_correlation2.png

import numpy as npfrom scipy.stats import normn = 1000x = np.cumsum(norm.rvs(size=n))y = np.cumsum(norm.rvs(size=n)) 

If you use a wider window, say 60 days, you'll still see a periodic pattern in the rolling correlation, though with lower frequency.

Related postsThe post Rolling correlation first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments