How to Calculate the Correlation Between Two Stocks
Paste return or price series, choose your method, and instantly compute correlation with a visual scatter chart and regression line.
Stock Data Input
Calculation Options
Tip: For investment analysis, use return data, not raw prices. Correlation on prices can be misleading due to trend effects.
Results
Enter data and click Calculate Correlation to see metrics.
Expert Guide: How to Calculate the Correlation Between Two Stocks
Correlation is one of the most practical statistics in portfolio management. If you are learning how to calculate the correlation between two stocks, you are really learning how to measure whether two return streams move together, move in opposite directions, or move independently. This matters because portfolio risk is not just about each stock on its own, but also about how holdings interact. Two volatile stocks can still reduce total portfolio risk if their correlation is low enough. Conversely, even high quality companies can create concentration risk when their returns are tightly linked.
The correlation coefficient ranges from -1.00 to +1.00. A value near +1 means the stocks tend to move together. A value near -1 means they tend to move in opposite directions. A value near 0 means little linear co-movement. In practice, values drift over time and can change significantly in different market regimes. That is why the correct method, clean data preparation, and rolling analysis are all essential for serious investors.
Why investors calculate stock correlation
- Diversification design: You can mix assets with lower correlations to potentially reduce portfolio volatility.
- Risk control: Correlation helps identify hidden concentration across sectors, factors, or geographies.
- Hedging decisions: A hedge is more effective when correlation relationships are stable and understood.
- Stress testing: During crises, previously low correlations can rise. Monitoring changes is critical.
The core formula you need
The standard approach is Pearson correlation, calculated on matched returns for Stock A and Stock B:
- Compute returns for each period (daily, weekly, or monthly).
- Calculate each stock’s mean return.
- Compute covariance between the two return series.
- Divide covariance by the product of both return standard deviations.
Symbolically: Correlation = Cov(A,B) / [StdDev(A) × StdDev(B)]. If your data has monotonic but not strictly linear behavior, you can also use Spearman correlation, which ranks values first and then computes correlation on ranks.
Step by step workflow used by professionals
- Select a consistent time period. Use identical start and end dates for both stocks.
- Use adjusted prices. Adjusted close accounts for dividends and splits, making return comparisons cleaner.
- Convert prices to returns. For each period: return = (Pt/Pt-1) – 1.
- Align observations. Remove non-overlapping dates and missing values.
- Choose frequency. Daily gives more observations but more noise; monthly is smoother for strategic allocation.
- Compute correlation. Prefer at least 24 to 36 monthly observations for stability in long term allocation analysis.
- Validate with rolling windows. Check 12 month, 24 month, or 36 month rolling correlations to detect structural shifts.
Real world interpretation guide
- +0.70 to +1.00: Strong positive co-movement. Diversification benefit is usually limited.
- +0.30 to +0.69: Moderate positive relationship. Some diversification remains.
- -0.29 to +0.29: Weak relationship. Often useful for risk balancing.
- -0.30 to -1.00: Negative relationship. Potentially strong diversification and hedging value.
Comparison table: sample stock pair correlations (monthly returns, Jan 2019 to Dec 2023)
| Stock Pair | Correlation (r) | Annualized Volatility A | Annualized Volatility B | Interpretation |
|---|---|---|---|---|
| AAPL vs MSFT | 0.86 | 29.1% | 25.4% | Very high co-movement inside mega-cap technology |
| XOM vs AAPL | 0.32 | 31.5% | 29.1% | Moderate link, better diversification than same-sector pair |
| TLT vs SPY | -0.29 | 18.7% | 17.8% | Historically diversifying, but relationship can flip in inflation shocks |
| GLD vs SPY | 0.07 | 14.2% | 17.8% | Near-zero long run relationship, often used as diversifier |
These figures are representative statistics from widely tracked instruments and are rounded for readability. The key lesson is that assets do not need negative correlation to improve diversification. Even moving from 0.85 to 0.30 can substantially change portfolio risk.
Correlation is regime-dependent: a second table for stress context
| Pair | Correlation in 2022 | Long-run Correlation | What changed |
|---|---|---|---|
| AAPL vs MSFT | 0.91 | 0.86 | Risk-off and rate shocks pushed mega-cap tech to move even more tightly together |
| TLT vs SPY | 0.34 | -0.29 | Inflation and rapid rate hikes weakened the classic stock-bond hedge behavior |
| GLD vs SPY | -0.12 | 0.07 | Gold’s defensive demand rose while equities struggled |
Most common mistakes when calculating stock correlation
- Using prices instead of returns: Price levels trend over time and can create spurious relationships.
- Mismatched periods: If dates do not align perfectly, the result is distorted.
- Too few observations: Very short samples can produce unstable and misleading coefficients.
- Ignoring nonlinearity: Pearson captures linear structure, not complex nonlinear dependence.
- Assuming stability: Correlation is not fixed. It changes with policy cycles, inflation, and market stress.
How to use the calculator above effectively
- Paste return data for both stocks using the same intervals.
- Select whether your values are in percent, decimal, or raw prices.
- Choose Pearson for classic portfolio work or Spearman for rank-based robustness.
- Click Calculate and review the coefficient, covariance, and standard deviations.
- Read the scatter chart: tighter upward clustering means stronger positive correlation.
- Repeat with rolling subsets (for example, the last 24 observations) to see drift over time.
Advanced practitioner notes
Institutional investors rarely rely on a single full-sample correlation number. They evaluate correlation matrices by factor regime, earnings cycle phase, and monetary policy environment. Many also combine correlation with beta decomposition and principal component analysis to understand whether two stocks co-move because of sector exposure, growth sensitivity, or broad market risk. For individual investors, the practical equivalent is to compare pair correlations across calm and volatile periods and avoid treating old correlations as permanent truths.
You should also think in terms of portfolio contribution to risk, not only pairwise coefficients. A stock with moderate correlation to the portfolio but very high volatility may still dominate risk contribution. So, correlation is necessary but not sufficient. Use it alongside volatility, expected return assumptions, drawdown behavior, and liquidity quality.
Authoritative learning resources
- U.S. SEC Investor.gov: Diversification basics
- NIST (.gov): Correlation and scatterplot fundamentals
- Penn State (.edu): Correlation interpretation tutorial
Final takeaway
To calculate the correlation between two stocks correctly, always start with clean, aligned return data, apply the right statistical method, and interpret results in context. A single number can be useful, but the highest quality analysis treats correlation as dynamic and scenario-dependent. When you combine correlation with volatility and regime awareness, you make materially better allocation and risk decisions.