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: [30.1008 3.6910 3.2895 19.2151 7.5761 44.5088 19.5419 1.7909 72.1443 12.6933 36.0228 1.7909 4.8512 23.0230 54.0877 35.9298 35.3757 26.1678 36.8868 24.6242 2.9770 15.3030 0 0 10.5546 61.2268 32.5802 42.5504 … ] (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.876 23.778 102.4 121.28
RiskConfidenceInterval=1×4 table
EL Std VaR CVaR
________________ ________________ ________________ ________________
24.729 25.023 23.674 23.883 101.19 103.5 120.13 122.42
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.036031 0.022762 0.083828 0.13625
2 0.068357 0.039295 0.23373 0.24984
3 1.2228 0.60699 2.3184 2.3775
4 0.002877 0.00079014 0.0024248 0.0013137
5 0.12127 0.037144 0.18474 0.24622
6 0.12638 0.078506 0.39779 0.48334
7 0.84284 0.3541 1.6221 1.8183
8 0.00090088 0.00011379 0.0016463 0.00089197
9 0.93117 0.87638 3.3868 3.9936
10 0.26054 0.37918 1.7399 2.3042
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: [3.6910 1.9775 128.4550 2.1852 4.8512 0 26.2682 0 54.8980 24.3618 16.8483 1.9775 26.5877 40.3189 13.0581 26.2682 2.0924 15.4193 25.1406 32.6275 34.6938 1.4985 24.0275 4.8512 228.3562 4.1248 1.4985 34.6339 … ] (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.525 23.799 24.079
20000 23.564 23.758 23.955
30000 23.543 23.701 23.861
40000 23.621 23.758 23.897
50000 23.565 23.687 23.811
60000 23.604 23.716 23.829
70000 23.688 23.792 23.897
80000 23.663 23.76 23.858
90000 23.639 23.73 23.823
1e+05 23.691 23.778 23.866
confidenceBands(cdct,'RiskMeasure','Std','ConfidenceIntervalLevel',0.90,'NumPoints',10)
ans=10×4 table
NumScenarios Lower Std Upper
____________ ______ ______ ______
10000 31.923 32.294 32.675
20000 31.775 32.036 32.302
30000 31.759 31.972 32.188
40000 31.922 32.107 32.295
50000 32.012 32.179 32.347
60000 31.911 32.062 32.216
70000 31.879 32.019 32.161
80000 31.909 32.04 32.173
90000 31.866 31.99 32.114
1e+05 31.933 32.05 32.169
See Also
creditDefaultCopula | simulate | portfolioRisk | riskContribution | confidenceBands | getScenarios | asrf