SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_script_econ_cap.sas
1/* ********************************************* */
2/* Economic Capital Analysis: Input Parameters */
3/* ********************************************* */
4
5/* TGT Authentication Ticket */
6%let rgf_tgt_ticket = ${globals.ticket};
7
8/* Get the root location of the SAS Risk Workgroup Application */
9%let sas_risk_workgroup_dir = ${globals.sas_risk_workgroup_dir};
10
11/* Cycle Id */
12%let cycle_id = ${context.cycle.key};
13
14/* Analysis Run Id */
15%let analysis_run_id = ${context.analysisRun.key};
16
17/* IRM Configuration Set Id */
18%let config_set_id = ${params.CONFIGSETID};
19
20/* Portfolio key */
21%let portfolio_key = ${params.PORTFOLIO.key};
22
23/* Counterparty key */
24%let counterparty_key = ${params.ECVARMODEL.params.COUNTERPARTY.key};
25
26/* Mitigant key */
27%let mitigant_key = ${params.ECVARMODEL.params.MITIGATION.key};
28
29/* Collateral key */
30%let collateral_key = ${params.ECVARMODEL.params.COLLATERAL.key};
31
32/*Economic Simulation key*/
33%let econsimulation_key = ${params.ECVARMODEL.params.ECONSIMULATION.key};
34
35/* Risk Type */
36%let risk_type = ${params.RISKTYPE};
37
38/* IA data key */
39%let ia_data_key = ${params.IADATA.key};
40/* Model Input DataMap key */
41%let modelIn_dataMap_key = ${params.MODELINPUTMAP.key};
42
43/* Model Output DataMap key */
44%let modelOut_dataMap_key = ${params.MODELOUTPUTMAP.key};
45
46/* Model Run Key */
47%let model_run_key = ${params.ECVARMODEL.rels("context").modelRun.key};
48
49/* Keep MIP Cube? */
50%let keep_mip_cube_flg = ${params.KEEPMIPCUBE};
51
52/* LASR load method (Append/Replace) */
53%let lasr_load_method = ${params.LASRLOADMETHOD};
54
55/* List of analysis data objecs to reload (if lasr_load_method = replace) */
56%let reload_key_list = ${params.RELOADKEYLIST};
57/* Convert to space separated list: ["<key1>","<key2>",...,"<keyN>"] --> <key1> <key2> ... <keyN> */
58%let reload_key_list = %sysfunc(prxchange(s/\W+/ /i, -1, %superq(reload_key_list)));
59
60/* Process BEP x MRS parameters */
61${function:ProcessModelParameter(params.BEP, "BEP", "MRS")}
62
63/* Log Level: 1-4 */
64%let log_level = ${params.LOGLEVEL};
65
66/* Maximum wait time for IRM job completion: <number of seconds> */
67%let max_wait = ${params.MAXWAIT};
68
69/* Run model or have data passed in directly */
70%let load_external = ${params.LOADEXTERNAL};
71
72/* External Load Parameters */
73%let extBaseScen_sn = ${params.EXTBASECASESCEN.mrsShortName};
74%let extAdverseScen_sn = ${params.EXTADVERSESCEN.mrsShortName};
75%let extBEP_sn = ${params.EXTBEP.bepShortName};
76
77${function:ProcessSpreadsheetParameter(params.EXTBASECASERESULTS,"extBaseResults")}
78${function:ProcessSpreadsheetParameter(params.EXTADVERSERESULTS,"extAdverseResults")}
79
80
81/* ********************************************* */
82
83/* Initialize the environment */
84%include "&sas_risk_workgroup_dir./groups/Public/SASRiskManagementCore/cycles/&cycle_id./init.sas" / lrecl = 32000 source2;
85
86/* Set logging options (based on the value of LOG_LEVEL macro variable) */
87%irm_set_logging_options();
88
89/* Set Instance Parameters */
90%let analysis_run_type = EC;
91%let jobflow_category = Analytics;
92%if &risk_type.=Credit %then %do;
93 %let jobflow_type = %lowcase(irm&solutionId._credit_risk);
94 %let instanceName = Credit Risk Analysis &instance_date._&instance_time.;
95 %let instanceDesc = Credit Risk Analysis;
96%end;
97%if &risk_type.=Market %then %do;
98 %let analysis_run_type = EC_MARKET;
99 %let jobflow_type = %lowcase(irm&solutionId._market_risk);
100 %let instanceName = Market Risk Analysis &instance_date._&instance_time.;
101 %let instanceDesc = Market Risk Analysis;
102%end;
103%let instance_date = %sysfunc(date(), yymmddp10.);
104%let instance_time = %sysfunc(prxchange(s/(\d+):(\d+):(\d+)/$1h$2m$3s/i, -1, %sysfunc(time(), tod8.)));
105%let jobflow_status = Unknown;
106%if(&load_external. = No) %then %do;
107
108 /* Process LASR load method */
109 %let reload_lasr_flg = %irmc_process_lasr_load_method(&lasr_load_method.);
110
111 /* Run option table */
112 data work.run_option;
113 length
114 config_name $32.
115 config_value $10000.
116 ;
117 config_name = "RMC_FA_ID"; config_value = "&rmc_fa_id."; output;
118 config_name = "CYCLE_ID"; config_value = "&cycle_id."; output;
119 config_name = "ANALYSIS_RUN_ID"; config_value = "&analysis_run_id."; output;
120 config_name = "ANALYSIS_TYPE"; config_value = "&analysis_run_type."; output;
121 config_name = "MAX_WAIT"; config_value = "&max_wait."; output;
122 config_name = "LOG_LEVEL"; config_value = "&log_level."; output;
123 config_name = "RELOAD_LASR_FLG"; config_value = "&reload_lasr_flg."; output;
124 config_name = "RELOAD_KEY_LIST"; config_value = "&reload_key_list."; output;
125 config_name = "TGT_TICKET"; config_value = "&rgf_tgt_ticket."; output;
126 run;
127
128 /* Credit Stress parameters table */
129 data work.credit_risk_config;
130 length
131 config_name $32.
132 config_value $100.
133 ;
134 config_name = "CREDIT_MODEL_RUN_KEY"; config_value = "&model_run_key."; output;
135 config_name = "PORTFOLIO_KEY"; config_value = "&portfolio_key."; output;
136 config_name = "COUNTERPARTY_KEY"; config_value = "&counterparty_key."; output;
137 config_name = "MITIGANT_KEY"; config_value = "&mitigant_key."; output;
138 config_name = "COLLATERAL_KEY"; config_value = "&collateral_key."; output;
139 config_name = "ECONSIMULATION_KEY"; config_value = "&econsimulation_key."; output;
140 config_name = "IA_DATA"; config_value = "&ia_data_key."; output;
141 config_name = "MODELIN_DATAMAP_KEY"; config_value = "&modelIn_dataMap_key."; output;
142 config_name = "MODELOUT_DATAMAP_KEY"; config_value = "&modelOut_dataMap_key."; output;
143 config_name = "KEEP_MIP_CUBE_FLG"; config_value = "&keep_mip_cube_flg."; output;
144 config_name = "MART_TABLE_NAME"; config_value = "VALUE_AT_RISK_DETAIL"; output;
145 run;
146
147 %let httpSuccess=1;
148 data bep_x_mrs_config;
149 length BEP_KEY MRS_KEY 8.;
150 keep BEP_KEY MRS_KEY;
151 bep_cnt = symgetn("BEP_CNT");
152 do n = 1 to bep_cnt;
153 bep_key = symgetn(cats("BEP_", n));
154 mrs_cnt = symgetn(cats("BEP_", n, "_MRS_CNT"));
155 if mrs_cnt <= 0 then do;
156 put "ERROR: No Master Risk Scenarios have been assigned to Business Evolution Plan Id " bep_key;
157 call symput("httpSuccess", 0);
158 stop;
159 end;
160 do i = 1 to mrs_cnt;
161 mrs_key = symgetn(cats("BEP_", n, "_MRS_", i));
162 output;
163 end;
164 end;
165 run;
166
167 %macro check_httpSuccess;
168 %if &httpSuccess. ne 1 %then %do;
169 %abort cancel;
170 %end;
171 %mend check_httpSuccess;
172 %check_httpSuccess;
173
174 %let instanceKey =;
175 /* Create job flow instance and wait for completion */
176 %irm_rest_create_jobflow_instance(instance_name = &instanceName.
177 , description = &instanceDesc.
178 , entityId = &entity_id.
179 , entityRoleKey = &entity_role_key.
180 , category = &jobflow_category.
181 , jobflowFile = &jobflow_type.
182 , baseDate = &irm_base_dt.
183 , configSetId = &config_set_id.
184 , federatedAreaID = &irm_fa_id.
185 , sourceFederatedAreaId = &irm_fa_id.
186 , src_param_tables = work.run_option work.credit_risk_config
187 , tgt_param_tables = &solutionLibrefPrefix._CFG.RUN_OPTION &solutionLibrefPrefix._CFG.CREDIT_RISK_CONFIG
188 , src_upload_tables = work.bep_x_mrs_config
189 , tgt_upload_tables = &solutionLibrefPrefix._CFG.BEP_X_MRS_CONFIG
190 , autoRun = true
191 , wait_flg = Y
192 , pollInterval = 3
193 , maxWait = &max_wait.
194 , host = &irm_protocol.://&irm_host.
195 , port = &irm_port.
196 , tgt_ticket = &rgf_tgt_ticket.
197 , outvar = instanceKey
198 , outVarStatus = jobflow_status
199 );
200%end;
201%put --- DONE CALLING JOBFLOW, STATUS IS: &jobflow_status.;
202%if(&jobflow_status. = Successful and &load_external. = No) %then %do;
203 /* Refresh the Star Schema Views */
204 %irmc_refresh_lasr_schema_view(lasr_lib = &lasr_libref.
205 , mart_table_name = &solutionId._VALUE_AT_RISK_DETAIL
206 , rls_table_name = &solutionId._VALUE_AT_RISK_DETAIL_RLS
207 , meta_repository = &meta_repository.
208 , lasr_library_name = &lasr_library_name.
209 , lasr_meta_folder = &lasr_meta_folder.
210 );
211
212 %irmst_create_loss_dist_summary(host = &rgf_protocol.://&rgf_host.
213 , server = &rgf_service.
214 , solution = &rgf_solution.
215 , port = &rgf_port.
216 , tgt_ticket = &rgf_tgt_ticket.
217 , name = %sysfunc(propcase(&risk_type.)) Risk for &entity_id. Summary &instance_date._&instance_time.
218 , description = Loss Distribution Summary information for analysis run &analysis_run_id.
219 , risktype = &risk_type.
220 , analysis_run_key = &analysis_run_id.
221 , base_date = &base_dt.
222 , cycle_id = &cycle_id.
223 , entity_id = &entity_id.
224 , status_cd = Preliminary
225 , libref = &dr_libref.
226 , schema_name = st_loss_distribution_sumry
227 , schema_version = &content_version.
228 , out_exceptions = data_exceptions
229 , out_analysis_data = out_loss_summary
230 , out_partition_list = ls_partitions
231 , out_data_definition = ls_data_def
232 , out_link_instance = ls_link_instances
233 , outVarTicket = ticket
234 , outSuccess = httpSuccess
235 , outResponseStatus = responseStatus
236 , restartLUA = Y
237 , clearCache = Y
238 );
239%end;
240%if(&load_external. = No) %then %do;
241 /* Update the Cycle control table */
242 %irmc_update_ctrl_table(cycle_id = &cycle_id.
243 , analysis_run_id = &analysis_run_id.
244 , dr_libref = &dr_libref.
245 , entry_type = IRM
246 , entry_id = &instanceKey.
247 , entry_name = &instanceName.
248 );
249%end;
250%if(&load_external. = Yes) %then %do;
251 data extBaseResults;
252 length SCENARIO_ID $ 32;
253 set extBaseResults;
254 RISK_TYPE = "&risk_type.";
255 SCENARIO_ID = compress("&extBEP_sn._&extBaseScen_sn._FT" || put(forecastTime,BEST.));
256 REPORTING_DT= input("&base_dt.",YYMMDD10.);
257 drop forecastTime key;
258 run;
259 data extAdverseResults;
260 length SCENARIO_ID $ 32;
261 set extAdverseResults;
262 RISK_TYPE = "&risk_type.";
263 SCENARIO_ID = compress("&extBEP_sn._&extAdverseScen_sn._FT" || put(forecastTime,BEST.));
264 REPORTING_DT= input("&base_dt.",YYMMDD10.);
265 drop forecastTime key;
266 run;
267 data loss_summary;
268 set extBaseResults extAdverseResults;
269 run;
270
271 %irm_rgf_store_analysis_data(ds_in = loss_summary
272 /* Analysis Data Parameters */
273 , analysis_data_name = %sysfunc(propcase(&risk_type.)) Risk for &entity_id. Summary &instance_date._&instance_time.
274 , analysis_data_desc = Externally produced &risk_type. risk results
275 , base_date = &base_dt.
276 , cycle_id = &cycle_id.
277 , entity_id = &entity_id.
278 , status_cd = Preliminary
279 , analysis_run_id = &analysis_run_id.
280
281 /* Data Definition Parameters */
282 , libref = &dr_libref.
283 , schema_name = st_loss_distribution_sumry
284 , schema_version = &content_version.
285
286 /* Output tables */
287 , out_exceptions = data_exceptions
288 , out_analysis_data = new_analysys_data
289 , out_partition_list = new_partitions
290 , out_data_definition = data_definition
291 , out_link_instance = link_instance
292
293 /* Connection Parameters */
294 , host = &rgf_protocol.://&rgf_host.
295 , server = &rgf_service.
296 , solution = &rgf_solution.
297 , port = &rgf_port.
298 , tgt_ticket = &rgf_tgt_ticket.
299 , outVarTicket = ticket
300 , outSuccess = httpSuccess
301 , outResponseStatus = responseStatus
302 );
303
304 /* Update the Cycle control table */
305 %irmc_update_ctrl_table(cycle_id = &cycle_id.
306 , analysis_run_id = &analysis_run_id.
307 , dr_libref = &dr_libref.
308 , entry_type = RGF
309 , entry_id = &analysis_run_id.
310 , entry_name = Economic Capital
311 , entry_location = analysisRuns
312 );
313%end;