MATLAB Examples

creditDefaultCopula Simulation Workflow

This example shows a common workflow for using a creditDefaultCopula object for a portfolio of credit instruments.

For an example of an advanced workflow using the creditDefaultCopula object, see docid:risk_ug.bvf6d93-1.

Contents

Step 1. Create a creditDefaultCopula object with a two-factor model.

Load the saved portfolio data. Create a creditdefaultCopula object with a two-factor model using with the values EAD, PD, LGD, and Weights2F.

load CreditPortfolioData.mat;
cdc = creditDefaultCopula(EAD, PD, LGD,Weights2F,'FactorCorrelation',FactorCorr2F);
disp(cdc)
disp(cdc.Portfolio(1:10:100,:))
  creditDefaultCopula with properties:

            Portfolio: [100x5 table]
    FactorCorrelation: [2x2 double]
             VaRLevel: 0.9500
      PortfolioLosses: []

    ID     EAD          PD        LGD              Weights          
    __    ______    __________    ____    __________________________

     1    21.627     0.0050092    0.35      0.35         0      0.65
    11    29.338     0.0050092    0.55      0.35         0      0.65
    21    3.8275     0.0020125    0.25    0.1125    0.3375      0.55
    31    26.286     0.0020125    0.55    0.1125    0.0375      0.85
    41    42.868     0.0050092    0.55      0.25         0      0.75
    51    7.1259    0.00099791    0.25         0      0.25      0.75
    61    10.678     0.0020125    0.35         0      0.15      0.85
    71     2.395    0.00099791    0.55         0      0.15      0.85
    81    26.445      0.060185    0.55         0      0.45      0.55
    91    7.1637       0.11015    0.25      0.35         0      0.65

Step 2. Set the VaRLevel to 99%.

Set the VarLevel property for the creditDefaultCopula object to 99% (the default is 95%).

cdc.VaRLevel = 0.99;

Step 3. Run a simulation.

Use the simulate function to run a simulation on the creditDefaultCopula object for 100,000 scenarios.

 cdc = simulate(cdc,1e5)
cdc = 

  creditDefaultCopula with properties:

            Portfolio: [100x5 table]
    FactorCorrelation: [2x2 double]
             VaRLevel: 0.9900
      PortfolioLosses: [1x100000 double]

Step 4. Generate a report for the portfolio risk.

Use the portfolioRisk function to obtain a report for risk measures and confidence intervals for EL, Std, VaR, and CVaR.

[portRisk,RiskConfidenceInterval] = portfolioRisk(cdc)
portRisk =

  1x4 table

      EL       Std       VaR       CVaR 
    ______    ______    ______    ______

    24.774    23.693    101.57    120.22


RiskConfidenceInterval =

  1x4 table

           EL                 Std                 VaR                CVaR      
    ________________    ________________    ________________    _______________

    24.627     24.92    23.589    23.797    100.65    102.82    119.1    121.35

Step 5. Visualize the distribution.

Use the histogram function to display the distribution for EL, VaR, and CVaR.

histogram(cdc.PortfolioLosses);
title('Distribution of Portfolio Losses');

Step 6. Generate a risk contributions report.

Use the riskContribution function to display the risk contribution. The risk contributions, EL and CVaR, are additive. If you sum each of these two metrics over all the counterparties, you get the values reported for the entire portfolio in the portfolioRisk table.

rc = riskContribution(cdc);

disp(rc(1:10,:))
    ID        EL           Std          VaR          CVaR   
    __    __________    __________    ________    __________

     1      0.038604       0.02495     0.10482       0.12868
     2      0.067068      0.036472     0.17378       0.24527
     3        1.2527       0.62684      2.0384        2.3103
     4     0.0023253    0.00073407           0     0.0026274
     5       0.11766      0.042185     0.27028       0.26223
     6       0.12437       0.07545     0.37669       0.47915
     7       0.82913        0.3475         1.6        1.6516
     8    0.00085629    4.3929e-05    0.001544    0.00089197
     9       0.91406       0.87311        3.55         4.009
    10       0.24352       0.36543      1.5864        2.2781

Step 7. Simulate the risk exposure with a t copula.

Use the simulate function with optional input arguments for Copula and t. Save the results to a new creditDefaultCopula object (cct).

cdct = simulate(cdc,1e5,'Copula','t','DegreesOfFreedom',10)
cdct = 

  creditDefaultCopula with properties:

            Portfolio: [100x5 table]
    FactorCorrelation: [2x2 double]
             VaRLevel: 0.9900
      PortfolioLosses: [1x100000 double]

Step 8. Compare confidence bands for different copulas.

Use the confidenceBands function to compare confidence bands for the two different copulas.

confidenceBands(cdc,'RiskMeasure','Std','ConfidenceIntervalLevel',0.90,'NumPoints',10)
confidenceBands(cdct,'RiskMeasure','Std','ConfidenceIntervalLevel',0.90,'NumPoints',10)
ans =

  10x4 table

    NumScenarios    Lower      Std      Upper 
    ____________    ______    ______    ______

       10000        23.467    23.739    24.019
       20000        23.781    23.977    24.176
       30000        23.589    23.747    23.908
       40000        23.484     23.62    23.758
       50000        23.486    23.608    23.732
       60000        23.521    23.632    23.745
       70000        23.558    23.662    23.767
       80000        23.575    23.672    23.769
       90000        23.602    23.693    23.785
       1e+05        23.606    23.693     23.78


ans =

  10x4 table

    NumScenarios    Lower      Std      Upper 
    ____________    ______    ______    ______

       10000        32.578    32.957    33.345
       20000        32.428    32.694    32.966
       30000        32.505    32.723    32.945
       40000        32.131    32.318    32.507
       50000        32.018    32.185    32.353
       60000        31.875    32.026    32.179
       70000        31.984    32.124    32.266
       80000        32.006    32.137     32.27
       90000        31.939    32.063    32.188
       1e+05        31.903     32.02    32.138