Solution (source code)

= Solution

The no-borrowing <portfolio> constraint is $0\le x\le T$. Net <asset returns> must be added to the original principal. Thus the two final <portfolio wealths> are
$$
\boxed{w_g=x(1+r)+(T-x)(1+g)=T(1+g)-(g-r)x,\qquad w_b=x(1+r)+(T-x)(1+b)=T(1+b)+(r-b)x.}
$$
The <expected utility> is
$$
\boxed{U(x)=p\,u(w_g)+(1-p)u(w_b).}
$$
The probabilities are those of the investor's beliefs; no <risk-neutral measure> is being used in this preference calculation.