# How to Calculate Covariance

By AJ Smith · March 29, 2022 · 6 minute read

We’re here to help! First and foremost, SoFi Learn strives to be a beneficial resource to you as you navigate your financial journey. Read more We develop content that covers a variety of financial topics. Sometimes, that content may include information about products, features, or services that SoFi does not provide. We aim to break down complicated concepts, loop you in on the latest trends, and keep you up-to-date on the stuff you can use to help get your money right. Read less

Covariance is a measure of how two variables — such as the price of two securities — move together (positive covariance) or move in opposite directions (negative covariance). It’s calculated using a specific formula that captures the degree to which the mean of the two variables move in tandem.

Calculating covariance is important in finance because it’s one way to help insure that a portfolio is well-diversified. The concept, which comes from statistics, is one of the key tenets of modern portfolio theory: that risk can be reduced by investing in a variety of assets, particularly those with a negative covariance.

Effective diversification involves not just making qualitative judgments about different assets but understanding their statistical relationship to each other. For optimal diversification in their own portfolios, investors need to understand covariance.

## What Is Covariance?

Covariance is very much as it sounds: variations in the average price of two securities, considered in relation to each other. In other words, if Stock X moves higher whenever Stock Y moves higher, and the same pattern occurs when each stock’s return decreases, then the two securities have a positive covariance. Negative covariance is when the mean values move inversely to one another.

Thus covariance is a measure of how two securities tend to move together or not, not a measure of the direction in which they move.

By considering the covariance of securities in a portfolio, investors may be able to enhance their portfolio’s diversification. It’s a way of handling investment risks.

Another way investors can gauge risk in their holdings is learning how to find portfolio beta, or the sensitivity to price swings in the broader market.

### Can Covariance Be Negative?

When the variables move together, the covariance is positive (i.e., they move above or below their respective averages together). But when they move in opposite directions, the covariance is negative.

When you pair assets that have a negative covariance, volatility and therefore risk may be reduced in the portfolio.

### Difference Between Covariance and Correlation

Covariance may sound similar to the concept of correlation. The two are related but they’re not identical. The correlation coefficient measures the strength of a correlative relationship between two stocks, for example.

## Covariance Formula

Covariance has a formula:

Cov (X,Y) = [SUM(x-xa) (y-ya)] / (n-1)

In the formula:

•   x is the value of the x variable. y is the value of the y variable.

•   xa is the average of the x variable, while ya is the average of the y variable.

•   n is the number of data points.

## Example of Calculating Covariance

For this example we will use the hypothetical performance of two stocks, AAA Corp and BBB Corp. Below are AAA Corp’s returns over five years.

2017: -15%

2018: -7%

2019: 25%

2020: 40%

2021: 50%

Average five-year returns = 18.6%

Here are BBB Corps returns.

2015: 5%

2016: 9%

2017: 11%

2018: 8%

2019: 12%

Average returns = 9

For each stock, we subtract the average return from the return of a given year and then multiply the two results together, and add them up for every year.

[(-15-18.6) x (5-9)] + [(-7-18.6) x (9-9)] + [(25-18.6) x (11-9)] + [(40-18.6) x (8-9)] + [(50-18.6) x (12-9)] / (5-1)

## Interpreting Covariance Results

After doing the math (or running it through Excel), the covariance of these two stocks is 55. That it’s positive means the stocks tend to move in the same direction at the same time. When you look at the two sets of returns, there are years where AAA has a negative return, and then a high positive return, whereas BBB has steady positive returns in the five-year sample.

So you can see that covariance isn’t a measure of returns, but how returns vary relative to their mean. In the two years BBB had above average returns, AAA had very high and above average returns. For there to be negative covariance, the below and above average years would have to be not paired at all.

While these examples are not necessarily reflective of a real-world comparison between two assets in a portfolio, it shows how covariance can work and how to think about it when managing your portfolio.

## Covariance Comparisons

In order to make use of covariance, it’s important for investors to distinguish between some common statistical measures.

### Covariance vs Correlation

While correlation is another metric used to measure the relationship between two variables, covariance measures the direction of that relationship whereas correlation measures its strength. It is often expressed via a correlation coefficient, which ranges from -1 to +1.

The correlation between two variables is considered strong if the correlation coefficient is close to +1 (positive) or -1 (negative)

A correlation is considered to be strong if the correlation coefficient has a value that is close to +1 (positive correlation) or -1 (negative correlation). When the coefficient is close to zero, there is only a weak relationship between the two variables.

### Covariance vs Variance

Both variance and covariance measure how data points are distributed around a calculated mean. However, variance is often used in data sets with only one variable, to gauge how closely data points group around the average, while covariance examines the directional relationship between two variables.

In finance, covariance is used to gauge whether that relationship is positive or negative covariance. Negative covariance is considered more desirable when trying to diversify the holdings in a portfolio.

## How Investors Can Use Covariance

For an investor, the covariance formula is used when you want to determine the relationship between two financial assets.

For example, investors and portfolio managers can look at the returns of different securities in order to gauge their covariance. Let’s say you own stock in AAA Corp from the example above. When considering whether to buy BBB Corp, or another other stock, you can use covariance to determine the relationship between the new stock’s returns over time and the ones of a given stock in our portfolio.

## The Takeaway

Covariance is a way of measuring whether the mean performance of two securities moves together, or inversely to each other. While covariance is similar to correlation, which measures the strength of the relationship between two variables (or in finance, two securities), covariance simply captures the direction: Are the two variables moving in tandem or not?

This statistical measure can be useful for creating a well-diversified portfolio, since securities with a negative covariance can help manage the impact of volatility on portfolio returns.

Ready to start building your own portfolio? It’s easy when you open an Active Invest account with the SoFi Invest® online brokerage. You can start trading stocks, ETFs, even crypto. SoFi doesn’t charge any commission, and SoFi members have access to advice from professionals, who can answer investment questions.

Check out SoFi Invest today.

SoFi Invest®
The information provided is not meant to provide investment or financial advice. Also, past performance is no guarantee of future results.
Investment decisions should be based on an individual’s specific financial needs, goals, and risk profile. SoFi can’t guarantee future financial performance. Advisory services offered through SoFi Wealth, LLC. SoFi Securities, LLC, member FINRA / SIPC . SoFi Invest refers to the three investment and trading platforms operated by Social Finance, Inc. and its affiliates (described below). Individual customer accounts may be subject to the terms applicable to one or more of the platforms below.
1) Automated Investing—The Automated Investing platform is owned by SoFi Wealth LLC, an SEC registered investment advisor (“Sofi Wealth“). Brokerage services are provided to SoFi Wealth LLC by SoFi Securities LLC, an affiliated SEC registered broker dealer and member FINRA/SIPC, (“Sofi Securities).
2) Active Investing—The Active Investing platform is owned by SoFi Securities LLC. Clearing and custody of all securities are provided by APEX Clearing Corporation.
3) Cryptocurrency is offered by SoFi Digital Assets, LLC, a FinCEN registered Money Service Business.
For additional disclosures related to the SoFi Invest platforms described above, including state licensure of Sofi Digital Assets, LLC, please visit www.sofi.com/legal. Neither the Investment Advisor Representatives of SoFi Wealth, nor the Registered Representatives of SoFi Securities are compensated for the sale of any product or service sold through any SoFi Invest platform. Information related to lending products contained herein should not be construed as an offer or prequalification for any loan product offered by SoFi Bank, N.A.
SOIN20304

## All your finances. All in one app.

### All your finances. All in one app.

App Store rating

TLS 1.2 Encrypted
Equal Housing Lender