This example show how to perform ECL computations using simulated loan data, macro scenario data, and an existing lifetime probability of default (PD) model.
Load loan data ready for prediction, macro scenario data, and corresponding scenario probabilities.
load DataPredictLifetime.mat
disp(LoanData)
ID ScoreGroup YOB Year ____ _____________ ___ ____ 1304 "Medium Risk" 4 2020 1304 "Medium Risk" 5 2021 1304 "Medium Risk" 6 2022 1304 "Medium Risk" 7 2023 1304 "Medium Risk" 8 2024 1304 "Medium Risk" 9 2025 1304 "Medium Risk" 10 2026 2067 "Low Risk" 7 2020 2067 "Low Risk" 8 2021 2067 "Low Risk" 9 2022 2067 "Low Risk" 10 2023
disp(head(MultipleScenarios,10))
ScenarioID Year GDP Market __________ ____ ____ ______ "Severe" 2020 -0.9 -5.5 "Severe" 2021 -0.5 -6.5 "Severe" 2022 0.2 -1 "Severe" 2023 0.8 1.5 "Severe" 2024 1.4 4 "Severe" 2025 1.8 6.5 "Severe" 2026 1.8 6.5 "Severe" 2027 1.8 6.5 "Adverse" 2020 0.1 -0.5 "Adverse" 2021 0.2 -2.5
disp(ScenarioProbabilities)
Probability ___________ Severe 0.1 Adverse 0.2 Baseline 0.3 Favorable 0.2 Excellent 0.2
load LifetimeChampionModel.mat
disp(pdModel)
Probit with properties: ModelID: "Champion" Description: "A sample model used as champion model for illustration purposes." Model: [1x1 classreg.regr.CompactGeneralizedLinearModel] IDVar: "ID" AgeVar: "YOB" LoanVars: "ScoreGroup" MacroVars: ["GDP" "Market"] ResponseVar: "Default"
For ECL computations, only the marginal PDs are required. However, first you can visualize the lifetime PDs.
CompanyIDChoice ="1304"; CompanyID = str2double(CompanyIDChoice); IndCompany = LoanData.ID == CompanyID; Years = LoanData.Year(IndCompany); NumYears = length(Years); ScenarioID = unique(MultipleScenarios.ScenarioID,'stable'); NumScenarios = length(ScenarioID); LifetimePD = zeros(NumYears,NumScenarios); for ii=1:NumScenarios IndScenario = MultipleScenarios.ScenarioID==ScenarioID(ii); data = join(LoanData(IndCompany,:),MultipleScenarios(IndScenario,:)); LifetimePD(:,ii) = predictLifetime(pdModel,data); end plot(Years,LifetimePD) xticks(Years) grid on xlabel('Year') ylabel('Lifetime PD') title('Lifetime PD By Scenario') legend(ScenarioID,'Location','best')
Strictly speaking, the computation of ECL requires a lifetime PD model, a lifetime LGD model, and a lifetime EAD model, plus the scenarios, scenario probabilities, and an effective interest rate.
For simplicity, this example assumes constant LGD
and EAD
models and a given interest rate.
LGD = 0.55; EAD = 100000; EffRate = 0.045; CompanyIDChoice ="1304"; CompanyID = str2double(CompanyIDChoice); IndCompany = LoanData.ID == CompanyID; Years = LoanData.Year(IndCompany); NumYears = length(Years); ScenarioID = unique(MultipleScenarios.ScenarioID,'stable'); NumScenarios = length(ScenarioID); MarginalPD = zeros(NumYears,NumScenarios); for ii=1:NumScenarios IndScenario = MultipleScenarios.ScenarioID==ScenarioID(ii); data = join(LoanData(IndCompany,:),MultipleScenarios(IndScenario,:)); MarginalPD(:,ii) = predictLifetime(pdModel,data,'ProbabilityType','marginal'); end DiscTimes = Years-Years(1)+1; DiscFactors = 1./(1+EffRate).^DiscTimes; ProbScenario = ScenarioProbabilities.Probability; ECL_t_s = (MarginalPD*LGD*EAD).*DiscFactors; % ECL by year and scenario ECL_s = sum(ECL_t_s); % ECL total by scenario ECL = ECL_s*ProbScenario; % ECL weighted average over all scenarios % Arrange ECL data for display in table format % Append ECL total per scenario and scenario probabilities ECL_Disp = array2table([ECL_t_s; ECL_s; ProbScenario']); ECL_Disp.Properties.VariableNames = ScenarioID; ECL_Disp.Properties.RowNames = [strcat("ECL ",string(Years)); "ECL total"; "Probability"]; disp(ECL_Disp)
Severe Adverse Baseline Favorable Excellent ______ _______ ________ _________ _________ ECL 2020 595.58 507.16 430.44 364.11 306.97 ECL 2021 394.24 349.95 310.02 274.11 241.9 ECL 2022 235.53 215.4 196.75 179.5 163.57 ECL 2023 143.05 135.23 127.75 120.59 113.77 ECL 2024 85.219 83.517 81.816 80.118 78.429 ECL 2025 51.346 51.514 51.665 51.798 51.917 ECL 2026 33.162 33.271 33.368 33.454 33.531 ECL total 1538.1 1376 1231.8 1103.7 990.08 Probability 0.1 0.2 0.3 0.2 0.2
fprintf('Lifetime ECL for company %s is: %g\n',CompanyIDChoice,ECL)
Lifetime ECL for company 1304 is: 1217.32
fitLifetimePDModel
| Logistic
| modelAccuracy
| modelDiscrimination
| predict
| predictLifetime
| Probit