Quant Memo
Advanced

Canonical Correlation Analysis

A way to measure how strongly two whole groups of variables — not just two single variables — move together, by finding the best possible blend of each group to correlate against the other.

Prerequisites: The Sample Covariance Matrix and Eigenvalue Bias

Think of two sections of an orchestra rehearsing somewhat independently — the strings and the brass. You want to know how tightly the two sections are locked together musically. You could pick one violin and one trumpet and check whether they're correlated, but that's an arbitrary and probably weak signal — maybe violin 1 and trumpet 1 happen not to be the pair that's actually in sync. What you really want is: what's the best possible blend of the whole string section, and the best possible blend of the whole brass section, such that those two blended signals move together as tightly as possible? That's the question canonical correlation analysis (CCA) answers, applied to any two groups of variables — a set of macro indicators and a set of asset returns, a block of risk-factor exposures and a block of performance metrics. Instead of testing pairwise correlations one at a time, CCA finds the single best linear "chord" from each side that makes the two groups correlate as strongly as the data allows.

The idea, one symbol at a time

Let XX be a group of pp variables and YY be a group of qq variables (possibly different sizes). CCA looks for a weight vector aa (length pp) and a weight vector bb (length qq) that define two new single variables — the canonical variates U=aXU = a'X and V=bYV = b'Y — chosen to maximize the correlation between UU and VV:

ρ1=maxa,b Corr(aX, bY)\rho_1 = \max_{a,\, b} \ \text{Corr}(a'X,\ b'Y)

In words: search over every possible weighted blend of the XX variables and every possible weighted blend of the YY variables, and find the one pair of blends that correlates the most. ρ1\rho_1, the first canonical correlation, is always at least as large as the biggest single pairwise correlation between any one XX variable and any one YY variable, because it's optimizing over a much larger space of possibilities. Having found that first pair, CCA then finds a second pair of blends — a2Xa_2'X and b2Yb_2'Y — required to be uncorrelated with the first pair, that captures the next-highest remaining correlation, and so on, up to min(p,q)\min(p,q) pairs total. In words: CCA doesn't stop at one relationship, it decomposes the entire cross-relationship between the two groups into a ranked sequence of independent pieces, the way principal components decompose variance within a single group into ranked independent pieces.

Worked example 1: finding the first canonical pair

Take a toy case: X=(x1,x2)X = (x_1, x_2) are two macro indicators and Y=(y1,y2)Y = (y_1, y_2) are two portfolio returns, all standardized to unit variance. Suppose the within-group correlations are zero (x1x2x_1 \perp x_2, y1y2y_1 \perp y_2, to keep the arithmetic clean) and the cross-correlations are Corr(x1,y1)=0.6\text{Corr}(x_1,y_1)=0.6, Corr(x1,y2)=0.1\text{Corr}(x_1,y_2)=0.1, Corr(x2,y1)=0.1\text{Corr}(x_2,y_1)=0.1, Corr(x2,y2)=0.5\text{Corr}(x_2,y_2)=0.5. The largest single pairwise correlation here is 0.60.6 (between x1x_1 and y1y_1). For this clean, uncorrelated-within-group case, the canonical weights work out close to a(0.6, 0.1)a \propto (0.6,\ 0.1) favoring x1x_1 and b(0.6, 0.1)b \propto (0.6,\ 0.1) favoring y1y_1 for the first pair, roughly aligning Ux1U \approx x_1-heavy and Vy1V \approx y_1-heavy — and solving the underlying eigenvalue problem for this cross-correlation matrix gives a first canonical correlation of approximately ρ10.62\rho_1 \approx 0.62, slightly higher than the best raw pairwise correlation of 0.60.6, because the optimal blend borrows a small, correctly-signed contribution from x2x_2 and y2y_2 to squeeze out a bit more shared signal.

Worked example 2: the second canonical pair

Having extracted the first pair (roughly the x1x_1-y1y_1 relationship), CCA finds a second pair of blends, orthogonal to the first, built mostly from x2x_2 and y2y_2 — because the remaining cross-correlation structure (x2x_2 with y2y_2 at 0.50.5) is the next-strongest signal not already captured. Working through the same eigenvalue problem gives a second canonical correlation of roughly ρ20.48\rho_2 \approx 0.48, smaller than ρ1\rho_1 as required (canonical correlations are always found in decreasing order), and by construction U2U_2 is uncorrelated with U1U_1 and V2V_2 is uncorrelated with V1V_1. The result is two separate stories about how the macro block and the return block relate — one dominated by the x1x_1/y1y_1 relationship, a second, weaker and independent one dominated by x2x_2/y2y_2 — rather than one blurred summary number.

Canonical correlation analysis generalizes ordinary correlation from "two variables" to "two whole groups of variables": it finds the best-correlated blend from each group, then a second independent best-correlated blend from what's left, decomposing the entire cross-relationship into ranked, mutually uncorrelated pieces.

Correlation explorer
X →Y ↑
ρ = 0.60r² = 0.36relationship: moderate positive

The scatter above shows what a single pairwise correlation of about the same strength as this example's first canonical correlation looks like — drag the correlation slider and watch how the point cloud tightens; canonical correlation analysis is finding the tightest possible such cloud by choosing the best blend on each axis, rather than being stuck with whatever raw variable pairing you happened to pick.

ρ₁ ≈ 0.62 ρ₂ ≈ 0.48 best raw pairwise = 0.60
CCA finds a first canonical correlation slightly stronger than the best single raw pairwise correlation, then a second, independent, weaker canonical pair capturing whatever cross-relationship the first pair left behind.

What this means in practice

  • Relating factor blocks to return blocks. A common use is checking how strongly a whole set of macro or style factors comoves with a whole set of asset or strategy returns — CCA finds the specific combinations driving that relationship rather than requiring you to guess which pairwise correlation to look at.
  • Dimensionality reduction before regression. When both the predictor set and the target set are multivariate, running CCA first and regressing on the leading canonical variates can be more stable and interpretable than throwing every raw variable into a giant regression.
  • Cross-asset comovement analysis. Comparing a block of rates-market variables to a block of equity-market variables, or a block of on-chain metrics to a block of crypto asset returns, are natural CCA applications.
  • It needs enough data. Estimating min(p,q)\min(p,q) pairs of weights from a covariance-type structure across two groups is a genuinely high-dimensional estimation problem, and gets fragile quickly as pp and qq grow relative to sample size.

The classic confusion: treating the first canonical correlation as a clean summary statistic for "how correlated are these two datasets," the way R2R^2 summarizes how well a regression fits. It's not that simple, because CCA is actively searching over every possible linear blend of each group to maximize the correlation — and with only a modest sample size relative to the number of variables in each group, that search can find and report a large, impressive-looking canonical correlation that is substantially an artifact of overfitting rather than a real, stable relationship. Canonical correlations are notoriously prone to this kind of small-sample inflation, so out-of-sample validation of the canonical relationship matters far more here than it does for an ordinary bivariate correlation between two fixed, pre-specified variables.

Related concepts

Practice in interviews

Further reading

  • Hotelling (1936), Relations Between Two Sets of Variates
  • Johnson & Wichern, Applied Multivariate Statistical Analysis, ch. 10
ShareTwitterLinkedIn