Two-state logarithmic portfolio with a borrowing constraint (source code)

= Two-state logarithmic portfolio with a borrowing constraint
{title2=$x_*=\max\{0,T[(1-p)(1+g)/(g-r)-p(1+b)/(r-b)]\}$}

Let a <portfolio> hold $x\in[0,T]$ in a <risk-free asset> with net return $r$ and $T-x$ in an asset returning $g$ or $b$, with probabilities $p$ and $1-p$. Assume $T>0$, $-1<b<r<g$, $0<p<1$, and $pg+(1-p)b>r$. Its state wealths are $w_g=T(1+g)-(g-r)x$ and $w_b=T(1+b)+(r-b)x$. The <expected utility> $p\log w_g+(1-p)\log w_b$ has strictly negative second <derivative>. Setting its first <derivative> to zero gives the displayed unconstrained root; the <derivative> at $x=T$ is negative, so only the lower constraint can bind. Thus the displayed formula is the unique optimum. All equity is optimal exactly when $p\ge (r-b)(1+g)/[(g-b)(1+r)]$. The positivity of both state wealths is part of the <logarithmic utility> domain.