Suppose you wish to invest a fixed sum of money in to assets that yield returns of $X$ and $Y$, where $X$, and $Y$ are random quantities. You will invest a fraction $a$ in $X$ and the remaining in $Y$. Because there is variability associated with the returns on these two assets we wish to choose $a$ such that the total risk or variance is minimized. We want to minimize $\mathbb{Var}(aX+(1-a)Y)$.
Find $a$ such that the risk is minimized.
Here's what I have gotten till so far: $$ a^2 \mathbb{Var}[X]+(1-a)^2 \mathbb{Var}[Y]+a(1-a)\mathbb{E}{[X-\mathbb{E}(X)][Y-\mathbb{E}(Y)]} $$
What's the next step for finding the minimum variance? Which terms should be expanded and how can they be rearranged together?
The variance is $$\text{Var}(aX+(1-a)Y) = a^2 \text{Var}(X) + (1-a)^2 \text{Var}(Y) + 2a(1-a) \text{Cov}(X,Y).$$ This is a quadratic of the form $$c_2 a^2 + c_1 a + c_0$$ with \begin{align} c_2 &= \text{Var}(X) + \text{Var}(Y) - 2 \text{Cov}(X,Y) \\ c_1 &= -2 \text{Var}(Y) + 2\text{Cov}(X,Y) \\ c_0 &= \text{Var}(Y) \end{align}
If $c_2 < 0$, then this is a $\cap$-shaped quadratic, which will be minimized either at $a=0$ or $a=1$, depending on which of $\text{Var}(X)$ or $\text{Var}(Y)$ is smaller.
If $c_2 = 0$, then this is a line, will be minimized either at $a=0$ or $a=1$.
If $c_2 > 0$, then this is a $\cup$-shaped quadratic, which is minimized at $-\frac{c_1}{2c_2} = \frac{\text{Var}(Y) - \text{Cov}(X,Y)}{\text{Var}(X) + \text{Var}(Y) - 2 \text{Cov}(X,Y)}$ if this quantity is between $0$ and $1$; otherwise it is again minimized either at $a=0$ or $a=1$.