This paper provides a general framework for doubly stochastic term structure models for portfolio of credits, such as collateralized debt obligations (CDOs). We introduce the defaultable (T, x)-bonds, which pay one if the aggregated loss process in the underlying pool of the CDO has not exceeded x at maturity T, and zero else. Necessary and sufficient conditions on the stochastic term structure movements for the absence of arbitrage are given. Moreover, we show that any exogenous specification of the forward rates and spreads volatility curve actually yields a consistent loss process and thus an arbitrage-free family of (T, x)-bond prices. For the sake of analytical and computational efficiency we then develop a tractable class of affine term structure models.