# Finding Correlation between Time Series - is it a meaningless value?

I want to measure the relationship between pairs of time series over different time periods. I've been looking into correlation of time series and it seems to me that there isn't much point in finding the correlation between pairs of time series due to a number of issues (such as potential trends etc.). Is finding the correlation between two time series pointless, or is it still a decent indicator for the relationship between how the two time series move?

I've tried looking into cross-correlation. However ,that seems to require the two time series to be stationary - the problem is that I have more than 80 different time series per year, so having to look over various plots to check for stationarity isn't realistic so I instead decided to just settle with correlation.

Here's what I did to find the correlation between pairs of time series: Each time series had two columns, a date and a number which showed the inventory for an item in a shop. Different time series were for different items in the shop. Many of the time series had varying lengths: one series will have 200 days in a year while another will only have 30. I first found the days the two time series had in common and I then grouped these values/days together (for example if both items had an inventory on 02/03/2016 then this would go into the new subset) and then found the correlation between the inventory of the two different items.

Is this method correct?

EDIT: I've just been reading more into correlation between time series and I was wondering if someone could check this for me. According to this topic: https://quant.stackexchange.com/questions/489/correlation-between-prices-or-returns it looks like it would be better for me to find the correlation between two time series if I instead look at the variation of the inventory of the items rather than looking at both the time series normally. Would that be better or would it still be bad idea for me to do?

2nd Edit: Alternatively, what if I tried to find the correlation of the cumulative sums for both the time series? Would that be okay to do instead?

• As you said, taking the correlation of two non stationary series will be troublesome (ex. Spurious correlations). Without seeing the data, it's expectable that your counts aren't stationary. Have a look at Autoregressive Conditional Poisson (ACP). Also, you've got another problem witch is alignment and missing data, but you should treat them separately. – mugen May 8 '17 at 23:45
• There can certainly a problem with simply calculating correlation or raw time series (e.g. see the simulation here). When you say you want to "measure the relationship", what are you trying to achieve? What's this measure for? There are methods for finding relationships among time series (for nonstationary series, there's methods involving cointegration for example), but knowing the ultimate aim may lead to better advice. – Glen_b May 8 '17 at 23:52
• @Glen_b I'd like to find out whether the pairs of time series I have 'move' together. So say if one of them were to go up, I'd like to find whether the other one goes up as well etc. so I thought correlation would be most appropriate. It's basically to find whether inventory for pairs of items increased/decreased together – ThePlowKing May 9 '17 at 2:40
• @mugen Sorry, could you go into a bit more detail regarding the alignment and missing data problems and how they could be resolved? – ThePlowKing May 9 '17 at 2:40
• Note the random walk simulation example in my link; the implication of the large positive correlation of coin1 and coin2 (well over 0.9) would be that they indeed move together, but the relationship is an illusion. – Glen_b May 9 '17 at 3:55

Traditional correlation measurements between two time series will not tell you much.

As an example, let's take the issue of height across both cross-sectional and time series data.

Cross-sectional example: Measuring the correlation coefficient of height for a sample of 100 21 year old British and Dutch males.

Time series example: Measuring the correlation coefficient of 100 males each year from age 4-21.

In the time series example, you will find that your correlation is highly significant (since growth from 4-18 will continue regardless of the eventual height of each male in the sample).

However, the correlation will be skewed upwards due to the time series trend. Therefore, one cannot interpret any insightful meaning from such a correlation coefficient. With cross-sectional data, the correlation coefficient will be more meaningful since a time trend will not bias the correlation reading to the upside.

Cointegration, on the other hand, allows one to determine whether the correlation is significant or simply due to chance.

To run this in R, you would use the egcm command as follows:

library(egcm)

egcm(x,y)

This will produce the relevant t-statistic which will indicate whether the two time series are cointegrated or not. This would be a recommended method for analysing the correlations (or lack thereof) for your first 30 days of data. Needless to say, one cannot calculate correlations for time series with varying observations.

• Thanks for the write up! So going from what you've written, what I should first do is check if the time series is cointegrated, and if the t-statistic is significant then that means I can find the correlation since the correlation would be meaningful? Also this might be a stupid question, but why can't we calculate correlations for time series with varying observations? I mean, if we only look at the dates where the time series match, then couldn't we use those dates to find whether the two time series move in the same direction etc.? – ThePlowKing May 9 '17 at 2:57
• To your first question, yes. To your second, you can compare time series assuming that you select the ones where they indeed match, i.e. if you select 30 days of data for both time series, then you are comparing two time series with equal observations. – Michael Grogan May 9 '17 at 3:02
• @ThePlowKing, cointegration only works for nonstationary, integrated time series and as such its use is quite limited. Cross correlation and vanilla correlation is fine as long as the series are stationary (thus no trends and no integration). Michael Grogan, what do you mean by your last sentence in the answer? – Richard Hardy May 9 '17 at 6:23
• Thanks for the extra points Richard, forgot to include those caveats. By my last sentence, I mean that if the OP selects a subset of 30 observations for the time series with 200 obs, then he is comparing two time series that have equal observations. i.e. the correlation coefficient must be measured on two time series where no. of observations are equal. – Michael Grogan May 9 '17 at 10:24