The Merton problem is solved with two variants, sufficient conditions are presented for the optimum portfolio of an agent with a piecewise utility function, which depend on a wealth value and is associated with its risk aversion , we use the martingale method and convex duality.