How do we get the variance for five or more assets (actions)?

For a finance project I have to compute my portfolio's variance.

I know that for two asset(actions) it is :

But what is the variance for five or more assets (actions) ? Is it :

$$\operatorname {var}\left(\sum _{{i=1}}^{n}{a_{i}\,X_{i}}\right)=\sum _{{i=1}}^{n}a_{i}^{2}\,\operatorname {var}(X_{i})+2\sum _{{1\leq i<j\leq n}}\,a_{i}a_{j}\,\operatorname {cov}(X_{i},X_{j})$$

With $X_i\in \{assets\}$ and $a_i\in[0,1]$ the $x_i$ assets'weight?

If it is, then how do we get to the first equation $\sigma_p^2$ for two actions ?

• $\text{Cov}(X,Y)=\rho_{XY}\sigma_X\sigma_Y.$ Is that enough of a clarification? – Richard Hardy Mar 8 '17 at 18:12