Solution (source code)

= Solution

The time-zero budget constraint is
$$
\theta^0+\theta^TS_0=w_0,
$$
so $\theta^0=w_0-\theta^TS_0$. The terminal wealth is therefore
$$
W_1=\overline\theta^T\overline S_1
=(1+r)w_0+\theta^T\bigl(S_1-(1+r)S_0\bigr).
$$
Put
$$
b=\mu-(1+r)S_0,
\qquad
c=w_1-(1+r)w_0.
$$
Then
$$
\mathbb EW_1=(1+r)w_0+\theta^Tb,
\qquad
\operatorname{Var}(W_1)=\theta^TV\theta,
$$
and the target mean is the linear constraint $\theta^Tb=c$.

Since the invertible <covariance matrix> $V$ is positive definite, the <Lagrange multiplier> equation for minimizing $\theta^TV\theta$ is
$$
2V\theta-\eta b=0.
$$
Thus
$$
\theta=\lambda V^{-1}b=\lambda\theta_m,
\qquad
\theta_m=V^{-1}\bigl(\mu-(1+r)S_0\bigr).
$$
The constraint determines
$$
\boxed{
\lambda=\frac{w_1-(1+r)w_0}
{\bigl(\mu-(1+r)S_0\bigr)^TV^{-1}
\bigl(\mu-(1+r)S_0\bigr)}.
}
$$
This is the <one-period Gaussian minimum-variance portfolio>; the riskless holding is then $\theta^0=w_0-\theta^TS_0$.