An investor has the choice to put his money in a savings account ($S$) with a return of $\mu_S=1.03$. Since the bank guarantees this return the investment is risk-free, hence $\sigma_S = 0$. Furthermore, the investor has the possibility to invest in a stock $A_1$ with an expected return of $\mu_{A_1}=1.04$ and a risk of $\sigma_{A_1}=0.1$ and a stock $A_2$ with an expected return $\mu_{A_2} = 1.05$ and a risk of $\sigma_{A_2} =0.2$. We summarize this information: $(\mu_S,\sigma_S)=(1.03; 0)$, $(\mu_{A_1}, \sigma_{A_1})=(1.04; 0.1)$ and $(\mu_{A_2}, \sigma_{A_2})=(1.05; 0.2)$. The utility function of the investor is given by $U(\mu,\sigma)=\mu-2\sigma^2, \ (\sigma \geq 0)$. The investor puts a fraction $w_1$ in the savings account, invests a fraction $w_2$  in stock $A_1$ and a fraction $w_3$ in stock $A_2$. Since we assume he invests the full amount available for investment, we obtain the following restriction for the fractions $w_1$, $w_2$ and $w_3$: $w_1+w_2 +w_3= 1$ and $w_1 \geq 0, \ w_2 \geq 0, \ w_3 \geq 0.$ By the use of several statistical formulas (that are outside the scope of this book) the expected return and risk of this portfolio $P=w_1S + w_2A_1 + w_3A_3$ can be calculated. Here we provide the result of this calculation: (In these formulas it is also used that the covariance between $A_1$ and $A_2$ is equal to 0.00375.)

$$
\begin{array}{lll}
\mu&=& 1.03w_1 + 1.04w_2 + 1.05w_3,\\
\sigma &=& \sqrt{0.01w_2^2 + 0.04w_3^2 +0.0075w_2w_3}.
\end{array}
$$

We find the optimal portfolio for this investor. We plug this information into the utility function $U(\mu,\sigma)=\mu - 2 \sigma^2$ such that we obtain a new utility function that depends on the fractions $w_1$, $w_2$ and $w_3$:

$$
\begin{array}{lll}
U(w_1,w_2,w_3) &=& 1.03w_1 + 1.04w_2 + 1.05w_3-2 (0.01w^2_2 + 0.04w^2_3+0.0075w_2w_3) \\
           &=& 1.03w_1 + 1.04w_2 +1.05w_3 -0.02w_2^2 -0.08w_3^2 - 0.015w_2w_3.
\end{array}
$$
Since the fractions satisfy the restrictions $w_1+w_2+w_3=1$ and $w_1 \geq 0$, $w_2 \geq 0$, $w_3 \geq 0$, the investor has to deal with the following constrained maximization problem:

$$\begin{array}{lll}
\mbox{maximize}&U(w_1,w_2,w_3) = 1.03w_1 + 1.04w_2 +1.05w_3 -0.02w_2^2 -0.08w_3^2 -0.015w_2w_3&\\
\mbox{subject to}&w_1 + w_2 +w_3=1,&\\
\mbox{where} &  w_1 \geq 0, w_2 \geq 0 \ \mbox{and} \ w_3 \geq 0.
\end{array}
$$
We solve this constrained maximization problem by the use of the substitution method.

Step 1. We rewrite the restriction to $w_1 = 1- w_2 -  w_3$.

Step 2. We substitute the equation of Step~1 into the utility function:

$$\begin{array}{lll}
u(w_2,w_3) &=& U(1-w_2-w_3,w_2,w_3) \\
&=& 1.03(1-w_2-w_3) + 1.04w_2 +1.05_3-0.02w_2^2 -0.08w_3^2 -0.015w_2w_3 \\
&=& 1.03 +0.01 w_2 +0.02w_3 -0.02w_2^2 -0.08w_3^2 -0.015w_2w_3,
\end{array}
$$
where $(0 \leq w_2 \leq 1, 0 \leq w_3 \leq 1).$

Step 3. We determine the maximum location of $u(w_2,w_3)$.
Contrary to Example 1 and Example 2 $u$ is a function of two variables. Hence, we use a solution method for unconstrained extremum problems of two variables. Since the partial derivatives of $u(w_2,w_3)$ equal $u'_{w_2}(w_2,w_3) = 0.01 -0.04w_2 - 0.015w_3$ and $u'_{w_3}(w_2,w_3)=0.02 - 0.16w_3 - 0.015w_2 $ the stationary point is the solution of the system:

$$
\begin{array}{lll}
0.01 -0.04w_2 - 0.015w_3&=&0\\
0.02 - 0.16w_3 - 0.015w_2&=&0
\end{array}
$$
From the first equation it follows that $w_2=\frac{1}{4}-\frac{3}{8}w_3$. We plug this into the second equation: $0.02-0.16w_3-0.015(\frac{1}{4}-\frac{3}{8}w_3)=0$, which gives $w_3=\frac{2}{19}$. Therefore, $w_2=\frac{1}{4}-\frac{3}{8}\cdot \frac{2}{19}=\frac{4}{19}$.

We have to verify whether $(w_2,w_3)=(\frac{4}{19},\frac{2}{19})$ is indeed a maximum location. Since $u''_{w_2w_2}(w_2,w_3)=-0.04$, $u''_{w_3w_3}(w_2,w_3)=-0.16$ and $u''_{w_2w_3}(w_2,w_3)=-0.015$ we may conclude that $C(w_2,w_3)=(-0.04 \cdot -0.16) - (-0.015)^2 =0.06175$. Hence, $(w_2,w_3)=(\frac{4}{19},\frac{2}{19})$ is a maximum location, because $C(\frac{4}{19},\frac{2}{19})>0$ and $u''_{w_2w_2}(\frac{4}{19},\frac{2}{19})=-0.04<0$.

Step 4. We determine the maximum (location) of $U(w_1,w_2,w_3)$.
By plugging $w_2=\frac{4}{19}$ and $w_3=\frac{2}{19}$ into $w_1=1-w_2-w_3$ it follows  that $w_1=\frac{13}{19}$ such that $(w_1,w_2,w_3)=(\frac{13}{19},\frac{4}{19}, \frac{2}{19})$  is a maximum location for this utility maximization problem of this investor.