# Variance of returns on a portfolio

This must be very basic, but I don't seem to be able to express the variance of returns on a portfolio in terms of variances-covariance sum of returns of its constituents, which seems to be what is used everywhere. Say $Y(t)=\sum{n_i X_i(t)}$ where $n_i$ is the number of shares of stock $i$ with price $X_i$. Define a relative return on $i$-th constituent over a period $T$ as

$$r_i(t,t+T) = \frac{X_i(t+T)-X_i(t)}{X_i(t)}$$

Then the relative return on the portfolio is

$$R_T = R(t,t+T) = \frac{Y(t+T)-Y(t)}{Y(t)} = \frac{1}{Y(t)}\sum{n_i X_i(t) r_i(t,t+T)}$$

Then

$$Var(R_T) = Var \left( \frac{1}{Y(t)}\sum{n_i X_i(t) r_i(t,t+T)} \right)$$

This is often expressed as

$$\sum w_iw_jCov(r_i,r_j)$$

but since both $X(t)$ and $Y(t)$ also vary with time I don't see how this is done.

# To estimate covariance between returns of security $i$ and $j$ using a sample from time $t=1$ to $T$:

### Step 1: Compute returns for every security $i$ and every period $t$

The return from time $t$ to $t+1$ for security $i$ is given by:

$$R_{i,t+1} = \frac{P_{t+1} + D_{t+1}}{P_t}$$

where $P_t$ denotes the price at time $t$ and $D_t$ is the time $t$ value of any distributions (eg. dividends, stock distributions, etc...).

Typically data providers will do this for you. Getting everything perfectly correct (eg. delisting returns, distributions etc...) is hugely important.

### Step 2: Compute sample mean of returns

For security $i$, the sample mean is given by:

$$\bar{r}_i = \frac{1}{T} \sum_t r_{i,t}$$

### Step 3: Compute sample covariance of returns:

For security $i$ and $j$, the sample covariance is given by:

$$\hat{Cov}(r_i, r_j) = \frac{1}{T-1} \sum_t \left(r_{i,t} - \bar{r}_i \right) \left( r_{j,t} - \bar{r}_j \right)$$

### A note on share counts and weights:

Holding a constant number of shares implies portfolio weights almost certainly vary period to period.

Let $P_{i,t}$ be the price of security $i$ and $n_i$ be the number of shares of security $i$. The portfolio weight on security $i$ at time $t$ is given by:

$$w_{i,t} = \frac{n_i P_{i,t}}{\sum_j n_j P_{j,t}}$$

Since the prices almost certainly change, the portfolio weights almost certainly change. (An exception is if the portfolio is value weighted, in which case the weights will basically remain the same.)