## Covariance Matrix in excel

The covariance matrix is a square matrix to show the covariance among the columns and variance in columns. Excel presented with an inbuilt ‘Data analysis’ tool to determine the covariance between the different data sets. The present article will explain the calculation of the covariance matrix in Excel by covering the following topics, including

### Explanation

Covariance is one of the measures used for understanding how a variable is associated with another variable. The following formula is used for covariance determination.

**COV (X,Y) = ∑(x – x) (y – y) / n**

The covariance matrix is a square matrix to understand the relationships presented between the different variables in a dataset. It is easy and useful to show the covariance between two or more variables.

The covariance will have both positive and negative values. A positive value indicates that two variables will decrease or increase in the same direction. A negative value indicates that if one variable decreases, other variable increases, and an inverse relationship exist between them. The covariance matrix is represented in the following format. The three-dimensional covariance matrix is shown as

To create the 3×3 square covariance matrix, we need to have three-dimensional data. The diagonal values of the matrix represent the variances of X, Y, and Z variables (i.e., COV(X, X), COV(Y, Y), and COV (Z, Z)). The covariance matrix is symmetric with respect to diagonal. This indicates that COV(X,Y)=COV(Y,X), COV(X,Z)=COV(Z,X), and COV(Y,Z)=COV(Z,Y). One point to remember about this matrix is the resulting from the NXN covariance matrix for data of n-dimensional.

### How to Use a Covariance Matrix in Excel?

The covariance matrix is used in various applications, including

- Analyzing how two vectors are differentiating from each other
- Used in machine learning to determine the dependency patterns between the two vectors
- The covariance matrix is used in telling the relationship among the different dimensions of random variables.
- Used in stochastic modeling in financial engineering to correlate the random variables
- The principle component is another application of the covariance matrix to original variables to linear independent variables.
- In data analysis, the covariance matrix has a vital role.
- The covariance matrix is utilized in modern portfolio theory in the estimation of risks.
- The measures of the covariance matrix are used in anticipating the returns on the financial assets.

### Examples of Covariance Matrix in Excel

Given below are some of the examples to use the covariance matrix in excel.

#### Example #1

**Performing covariance analysis on the marks obtained by students in different subjects.**

**Step1:** The following data, including the marks of students in Mathematics, English, and Science, are considered as shown in the figure.

**Step 2:** Go to the “Data” tab on the ribbon and find the ‘Data analysis’ ToolPak on the right side corner.

4.9 (1,353 ratings) 35+ Courses | 120+ Hours | Full Lifetime Access | Certificate of Completion

If “Data analysis” ToolPak not available, then follow these steps.

**Step A:** Go to the ‘File’ tab and then select the “options.”

The following screen will be opened.

**Step B:** Go to Add-ins. Under the Manage Option, ensure that ‘Excel add-ins’ is selected and select the ‘Go’ button, as shown in the figure.

**Step C:** Select the “Analysis-Tool Pak” and “Analysis-ToolPak VBA,” as shown in the screenshot.

After completing these steps, the “Data analysis” tool pack is added to the ‘Data’ tab.

**Step 3:** Click on Data Analysis. This opens the “Data Analysis” dialog box. Select the “Covariance” by scrolling up and click on “OK.”

It displays the “Covariance” dialog box.

**Step 5:** Select the range of input, including the subject names, check the “labels in First Row,” and give the “output range” in the existing worksheet. And click on “OK.”

**Step 6:** We will get the output as follows –

The upper part of the diagonal is empty as the excel covariance matrix is symmetric towards the diagonal.

#### Example #2

** Perform calculation of the covariance matrix to determine variances between the returns of different portfolio stocks.**

**Step 1:** For this example, the following data, including the stock returns, are considered.

**Step 2:** Opens the “Data Analysis” dialog box and select the “Covariance” by scrolling up and click on “OK.”

It displays the “Covariance” dialog box.

**Step 3:** Select the range of input, including the headers, check the “labels in First Row” and give the “output range” in the existing worksheet. And click on “OK.”

**Step 4:** We will get the output as follows –

The upper part of the diagonal is empty as the covariance matrix is symmetric towards the diagonal.

#### Example #3

**Calculation of covariance matrix for stock prices of corporate companies**

**Step 1:** For this example, the following data, including stock prices of different companies, are considered.

**Step 2:** Opens the “Data Analysis” dialog box, select the “Covariance” by scrolling up and click on “OK.”

It displays the “Covariance” dialog box.

**Step 3:** Select the range of input, including the headers, check the “labels in First Row” and give the “output range” in the existing worksheet and click on “OK.”

**Step 4:** We will get the output as follows –

### Things to Remember

- The covariance tool presented by Excel has some limitations, including the determination of only population variances formula, creation of matrix with only lower diagonal values, and consideration of formulae only for a variance.
- When return values are changed, it doesn’t automatically update the values of the matrix.
- The upper half of the matrix is displayed as empty since it is symmetric, and mirror-image values are displayed in the lower diagonal.

### Recommended Articles

This has been a guide to the Covariance matrix in Excel. Here we discuss how to use the covariance matrix in excel along with the examples and downloadable excel sheet. You can learn more about excel from the following articles –

- Convert Function in Excel
- Statistical Functions in Excel
- Correlation vs. Covariance
- Formula of Covariance

- 35+ Courses
- 120+ Hours
- Full Lifetime Access
- Certificate of Completion