Clean implementation of Value at Risk optimization