Functional Constrained Optimization for Risk Aversion and Sparsity Control