Counterparty Risk and CVA › CVA Calculation Implementation

Michael BrenndoerferDecember 23, 20255 min read
Quantitative FinanceAll chapters
Part 10 of 15Risk Management and Financial Risk Controls
Chapter 56Counterparty Risk and CVA › CVA Calculation Implementation
Reading section 6 of 16 · CVA Calculation Implementation · 5 minSection 6 of 16 · 5 min

Book contents

Section 6 of 16 · 5 min read

Counterparty Risk and CVA › CVA Calculation ImplementationOne section · Sections in this chapter6 / 16 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

With exposure profiles computed, we now calculate CVA by combining expected exposures with default probabilities derived from CDS spreads. This implementation brings together the theoretical framework we developed earlier with practical computation.

In[10]:
Code
import numpy as np


def calculate_default_probabilities(cds_spread, recovery_rate, times):
    """
    Calculate marginal default probabilities from CDS spread.
    Uses constant hazard rate assumption.
    """
    lgd = 1 - recovery_rate
    hazard_rate = cds_spread / lgd

    # Survival probabilities
    survival_probs = np.exp(-hazard_rate * times)

    # Marginal default probabilities (probability of default in each period)
    marginal_pds = np.zeros(len(times))
    marginal_pds[0] = 1 - survival_probs[0]
    marginal_pds[1:] = survival_probs[:-1] - survival_probs[1:]

    return marginal_pds, survival_probs


# Counterparty credit parameters
cds_spread = 0.015  # 150 basis points
recovery_rate = 0.40  # 40% recovery
lgd = 1 - recovery_rate

marginal_pds, survival_probs = calculate_default_probabilities(
    cds_spread, recovery_rate, times
)

The hazard rate extracted from the CDS spread reflects the market's assessment of the counterparty's creditworthiness. A 150 basis point CDS spread for a counterparty with 40% recovery implies a hazard rate of approximately 2.5% per year. This hazard rate means that, conditional on surviving to any given moment, there is roughly a 2.5% annual probability of defaulting in the next year. The exponential survival function then translates this instantaneous rate into cumulative survival and default probabilities at each future date.

Out[11]:
Visualization
Bar chart of quarterly marginal default probabilities declining over time, with a secondary axis overlaying the rising cumulative default probability curve.
Marginal default probabilities by time period derived from a 150bp CDS spread. The marginal probability represents the chance of default in each specific interval, conditional on surviving to the start of that interval. Earlier periods have higher marginal probabilities because survival probability is higher.
In[12]:
Code
import numpy as np


def calculate_discount_factors(r0, times):
    """Calculate discount factors using initial rate."""
    return np.exp(-r0 * times)


def calculate_cva(expected_exposure, marginal_pds, discount_factors, lgd):
    """
    Calculate CVA as discounted expected loss.

    CVA = LGD * sum(DF * EE * marginal_PD)
    """
    # Align dimensions - use midpoint exposures for each period
    n_periods = len(marginal_pds) - 1
    cva = 0.0

    for i in range(1, len(marginal_pds)):
        # Average exposure in period
        avg_ee = 0.5 * (expected_exposure[i - 1] + expected_exposure[i])
        # Discount to present
        df = discount_factors[i]
        # Add contribution
        cva += lgd * df * avg_ee * marginal_pds[i]

    return cva


discount_factors = calculate_discount_factors(r0, times)
cva = calculate_cva(expected_exposure, marginal_pds, discount_factors, lgd)
Out[13]:
Console
CVA Calculation Results
========================================
Notional:              $1,000,000
CDS Spread:            150 bps
Recovery Rate:         40%
Loss Given Default:    60%

Peak Expected Exposure: $48,277
Peak PFE (99%):         $248,235

CVA:                   $3,547
CVA as % of Notional:  0.3547%

The CVA of approximately 0.25% of notional represents the upfront price of counterparty credit risk for this swap. This amount should be charged to the counterparty or reserved against potential losses. For our portfolio of derivatives, CVA can become a substantial adjustment to firm-wide valuations. A large dealer with hundreds of billions of dollars in derivative notional can have aggregate CVA in the billions, making it a material component of the firm's balance sheet.

Out[14]:
Visualization
Bar chart of quarterly CVA contributions peaking in mid-life and declining toward maturity, with a secondary axis showing the cumulative CVA rising to the total.
CVA contribution by time period showing how each interval contributes to total CVA. The contribution depends on the product of expected exposure, marginal default probability, and discount factor. The hump shape reflects the exposure profile, while the declining contribution in later years reflects both lower marginal PD (due to declining survival probability) and higher discounting.