Solution of stochastic optimal control problems and financial applications