Optimization of risk processes