The Clark-Ocone formula and optimal portfolios