This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 Modeling Correlated Defaults with Copulas.

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)
  creditDefaultCopula with properties:

            Portfolio: [100×5 table]
    FactorCorrelation: [2×2 double]
             VaRLevel: 0.9500
          UseParallel: 0
      PortfolioLosses: []
disp(cdc.Portfolio(1:10:100,:))
    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: [100×5 table]
    FactorCorrelation: [2×2 double]
             VaRLevel: 0.9900
          UseParallel: 0
      PortfolioLosses: [1×100000 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=1×4 table
      EL       Std       VaR      CVaR 
    ______    ______    _____    ______

    24.898    23.853    103.3    121.86

RiskConfidenceInterval=1×4 table
          EL                 Std                 VaR                 CVaR      
    _______________    ________________    ________________    ________________

    24.75    25.046    23.749    23.958    102.21    104.25    120.75    122.98

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.036712      0.025238     0.043102       0.10597
     2     0.068893      0.037862      0.17972       0.24984
     3       1.2433       0.61879       2.6182        2.4785
     4    0.0029164    0.00073255    0.0074805     0.0078822
     5      0.12057      0.036235      0.21657       0.20618
     6      0.12617      0.079902      0.46466        0.5503
     7      0.83276       0.35637       1.5099        1.7955
     8    0.0009098    0.00016638            0    0.00089197
     9      0.92994       0.88569       3.5413        4.6875
    10      0.25504       0.37783       2.0377        1.9638

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: [100×5 table]
    FactorCorrelation: [2×2 double]
             VaRLevel: 0.9900
          UseParallel: 0
      PortfolioLosses: [1×100000 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) 
ans=10×4 table
    NumScenarios    Lower      Std      Upper 
    ____________    ______    ______    ______

       10000        23.485    23.758    24.037
       20000        23.518    23.711    23.908
       30000        23.673    23.832    23.993
       40000        23.735    23.873    24.013
       50000        23.724    23.847    23.972
       60000        23.699    23.812    23.926
       70000        23.688    23.792    23.898
       80000         23.75    23.848    23.946
       90000        23.718     23.81    23.902
       1e+05        23.766    23.853    23.942

confidenceBands(cdct,'RiskMeasure','Std','ConfidenceIntervalLevel',0.90,'NumPoints',10)
ans=10×4 table
    NumScenarios    Lower      Std      Upper 
    ____________    ______    ______    ______

       10000        31.547    31.914     32.29
       20000        31.556    31.816     32.08
       30000        31.737     31.95    32.166
       40000        31.646     31.83    32.017
       50000        31.591    31.755    31.922
       60000        31.572    31.721    31.873
       70000        31.686    31.825    31.965
       80000         31.78    31.911    32.043
       90000        31.779    31.902    32.026
       1e+05         31.84    31.957    32.075