Now, let's look at the average risk. Since we want to take the average over only the invested amount, a direct translation of this constraint is
This constraint is not linear, but we can cross multiply, and simplify to get the equivalent linear constraint:
Similarly we need
The final constraint is
Together with nonnegativity, this gives the entire formulation.