Correlation Calculator
Last updated: 27 June 2026
Reviewed by Gavin Meiring, Lead research and primary author ยท Doctoral Candidate (Corporate Governance) ยท Research and drafting assisted by AI
- The Pearson correlation coefficient is named after Karl Pearson, who formalised it in the 1890s โ building on the work of Francis Galton, who first plotted how two variables move together.
- Correlation runs from โ1 to +1, but it's not the same as causation: ice cream sales and drowning deaths are strongly correlated, simply because both peak in summer.
- Modern portfolio theory was born from correlation: Harry Markowitz's 1952 paper showed that combining assets with low correlations cuts risk more than simply adding more assets of the same type.
Correlation Calculator
A correlation calculator measures the statistical relationship between two sets of data, expressing the strength and direction of that relationship as a coefficient between -1 and +1. It is used by investors assessing portfolio diversification, analysts studying the relationship between economic variables, and researchers identifying connections in data.
How to Use the Correlation Calculator
- Enter the first data set (X values), separated by commas or on separate lines.
- Enter the second data set (Y values) in the same order.
- Click calculate to see the Pearson correlation coefficient and, optionally, a scatter plot of the data.
The Formula
Pearson correlation coefficient (r):
r = (n x sum(XY) - sum(X) x sum(Y)) / sqrt((n x sum(X^2) - (sum(X))^2) x (n x sum(Y^2) - (sum(Y))^2))
Where n is the number of data pairs, and sum() denotes the sum across all pairs.
Alternatively, using means:
r = sum((X - X_mean) x (Y - Y_mean)) / sqrt(sum((X - X_mean)^2) x sum((Y - Y_mean)^2))
The result ranges from -1 (perfect negative correlation) to +1 (perfect positive correlation). A coefficient of 0 indicates no linear relationship.
Real-World Example
Monthly returns for two assets over 6 months:
Asset A: 2%, -1%, 3%, 1.5%, -0.5%, 2.5% Asset B: 1.5%, -0.8%, 2.2%, 1.1%, -0.3%, 1.9%
X_mean = 1.25%, Y_mean = 0.93%
The correlation coefficient works out to approximately r = 0.98, indicating a very strong positive relationship. When Asset A rises, Asset B almost always rises by a proportional amount. Adding both assets to a portfolio provides almost no diversification benefit; they move too closely together.
Now compare Asset A with Asset C: -1.5%, 0.8%, -2.2%, -1.0%, 0.4%, -2.0%
The correlation between A and C would be approximately -0.97, a strong negative correlation. Combining these two assets would provide substantial diversification benefit, as gains in one tend to offset losses in the other.
Correlation in Portfolio Construction
Correlation is central to Modern Portfolio Theory. Harry Markowitz's insight was that combining assets with low or negative correlation reduces portfolio volatility without necessarily reducing expected return. Adding an asset with a correlation of 0.3 to an existing portfolio of correlated stocks reduces overall volatility more than its individual volatility would suggest, because its returns are largely independent of the existing holdings. In practice, correlations between asset classes are not stable over time. Correlations between equities and bonds were negative for much of the 2000s and 2010s (bonds rising when equities fell), providing diversification benefit. In 2022, both fell simultaneously, showing that historical correlations do not always persist in stress periods. Investors should consider stress-period correlations (not just normal-period correlations) when assessing diversification.
Frequently Asked Questions
What is the difference between correlation and causation? Correlation measures whether two variables tend to move together; it says nothing about why. Two variables can be highly correlated due to a shared underlying cause, coincidence, or statistical noise in small samples. The classic example is the high historical correlation between per capita cheese consumption and deaths from bedsheet entanglement: both happen to trend upward over time with no causal relationship. In financial analysis, always consider the economic rationale for a correlation, not just the statistical coefficient.
What is a strong versus weak correlation? As a rough guide: a coefficient of 0.8 to 1.0 (or -0.8 to -1.0) is considered strong; 0.5 to 0.8 (or -0.5 to -0.8) is moderate; 0.2 to 0.5 (or -0.2 to -0.5) is weak; and below 0.2 is negligible. These thresholds vary by field: in the physical sciences, r above 0.9 may be expected; in social science, r above 0.5 can be noteworthy. In portfolio construction, even a correlation of 0.5 between two assets provides meaningful diversification compared to fully correlated assets.
Does the Pearson coefficient capture all types of relationships? No. Pearson's r measures linear relationships only. If two variables have a strong non-linear relationship (for example, a U-shaped or exponential relationship), the Pearson coefficient may be near zero even though the variables are clearly related. In these cases, Spearman's rank correlation or Kendall's tau are better alternatives, as they capture monotonic (not just linear) relationships. For financial return data, Pearson is generally appropriate; for ordinal data or non-normal distributions, rank-based measures are preferable.
How does sample size affect the reliability of a correlation coefficient? Small samples can produce large correlation coefficients purely by chance. With only 6 data points, a coefficient of 0.5 is not statistically significant at standard thresholds. With 30 or more data points, a coefficient of 0.5 is typically significant. Always check the p-value or confidence interval alongside the coefficient, particularly with fewer than 20 to 30 observations. In portfolio analysis, using monthly returns over 36 to 60 months provides a reasonable balance of data points versus recency.
Also try these free tools related to Correlation Calculator: - Standard Deviation Calculator
Building r from the six monthly returns
The two series on this page can be worked by hand, and doing so shows where the coefficient comes from. Take the six monthly returns as percentages and subtract each series' own mean.
| Month | Asset A | Asset B | A minus 1.25 | B minus 0.933333 | Product of deviations |
|---|---|---|---|---|---|
| 1 | 2.0 | 1.5 | 0.75 | 0.5667 | 0.425 |
| 2 | -1.0 | -0.8 | -2.25 | -1.7333 | 3.9 |
| 3 | 3.0 | 2.2 | 1.75 | 1.2667 | 2.216667 |
| 4 | 1.5 | 1.1 | 0.25 | 0.1667 | 0.041667 |
| 5 | -0.5 | -0.3 | -1.75 | -1.2333 | 2.158333 |
| 6 | 2.5 | 1.9 | 1.25 | 0.9667 | 1.208333 |
| Sum | 9.95 |
The mean of A is 7.5 divided by 6, or 1.25 percent. The mean of B is 5.6 divided by 6, or 0.933333 percent. The sum of the products of the deviations is 9.95, the sum of the squared deviations of A is 13.375, and the same sum for B is 7.413333.
Pearson's coefficient divides the sum of products by the square root of the product of the two sums of squares. The product is 99.153333, its square root is 9.957577, and 9.95 divided by 9.957577 gives r = 0.999239.
Two features of that arithmetic matter. Both sums of squares are positive, so the sign of the coefficient comes entirely from the numerator. And r does not change if you rescale either series: shifting B from percentage points to basis points multiplies every deviation by 100 and leaves the coefficient at 0.999239. Multiplying both sums of squares by the same factor squares out through the square root.
The same six months against a third asset
The page sets a third series against A and quotes a strong negative coefficient. The same arithmetic gives the figures in the table.
| Pair | Mean of the second series | Sum of products | r |
|---|---|---|---|
| A against B | 0.933333 | 9.95 | 0.999239 |
| A against C | -0.916667 | -10.225 | -0.997993 |
| B against C | -0.916667 | -7.6167 | -0.998549 |
The third row is the one the page does not give, and it matters for a portfolio decision. Two assets that each move against the first asset also move together, so pairing B with C diversifies nothing even though each of them diversifies A.
The coefficient printed in the example above reads 0.98 for the first pair and minus 0.97 for the second. Recomputing from the twelve returns gives 0.999239 and -0.997993. The recomputed figures are the ones to use when checking your own arithmetic against this page, because the series above are all the data the coefficient needs.
Is a coefficient of this size significant at six points?
Six pairs leave four degrees of freedom, so the test statistic is t = r times the square root of 4, divided by the square root of 1 minus r squared. The two-tailed p-value comes from the t distribution on four degrees of freedom.
| Points | r | t | Two-tailed p |
|---|---|---|---|
| 6 | 0.999239 | 51.239444 | 8.682e-07 |
| 6 | 0.811401 | 2.776445 | 0.05 |
| 6 | 0.5 | 1.154701 | 0.3125 |
| 30 | 0.5 | 3.05505 | 0.0049 |
The critical coefficient at six points is 0.811401 at the 5 percent level, because a coefficient of that size gives exactly the critical t value of 2.776445. The observed 0.999239 clears the bar with a p-value of 8.682e-07, so the relationship is not an artefact of the small sample.
Sample size is what changes the verdict for a moderate coefficient. A coefficient of 0.5 on six points gives t = 1.154701 and a p-value of 0.3125, which is consistent with chance. The same coefficient on 30 points gives t = 3.05505 and a p-value of 0.0049, which is not. That is the whole reason a small-sample correlation needs company before it supports a decision.
Pearson against rank correlation on a curved pair
Pearson's coefficient measures linear association. A relationship that is strong but curved produces a lower figure, and the table shows how much.
| Data | Pearson | Spearman |
|---|---|---|
| X is 1 to 7, Y is 2, 4, 8, 16, 32, 64, 128 | 0.877878 | 1.0 |
| X is 1 to 5, Y is 1, 8, 27, 64, 125 | 0.943118 | 1.0 |
| X is minus 3 to 3, Y is X squared | 0.0 | 0.0 |
In the first two rows every increase in X raises Y, so the rank correlation is exactly 1 and the Pearson coefficient falls short of it: 0.877878 for the doubling series and 0.943118 for the cubes. Take the base-2 logarithm of the doubling series and the Pearson coefficient rises to 1.0, which shows that the first figure was measuring the straightness of the relationship rather than its strength.
The third row is the case rank methods do not rescue. X squared is symmetric about zero, so the linear coefficient is 0 and the rank correlation is also 0, because the relationship is not monotonic either. Neither measure detects a U shape, and a scatter plot found it in a second.
Method and assumptions behind the coefficient
Five properties decide when the coefficient answers the question you asked.
- Pearson measures linear association only. A curved but monotonic relationship gives a lower figure, and a symmetric curve gives zero.
- Both series must have the same number of paired observations, and the pairing must be meaningful. Matching this month's return for one asset to last month's for another produces a number with no interpretation.
- The coefficient is unit-free and symmetric. r between height in metres and mass in kilograms equals r between height in feet and mass in pounds, and r for X against Y equals r for Y against X.
- A restricted range lowers the coefficient. Correlations computed on a subset of the data, such as only the months when the market rose, understate the relationship in the full series.
- One extreme pair can dominate a small sample. With six observations a single outlier moves r by tenths, which is why the p-value above is quoted alongside the coefficient rather than instead of it.
The sample and population conventions do not change the answer here. Dividing the covariance and the two variances by 5 rather than 6 scales all three quantities by the same factor, and that factor cancels in the ratio.
A note on the two papers
Karl Pearson set out the coefficient in Mathematical Contributions to the Theory of Evolution. III. Regression, Heredity, and Panmixia, published in the Philosophical Transactions of the Royal Society of London in 1896. The exact distribution of the coefficient in small samples came from Ronald Fisher, in Frequency Distribution of the Values of the Correlation Coefficient in Samples from an Indefinitely Large Population, published in Biometrika in 1915. The significance table above follows from Fisher's distribution, which is why a sample of six can support a coefficient of 0.999239 and cannot support a coefficient of 0.5.