Optimal trading with frictions