Solution (source code)

= Solution

Normalize $Y_0=1/X_0$. Solving its stochastic differential equation gives
$$
\log Y_T
=-\log X_0-\left(r+\frac{\lambda^2}{2}\right)T-\lambda W_T.
$$
For logarithmic utility, $\widehat U(y)=-\log y-1$. Part c and $\mathbb EW_T=0$ therefore give
$$
\mathbb E\log X_T
\leq\log X_0+\left(r+\frac{\lambda^2}{2}\right)T.
$$
If $\pi_t=X_t\lambda/(S_t\sigma)$, part d gives $d(XY)=0$. Hence $X_tY_t=X_0Y_0=1$, so $U'(X_T)=1/X_T=Y_T$ and both inequalities in part c are equalities.