SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_model_precode_EBA2020.sas
1/* ******************************************** *
2/* Pre-processing script for the MIP execution *
3/* ******************************************** *
4
5Details:
6 The following SAS macro variables are available to the model at run time:
7 - ticket: SAS authentication service ticket (useful for performing operations that require authentication, i.e. interacting with REST services).
8 - rgf_protocol: Communication protocol (http/https) of the SAS Risk and Governance Framework web application
9 - rgf_host: Hostname of the SAS Risk and Governance Framework web application
10 - rgf_port: Port where the SAS Risk and Governance Framework web application is listening
11 - rgf_service: The service where the SAS Risk and Governance Framework web application is listening
12 - ds_in_portfolio: portfolio table
13 - ds_in_scenario: scenario table
14 - ds_in_counterparty: counterparty table (if used)
15 - ds_in_mitigant: credit risk mitigant table (if used)
16
17 The following libraries are pre assigned:
18 - mipport: MIP portfolio library
19 - mipcpty: MIP counterparty library
20 - mipmit: MIP credit risk mitigant library
21 - mipcf: MIP cashflow library
22 - mippmx: MIP parameter matrix library
23 - mippmx: MIP valueData library
24 - mipfunc: MIP functions library
25
26*/
27
28/* Cashflow data object key */
29%let cashflow_key = ${params.CASHFLOW.key};
30
31/* ******************************************** */
32
33/* Prepare RiskDataMaps parameters for the MIP execution
34 Syntax: <Risk Data Object Name>:<Libname.Dataset> [, <Risk Data Object Name>:<Libname.Dataset>] */
35%let mipParameterMatrices = stresstest_coef : mippmx.st_ecl_parameter_&model_run_key.;
36%let mipCashflows = cashflow_dataset : mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
37
38%macro st_model_prep();
39
40 %local
41 cashflow_flg
42 renameStmt
43 ;
44
45 /* Flag (1/0) to determine if we need to process the cashflow table */
46 %let cashflow_flg = %sysevalf(%superq(cashflow_key) ne, boolean);
47
48 /* Create parameter table for the MIP model */
49 data mippmx.st_ecl_parameter_&model_run_key.;
50 length
51 _NAME_ $100.
52 _VALUE_ 8.
53 ;
54 /* Compute RWA */
55 _NAME_ = "FLAG_RWA_CALCULATION_CMatrix"; _VALUE_ = 1; output;
56 /* Number of credit states */
57 _NAME_ = "STATE_CNT_CMatrix"; _VALUE_ = 9; output;
58 /* Number of active (non-defaulted) credit states */
59 _NAME_ = "ACTIVE_STATE_CNT_CMatrix"; _VALUE_ = 8; output;
60 /* Default credit state */
61 _NAME_ = "DEFAULT_STATE_INDEX_CMatrix"; _VALUE_ = 9; output;
62 /* Use PD at origination to compute the PD deterioration delta */
63 _NAME_ = "FLAG_INITIAL_PD_FROM_PRTF_CMatrix"; _VALUE_ = 1; output;
64 /* Use cashflow data? */
65 _NAME_ = "FLAG_PAYMENTS_AS_CASHFLOWS_CMatrix"; _VALUE_ = &cashflow_flg.; output;
66 run;
67
68 /* Retrieve cashflow data */
69 %if &cashflow_flg. %then %do;
70
71 %let renameStmt = %nrstr(
72 rename
73 cashflow_dt = valDate
74 cashflow_leg = valType
75 cashflow_amt = valAmount
76 ;
77 );
78
79 /*It register the cash-flow data set into MIP*/
80 %let httpSuccess = 0;
81 %let responseStatus =;
82 %irm_rgf_retrieve_analysis_data(key = &cashflow_key.
83 , libref = &dr_libref.
84 , outds = mipcf.cashflow_&base_dt_ymdn._&model_run_key.
85 , outds_partition_list = cashflow_partition_list
86 , out_type = data
87 , custom_code = %superq(renameStmt)
88 , outds_dataInfo = cashflow_dataInfo
89 , outds_dataDef = cashflow_dataDef
90 , host = &rgf_protocol.://&rgf_host.
91 , server = &rgf_service.
92 , solution = &rgf_solution.
93 , port = &rgf_port.
94 , tgt_ticket = &tgt_ticket.
95 , outVarTicket = ticket
96 , outSuccess = httpSuccess
97 , outResponseStatus = responseStatus
98 , restartLUA = Y
99 , clearCache = Y
100 );
101
102
103 /*It creates the cash-flow data set for the synthetic positions ("Front Book")*/
104 %let reporting_dt=%sysfunc(datepart(&BASE_DTTM.));
105 %irmc_cf_frontbook_generation( ds_in_frontbook = &ds_in_synth_position.
106 , ds_in_cf_config = ST_CFG.SYNTHETIC_TEMPLATE_CF_CONFIG
107 , ds_out = mipcf.frontbook_cf_&base_dt_ymdn._&model_run_key.
108 , balance_var = unpaid_balance_amt
109 , id_var = INSTID
110 , maturity_dt_var = maturity_dt
111 , reporting_dt = &reporting_dt.
112 , interval = ${params.MIPINTERVAL}
113 , debug = FALSE
114 );
115
116 /*It appends the cash-flow for the synthetic instruments to the cash-flow of the portfolio.*/
117 proc append
118 data=mipcf.frontbook_cf_&base_dt_ymdn._&model_run_key.
119 base=mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
120 run;
121
122
123
124
125
126 %if (%rsk_dsexist(_FRTBK_.short_position) and %rsk_attrn(_FRTBK_.short_position, nlobs) ne 0) %then %do;
127
128 /*It creates the cash-flow data set for the elimnated positions*/
129 %irmc_cf_eliminated_remap( ds_in_cf = mipcf.cashflow_&base_dt_ymdn._&model_run_key.
130 , ds_in_short_position = _FRTBK_.short_position
131 , working_libname = _FRTBK_
132 , ds_out = mipcf.elimnated_CF_&base_dt_ymdn._&model_run_key.
133 );
134
135 /*It appends the cash-flow for the eliminated positions to the cash-flow of the portfolio.*/
136 proc append
137 data=mipcf.elimnated_CF_&base_dt_ymdn._&model_run_key.(drop=ORIG_INSTID)
138 base=mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
139 run;
140
141 %end;
142
143 %end;
144 %else %do;
145 /* Create empty cashflow table */
146 data mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
147 length
148 instid $32.
149 valDate 8.
150 valType $32.
151 valAmount 8.
152 ;
153 stop;
154 run;
155 %end;
156
157
158 /*This pre-run persecution code assumes that the analysis is based only on one business evolution plan and two master risk scenarios:
159 A basecase scenario and an adverse scenario.*/
160 %let base_key=${params.BASECASESCENARIO};
161 proc sql noprint;
162 select min(mrsShortName) into :basecase_scenario_name
163 from ST_STG.SCENARIO_INFO
164 where mrsKey eq &base_key.;
165 select min(mrsShortName) into :adverse_scenario_name
166 from ST_STG.SCENARIO_INFO
167 where mrsKey ne &base_key.;
168 quit;
169
170
171 /*It creates the computed methods for the EBA2020 analysis*/
172 %irmc_mip_cm_eba2020_gen( model_run_key = &model_run_key.
173 , base_dt = &base_dt.
174 , mipHorizon = ${params.MIPHORIZON}
175 , computedmethod_name_prefix = CM_ST_EBA2020_FT
176 , adverse_scenario_name = &adverse_scenario_name.
177 , basecase_scenario_name = &basecase_scenario_name.
178 , ds_out_cm_list = cm_list
179 , mip_cm_eba2020_template = &fa_path./source/sas/nodes/irmst_mip_cm_eba2020_template.sas
180 );
181
182
183 %mend;
184
185%st_model_prep();
186
187/*It creates a macro with all the names of the computed methods that have been generated (It will be used in the post run.)*/
188proc sql noprint;
189 select computedmethod into:mipcomputedmethods separated by " "
190 from cm_list;