Covariance Calculator (Stocks)
Calculate covariance and correlation between two stocks from period returns. Measure how two assets move together for diversification and risk analysis.
The prefilled returns are a synthetic example. Enter 2 for 2%, not 0.02. Asset labels do not fetch market data; calculations run in your browser.
Sample covariance (percentage points²)
N/A for a constant return series
Sample std dev, not annualized
Sample std dev, not annualized
Period returns (%)
Use the same dates, frequency, currency, and return convention for both assets. Sample covariance and variances use n−1; correlation normalizes covariance by the two sample standard deviations. Two nonconstant observations always give correlation +1 or −1, so that minimum is not a reliable history.
What is Stock Covariance?
Covariance measures how two variables (e.g. two stock returns) move together. A positive covariance means the returns tend to move in the same direction; a negative covariance means they tend to move in opposite directions. Covariance is used in portfolio theory to quantify diversification: combining assets with low or negative covariance can reduce portfolio risk.
Correlation is the normalized version of covariance (between -1 and 1), so it is easier to compare across different pairs of stocks. Covariance has units of (% × %), while correlation is unitless.
How to Use This Calculator
- Name your stocks: Optionally label the two assets (e.g. AAPL, MSFT) for clarity in results.
- Enter period returns: For each time period (e.g. month or year), enter the return for Stock A and Stock B in percent. Use the same number of periods for both; add or remove rows as needed.
- Results: The calculator shows sample covariance, correlation (ρ), and the standard deviation of each return series. Covariance and correlation update automatically as you edit.
Why Stock Covariance Matters
Understanding covariance between stocks helps you build diversified portfolios, estimate portfolio variance, and assess how much two positions hedge each other. It is used in modern portfolio theory (MPT), risk budgeting, and correlation-based strategies.
- Diversification: Low or negative covariance lowers the covariance contribution when weights and individual variances are held fixed. Changing assets or weights also changes expected return and risk.
- Portfolio variance: Portfolio variance depends on weights, individual variances, and pairwise covariances; this calculator gives you the covariance input for two assets.
- Hedging: Negative covariance can indicate offsetting historical moves; it does not establish a reliable future hedge.
Formula, units, and a checkable example
For two assets, portfolio variance is wA² × varianceA + wB² × varianceB + 2 × wA × wB × covariance. Positive long-only weights benefit from a lower covariance term when the other inputs are fixed; a short weight changes that relationship.
Returns A = [0, 1, 2]% and B = [2, 1, 0]% give means of 1%, sample covariance −1 percentage points², standard deviations of 1%, and correlation −1. In decimal-return units the covariance is −0.0001. Do not mix those units in a portfolio formula.
Missing periods must be aligned before entry. No covariance or correlation estimate guarantees future co-movement, and zero correlation does not prove independence. Nearly constant data can be numerically unstable.
Method references: NumPy sample covariance and SciPy Pearson correlation and constant-input limits.
Frequently Asked Questions
What does this stock covariance calculator compute?
It estimates sample covariance, sample standard deviations, and Pearson correlation from two manually entered, aligned return series. It does not retrieve prices or estimate a future return.
What units should I enter?
Enter percentage returns: 2 means 2%. Covariance is in squared percentage points, while standard deviations are percentages. Divide covariance by 10,000 to express it in decimal-return units.
How is sample covariance calculated?
Subtract each series mean, multiply paired deviations, sum them, and divide by n−1. Correlation divides that covariance by the two sample standard deviations; it is undefined if either series is constant.
Does negative covariance guarantee diversification?
No. For fixed positive weights and individual variances, a lower covariance reduces the covariance term in portfolio variance. Actual risk also depends on weights, volatility, and whether historical relationships persist.
Model Risk, Then Build the Strategy
You've measured stock covariance—next, build indicators and strategies that use it. Use Pineify's Pine Script editor and AI to create custom risk and correlation tools on TradingView.