Stochastic Optimization in Insurance:A Dynamic Programming Approach