An optimization model for minimizing systemic risk