# Calculating covariance from three variances

I have been asked to look to refactor some code.

There is a line shown below:

$$\text{implied covariance} = -\frac{(\text{var}_1 - \text{var}_2 - \text{var}_3)} {2}$$,

where $$\text{var}_1$$ is the implied variance of AUDUSD, $$\text{var}_2$$ is the implied variance of USDCAD and $$\text{var}_3$$ is the implied variance AUDCAD

I understand that this is a calculation of covariance between AUDCAD.

However I don't understand the $$\text{var}_1 - \text{var}_2 - \text{var}_3$$ line. I thought the covariance between two variables was the variance of the two variables multiplied together divided by $$n-1$$.

\ \begin{align} \log(S_{AUDCAD})&=\log(S_{AUDUSD})\pm\log(S_{USDCAD})\\ \Rightarrow z&=x\pm y \end{align} Thus,
$$\sigma_z^2=\mathrm{E}\left(\left(x\pm y\right)^2\right)- [\mathrm{E}(x\pm y)]^2 =\sigma_x^2+\sigma_y^2\pm 2\sigma_{xy}$$ Hence, $$\tag{1} \sigma_{xy}=\frac{\sigma_z^2-\sigma_x^2-\sigma_y^2}{\pm 2}$$