Methods for Measuring Similarity Between Financial Time Series
Summary
The document surveys ways to compare stock time series, with the practical suggestion to work with returns or differences rather than trending price levels. It reviews Pearson correlation for linear association and rank-based Spearman and Kendall measures for monotonic relationships and reduced sensitivity to outliers. It also introduces distance correlation, which can detect nonlinear dependence and is described as zero only under independence, plus cointegration as a way to study long-run relationships.
Other methods address structure that a single correlation can miss. Wavelet coherence compares comovement across time and frequency and can use phase differences to examine lead-lag patterns. Copulas can describe conditional and tail dependence, while quantile correlation focuses on relationships in distributional extremes. Cross-correlation of lagged returns and ARIMA-based clustering are also mentioned. These are options rather than a tested ranking: the document gives no comparative experiment, and method choice depends on the intended notion of similarity, sampling, stationarity, and whether the goal is substitution, prediction, or risk analysis.
Key ideas
- Return or differenced series can reduce spurious similarity caused by shared price trends.
- Pearson correlation measures linear association, while rank correlations capture monotonic relationships with less reliance on magnitudes.
- Distance correlation can identify nonlinear dependence as well as linear dependence.
- Wavelet coherence examines time-varying and frequency-specific comovement and phase.
- Copulas and quantile methods can focus analysis on conditional or tail dependence.
Tags
Full text
# Time-series similarity measures
# Time-series similarity measures
Suppose I have two time series $X$ and $Y$ of stock prices. How do I measure the "similarity" of $X$ and $Y$?
(I'm being deliberately vague as I don't have a particular application, and I'm curious about different approaches in general. But I guess you can imagine that there's some stock x that I don't want to trade directly, for whatever reason, so I want to find a similar stock y to trade in its place.)
One method is to take a Pearson or Spearman correlation. To avoid problems of spurious correlation (since the price series likely contain trends), I should take these correlations on the differenced or returns series (which should be more stationary).
What are other similarity methods and their pros/cons?
## Answer by vonjd (score 30)
https://quant.stackexchange.com/a/8120
One of my favorites is a generalization of correlation: Distance Correlation (dCor)
There are several reasons for that:
- It generalizes classical (i.e. linear) correlation in the sense that linearity is a special case. It gives identical readings for linear dependence.
- There are analogs for variance, covariance and standard deviation, so these identities hold: $$\operatorname{dVar}^2_n(X) := \operatorname{dCov}^2_n(X,X)$$ and $$\operatorname{dCor}(X,Y) = \frac{\operatorname{dCov}(X,Y)}{\sqrt{\operatorname{dVar}(X)\,\operatorname{dVar}(Y)}}$$
- $dCor=0$ implies true independence, all other readings imply linear or non-linear dependence - Compare the following readings, first linear correlation (source):
and distance correlation (source):
Beware, oversimplification ahead: The reason it shows this behavior is basically that it is the correlation of the characteristic functions of the random variables, i.e. the Fourier transforms of the probability density functions, i.e. a rotation from the time into the frequency domain. Therefore not only linear dependence is being tested but basically all functional dependencies which can be represented by the (periodic) complex exponential function. To get an intuition read also this article: Here.
There is an implementation in R.
## Answer by chrisaycock (score 29)
https://quant.stackexchange.com/a/850
I assume you're using returns (or log returns) instead of actual stock prices. In practice, you may also want to smooth the data by using a moving average.
There are several correlation coefficients:
- Pearson's $r$ - most commonly used definition of correlation:
\begin{equation} r = \frac{\sigma_{x,y}}{\sigma_x \sigma_y} \end{equation}
- Spearman's $\rho$ - uses the rank of each data set (array index if data had been sorted); less sensitive to outliers in the sample as it's non-parametric:
\begin{equation} d_i = x_i - y_i \end{equation}
\begin{equation} \rho = 1 - \frac{6\Sigma d_{i}^{2}}{n(n^{2}-1)} \end{equation}
- Kendall's $\tau$ - also based on ranking, but represents the probability that the two data sets are in the same order vs. the probability that they are in different orders:
\begin{equation} \tau = \frac{C - D}{\frac{1}{2} n(n - 1)} \end{equation}
- Kruskal's $\Gamma$ - similar to Kendall's, but acknowledges ties in the ordering:
\begin{equation} \Gamma = \frac{C - D}{C + D} \end{equation}
$C$ is the number of concordant pairs and $D$ is the number of discordant pairs.
## Answer by Zarbouzou (score 6)
https://quant.stackexchange.com/a/854
You can look at cointegration.
## Answer by Ralph Winters (score 4)
https://quant.stackexchange.com/a/859
If you use a Box-Jenkins model, look at this research which uses an ARIMA framework to define clusters, and then measures the similarity of the time series via a cepstral coefficient based upon the autoregressive parameters.
http://www.csee.umbc.edu/~kalpakis/homepage/papers/ICDM01.pdf
## Answer by Jase (score 3)
https://quant.stackexchange.com/a/8116
You can use wavelet coherence, which is a measure of frequency-varying and time-varying similarity of two time series $X_t$ and $Y_t$ by comparing the coefficients of the wavelet transform $\int_{-\infty}^{\infty} f(t) \psi_{u,s}(t)dt$ (in highly non-technical terms). You can use the phase difference to study the lead-lag relationship.
The benefit would be:
- Doesn't require stationarity in $f(t)$.
- Detects frequency-dependent comovement. If speculative behavior drives mid-high frequency returns and investment behavior drives low frequency returns then there is no reason why comovement at one frequency necessitates comovement at another frequency.
- You can couple the analysis with an analysis of phase difference between the two wavelet transforms, frequency-dependent Granger causality and other tools.
Another method would be copula correlations and copula conditional probabilities.
- These can be time-varying through the Patton (2006) paramaterizations and more recent SCAR versions and I don't think the assumptions on the DGP is very strict.
- You can study $\mathbb{P}(X < q | Y < q)$ which is a measure of comovement that is not offered by standard correlation measures.
- You can get time-varying tail correlations if you are concerned with tail events.
Also, quantile correlations:
- Still a working paper.
- Correlation of one variable and another, conditional on the other being in an extreme region of the distribution.
There's also extreme correlation measures within generalised pareto distribtions. ...Not sure how this works though.
## Answer by rtybase (score 1)
https://quant.stackexchange.com/a/8948
Start with simple things like Pearson correlation, e.g.
## Answer by Richard Hardy (score 0)
https://quant.stackexchange.com/a/24648
You may consider cross correlations of logarithmic returns on the two assets' prices, $\text{Corr}(x_t,y_{t-h})$, where $x_t$ and $y_t$ are the returns series and $h$ is the time lag. Cross correlation is the same as ordinary correlation but one series of returns is lagged by $h$ periods with respect to the other series. However, its use may be limited as information dissemination in liquid markets is quick and prices react to shocks without considerable delays.
## Answer by Barnaby (score 0)
https://quant.stackexchange.com/a/24666
You could use wavelet cross correlation and phase analysis coherence between the two series. By analyzing the the series at multiple frequencies you can establish if there is causality (one causing the other and such even if not direct and thus if one can be used to precict another). Cross correlation will indicate at what frequencies the two series are related.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.