An efficient method for valuing credit derivatives based on three entities is developed in an affine framework. This includes interdependence of market and credit risk, joint credit migration and counterparty default risk of three forms. As an application we provide closed form expressions for the joint distribution of default times, default correlations, and default swap spreads in the presence of counterparty default risk