We construct portfolios from the credit default swap (CDS) market by incorporating cardinality and solvency constraints into mean-variance and conditional value at risk (CVaR) models. Cardinality constraints are applied to limit the portfolio size and improve the allocation structure, while the solvency constraint is used to insulate the default risks of the portfolios under worst scenarios. CDS-based portfolios involve uncertainties that stem from spread changing and jump-to-default volatilities. We show that these uncertainties can be identified and managed using our developed systematic approach. Market data analysis from the CDS portfolios shows that using cardinality constraints reduces counterparty risks significantly. The proposed cardinality constrained CVaR model has robust performance in terms of the portfolio Sharpe ratio and one other metric, and also generally outperforms the associated mean-variance strategy.