# Covariance

Covariance is a measure of how two variables, such as stock returns, move together relative to their respective averages.

## What it means

When comparing two stocks, covariance helps describe whether their returns have tended to rise and fall together. Positive covariance means above-average returns for one have generally coincided with above-average returns for the other. Negative covariance means above-average returns for one have generally coincided with below-average returns for the other. A value near zero indicates little *linear* co-movement in the observations used.

Covariance is not a probability or a percentage return. Its size depends on the scale and units of the inputs. If both inputs are daily returns expressed as decimals, the result is in squared decimal-return units. Using percentage-point returns instead changes the numerical result by a factor of 10,000. Correlation standardizes covariance, making the strength of linear co-movement easier to compare across pairs.

## How it is calculated

For a sample of observations, use `sample covariance = Σ[(xᵢ − x̄)(yᵢ − ȳ)] / (n − 1)`.

- `xᵢ` and `yᵢ` are the two variables' values in the same observation period, such as the daily returns of stocks X and Y on day `i`.
- `x̄` and `ȳ` are their respective sample-average returns.
- `n` is the number of paired observations; at least two are needed for this sample formula.
- `Σ` means add the products across all `n` observations.

The denominator `n − 1` is conventional when estimating covariance from a sample. If the observations constitute the entire population being described, population covariance instead divides by `n`. State which convention you use when comparing results.

## Worked example

Suppose two hypothetical stocks have paired daily returns over three days. Returns below are in percentage points, not decimal form.

| Day | Stock X | Stock Y |
| --- | ---: | ---: |
| 1 | 1% | 2% |
| 2 | 2% | 1% |
| 3 | 3% | 3% |

1. Find each average: X is `(1 + 2 + 3) / 3 = 2%`; Y is `(2 + 1 + 3) / 3 = 2%`.
2. Subtract the averages. X's deviations are `−1, 0, +1` percentage points; Y's are `0, −1, +1` percentage points.
3. Multiply the paired deviations and add: `(−1 × 0) + (0 × −1) + (1 × 1) = 1` squared percentage point.
4. Divide by `n − 1 = 2`. Sample covariance is `0.5` squared percentage points, or `0.00005` when returns are expressed as decimals.

The positive result reflects co-movement in this tiny hypothetical sample. Three days are not enough to establish a stable relationship or predict future returns.

## Why it matters before you trade

A stock basket's risk depends not just on each holding's volatility, but also on how their returns move together. In a two-stock portfolio, the covariance term in return variance is `2 × wX × wY × Cov(X,Y)`, where `wX` and `wY` are portfolio weights expressed as fractions and `Cov(X,Y)` is return covariance. Positive covariance increases that term; negative covariance reduces it. Other variance terms still matter, and past relationships can change.

Before placing an order, a pre-trade check can use covariance to examine whether an added position changes estimated portfolio risk. This is different from concentration by name, sector or country: stocks in separate sectors can still move together.

## How PreTrAIde uses it

PreTrAIde's product facts do not state that it calculates or displays covariance. Its pre-trade analysis instead includes stock-level volatility estimates, a 1-day 95% value-at-risk calculation, and basket breakdowns and concentration measures. These provide other views of risk but should not be presented as a covariance matrix or a measurement of pairwise return co-movement. PreTrAIde's GO, NO-GO and MODIFY verdicts are decision support, not recommendations.

## Common mistakes

- **Treating covariance as correlation:** Covariance has units and no fixed −1 to +1 range; correlation is unitless and bounded by that range.
- **Mixing return formats:** Decimal returns and percentage-point returns produce differently scaled covariance values.
- **Pairing mismatched dates:** Calculate from returns covering the same periods, with consistent treatment of missing observations.
- **Assuming a negative value guarantees protection:** Historical co-movement can change, including during market stress.
- **Confusing covariance with causation:** Moving together does not establish why two stocks moved.

---
Source: https://pretraide.com/glossary/covariance
