The criterion is inspired by the Chicago Mercantile Exchange's riskbased margining system, which sets the collateralization requirements on margin accounts. The margin criterion computes the losses expected at the portfolio level, using expected stock price and volatility variations, and is itself an optimization problem. Our contribution is to remodel the criterion as a quadratic programming subproblem of the main portfolio optimization problem, using option Greeks. We also extend the margin subproblem to a continuous domain. The quadratic programming problems thus designed can be solved numerically or in closed form with high efficiency, greatly facilitating the main portfolio selection problem. We present two extended practical examples of the application of our approach to obtain optimal portfolios with options. These examples include a study of liquidity effects (bid-ask spreads and limited order sizes) and sensitivity to changing market conditions. Our analysis shows that the approach advocated here is more stable and more efficient than discrete approaches to portfolio selection.