SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_script_seg_level.sas
1/*----------------------------------------------------------------------------
2 * NAME: irmst_script_seg_level.sas
3 * (Credit Stress Analysis (Segment-level): Input Parameters)
4 *
5 * PURPOSE: Execution configuration code for Segment-level process task
6 *
7 * NOTES: The output PMXs are linked to a loan-level model run key. These
8 * PMXs are then picked up in the loan-level run using the same key
9 *
10 *
11 * Copyright (c) 2020 SAS Institute
12 *----------------------------------------------------------------------------*/
13
14/* TGT Authentication Ticket */
15%let rgf_tgt_ticket = ${globals.ticket};
16
17/* Cycle Id */
18%let cycle_id = ${context.cycle.key};
19
20/* Analysis Run Id */
21%let analysis_run_id = ${context.analysisRun.key};
22
23/* Process BEP x MRS parameters (creates global macro variables) */
24${function:ProcessModelParameter(params.BEP, "BEP", "MRS")}
25
26/* Log Level: 1-4 (1 toggle debug off, 2-4 toggle debug on) */
27%let log_level = ${params.LOGLEVEL};
28%if &log_level gt 1 %then
29%do;
30 %let log_debug = true;
31%end;
32%else
33%do;
34 %let log_debug = false;
35%end;
36
37/* Maximum wait time for IRM job completion: <number of seconds> */
38%let max_wait = ${params.MAXWAIT};
39
40/* Base date specified in the cycle */
41%let base_dt = ${context.cycle.baseDt};
42
43/* ********************************************* */
44
45/* Get the root location of the SAS Risk Workgroup Application */
46%let sas_risk_workgroup_dir = %sysfunc(metadata_appprop(Risk Work Group Svr Cfg, root.dir));
47
48/* Initialize the environment & compile custom macros */
49%include "&sas_risk_workgroup_dir./groups/Public/SASRiskManagementCore/cycles/&cycle_id./init.sas" / lrecl = 32000 source2;
50
51/* Set logging options (based on the value of LOG_LEVEL macro variable) */
52%irm_set_logging_options();
53
54/* Segment-level run key */
55%let seg_lvl_model_run_key = ${params.SEGLEVELMODEL.rels("context").modelRun.key};
56
57%let httpSuccess = 0;
58%let responseStatus =;
59%let ticket=;
60%irm_rest_get_rgf_model_run(host = &rgf_protocol.://&rgf_host.
61 , server = &rgf_service.
62 , solution = &rgf_solution.
63 , port = &rgf_port.
64 , tgt_ticket = &rgf_tgt_ticket.
65 , key = &seg_lvl_model_run_key.
66 , outds = tmp_model_run_info
67 , outds_params = ds_out_model_run_parms
68 , fout_code = fcd
69 , fout_pre_code = fpre
70 , fout_post_code = fpost
71 , fout_mip_pre_code = mippre
72 , fout_mip_post_code = mippost
73 , outVarTicket = ticket
74 , outSuccess = httpSuccess
75 , outResponseStatus = responseStatus
76 , restartLUA = Y
77 , clearCache = Y
78 );
79
80data _null_;
81 set ds_out_model_run_parms;
82 where
83 lowcase(parameterName) in
84 ("modelin_datamap_key"
85 , "mipqueryflg"
86 , "mipnumbernodes"
87 , "mipnumberthreads"
88 , "mipinterval"
89 , "miphorizon"
90 , "mipoutputcurrency"
91 , "mipnumbersimulations"
92 , "mipoutputvariables"
93 , "mipcomputedmethods"
94 , "mipparametermatrices"
95 , "mipcashflows"
96 , "mipvaluedata"
97 , "mipprochpriskarguments"
98 , "mipaggregationlevels"
99 , "mipoutputdatasets"
100 , "mipqueryfilter"
101 , "mipintervalalignment"
102 )
103 and not missing(parameterValue)
104 ;
105 call symputx(parameterName, parameterValue, "L");
106run;
107
108%let httpSuccess = 0;
109%let responseStatus =;
110%let ticket=;
111%irm_rest_get_rgf_model(host = &rgf_protocol.://&rgf_host.
112 , server = &rgf_service.
113 , solution = &rgf_solution.
114 , port = &rgf_port.
115 , tgt_ticket = &rgf_tgt_ticket.
116 , filter = filter=hasObjectLinkTo('%upcase(&rgf_solution.)','model_modelRun',&seg_lvl_model_run_key.,0)
117 , outds = tmp_model_info
118 , outds_params = tmp_model_params
119 , fout_code =
120 , fout_pre_code =
121 , fout_post_code =
122 , fout_mip_pre_code =
123 , fout_mip_post_code =
124 , outVarTicket = ticket
125 , outSuccess = httpSuccess
126 , outResponseStatus = responseStatus
127 , restartLUA = Y
128 , clearCache = Y
129 );
130
131/* Get the engine type */
132data ds_out_model_run_info;
133 merge
134 tmp_model_run_info (keep = key name rename = (key = modelRunKey name = modelRunName))
135 tmp_model_info
136 (keep = key
137 name
138 versionId
139 runTypeCd
140 typeCd
141 subTypeCd
142 statusCd
143 engineCd
144 businessCatCd
145 preCodeFlg
146 postCodeFlg
147 preMipFlg
148 postMipFlg
149 scenWeightFlg
150 solutionCreatedIn
151 vmmModelId
152 mipRunTypeCd
153 mipModelingSystemWorkgroup
154 mipModelingSystemName
155 mipModelingSystemVersion
156 mipWeightedOutputVars
157 rename = (key = modelKey
158 name = modelName
159 solutionCreatedIn = modelPerspectiveId
160 )
161 )
162 ;
163 /* Model engine */
164 call symputx("model_engine_cd", engineCd, "L");
165 call symputx("model_perspective_id", lowcase(modelPerspectiveId), "L");
166
167 /* MIP specific fields */
168 call symputx("mip_ms_name", mipModelingSystemName, "L");
169 call symputx("mip_ms_version", mipModelingSystemVersion, "L");
170 call symputx("mip_ms_workgroup", mipModelingSystemWorkgroup, "L");
171 call symputx("pre_mip_flg", ifc(preMipFlg = "true", "Y", "N"), "L");
172 call symputx("post_mip_flg", ifc(postMipFlg = "true", "Y", "N"), "L");
173 call symputx("pre_code_flg", ifc(preCodeFlg = "true", "Y", "N"), "L");
174 call symputx("post_code_flg", ifc(postCodeFlg = "true", "Y", "N"), "L");
175
176run;
177
178%if(&pre_code_flg. = Y) %then %do;
179
180 /* Run the SAS pre-execution code */
181 %let ticket =;
182 %include fpre / source2 lrecl = 32000;
183 /* In the SAS pre-execution we may need to use the service ticket: for example retrieving spcific data set.
184 Given that we don't know how many times the service ticket will be used, we may want to get a new one after running the pre-execution program
185 */
186 %let ticket =;
187
188%end;
189
190/*----------------------------------------------
191 * Retrieve the specified modeling system SK/ID
192 *----------------------------------------------*/
193%let httpSuccess = 0;
194%let responseStatus =;
195%let ticket_ms =;
196%irm_rest_get_mip_ms_info(host = &mip_protocol.://&mip_host
197 , server = &mip_service
198 , port = &mip_port
199 , tgt_ticket = &rgf_tgt_ticket
200 , workgroup = &mip_ms_workgroup
201 , outds = work.tmp_mip_msinfo
202 , outVarTicket = ticket_ms
203 , outSuccess = httpSuccess
204 , outResponseStatus = responseStatus
205 , restartLUA = Y
206 , clearCache = Y
207 )
208
209data _null_;
210 set work.tmp_mip_msinfo;
211 if upcase(modelingSystemName) eq upcase("&mip_ms_name") and
212 upcase(modelingSystemVersion) eq upcase("&mip_ms_version") then
213 call symputx("tgt_ms_sk", modelingSystemId, "G");
214run;
215
216/*--------------------------------------------
217 * Retrieve information about MIP model group
218 *--------------------------------------------*/
219%let httpSuccess = 0;
220%let responseStatus =;
221%let ticket_workgroup =;
222%irmst_get_model_group_maps(model_group_kind = EVALUATION
223 , ms_sk = &tgt_ms_sk
224 , add_seg_lvl_ms_sk = &tgt_ms_sk
225 , out_model_group_map = work.model_group_map_seg
226 , mipurl = &mip_protocol.://&mip_host.:&mip_port./&mip_service.
227 , tgt_ticket = %superq(rgf_tgt_ticket)
228 , debug = &log_debug
229 , host = &mip_protocol.://&mip_host
230 , server = &mip_service
231 , port = &mip_port
232 , workgroup = &mip_ms_workgroup
233 , authMethod = token
234 , outds = work._tmp_workgroups_
235 , outVarTicket = ticket_workgroup
236 , outSuccess = httpSuccess
237 , outResponseStatus = responseStatus
238 , restartLUA = Y
239 , clearCache = Y
240 )
241
242/*-------------------------
243 * Generate MIP cube names
244 *-------------------------*/
245%let base_dt_fmt1 = %sysfunc(inputn(&base_dt, yymmdd10.), yymmddn8.);
246%let base_dt_fmt2 = %sysfunc(inputn(&base_dt, yymmdd10.), yymmddd10.);
247
248%let source_ptf = synth_port_&base_dt_fmt1._&seg_lvl_model_run_key;
249%let cube_nm = seg_lvl_cube_&base_dt_fmt1._&seg_lvl_model_run_key;
250%let modscen_nm = seg_lvl_scenRun_&base_dt_fmt1._&seg_lvl_model_run_key;
251
252/*---------------------------
253 * Build synthetic portfolio
254 *---------------------------*/
255libname _port_ "&sas_risk_workgroup_dir./groups/&mip_ms_workgroup./&mip_service./input/portfolios";
256
257%irmst_build_synthetic_portfolio(model_group_map_tbl = work.model_group_map_seg
258 , mipport_libref = _port_
259 , outds = &source_ptf
260 )
261
262libname _port_ clear;
263
264/*-----------------------
265 * Create Portfolio cube
266 *-----------------------*/
267%let httpSuccess = 0;
268%let responseStatus =;
269%let ticket_mip =;
270%irm_rest_create_mip_cube(host = &mip_protocol.://&mip_host
271 , server = &mip_service
272 , port = &mip_port
273 , tgt_ticket = %superq(rgf_tgt_ticket)
274 , cubeName = &cube_nm
275 , workgroup = &mip_ms_workgroup
276 , portfolioDataName = &source_ptf
277 , counterpartyDataName =
278 , numberNodes = &mipnumbernodes
279 , numberThreads = &mipnumberthreads
280 , runAsOfDate = &base_dt_fmt2
281 , procHpriskArguments =
282 , crossClassVars =
283 , wait_flg = Y
284 , pollInterval = 3
285 , maxWait = &max_wait
286 , outds = work.cube_details
287 , outVarTicket = ticket_mip
288 , outSuccess = httpSuccess
289 , outResponseStatus = responseStatus
290 , restartLUA = Y
291 , clearCache = Y
292 )
293
294/*---------------------------
295 * Configure BEP x MRS table
296 *---------------------------*/
297data bep_x_mrs_config;
298 length BEP_KEY MRS_KEY 8.;
299 keep BEP_KEY MRS_KEY;
300 bep_cnt = symgetn("BEP_CNT");
301 do n = 1 to bep_cnt;
302 bep_key = symgetn(cats("BEP_", n));
303 mrs_cnt = symgetn(cats("BEP_", n, "_MRS_CNT"));
304 do i = 1 to mrs_cnt;
305 mrs_key = symgetn(cats("BEP_", n, "_MRS_", i));
306 output;
307 end;
308 if mrs_cnt <= 0 then
309 put "WARNING: No Master Risk Scenarios have been assigned to Business Evolution Plan Id " bep_key;
310 end;
311run;
312
313/*-------------------------
314 * Setup economics dataset
315 *-------------------------*/
316%rsk_mkdirs(&sas_risk_workgroup_dir./groups/&mip_ms_workgroup./SASModelImplementationPlatform/input/economics/scenarios_&base_dt_fmt1._&seg_lvl_model_run_key.);
317
318%irmst_get_scenarios_from_rsm(analysis_run_id = &analysis_run_id
319 , bep_x_mrs_tbl = work.bep_x_mrs_config
320 , base_dt = &base_dt
321 , out_scen_meta = work.scenario_info
322 , out_scen_data = work.out_scenario_data
323 , rgf_protocol = &rgf_protocol
324 , rgf_host = &rgf_host
325 , rgf_port = &rgf_port
326 , rgf_service = &rgf_service
327 , rgf_solution = &rgf_solution
328 , rsm_protocol = &rsm_protocol
329 , rsm_host = &rsm_host
330 , rsm_port = &rsm_port
331 , rsm_service = &rsm_service
332 , tgt_ticket = %superq(rgf_tgt_ticket)
333 , debug = &log_debug
334 )
335
336libname _econ_ "&sas_risk_workgroup_dir./groups/&mip_ms_workgroup./SASModelImplementationPlatform/input/economics/scenarios_&base_dt_fmt1._&seg_lvl_model_run_key.";
337
338/* Creates economics dataset to MIP input directory */
339data _econ_.scenario_data;
340 set work.out_scenario_data end = last;
341
342 /* Set the max horizon */
343 %if(%upcase(&miphorizon.) eq MAX) %then
344 %do;
345 retain maxHorizon;
346 maxHorizon = max(maxHorizon, horizon);
347
348 /* Re-set the number of horizons to run in MIP */
349 if last then
350 do;
351 call symputx("miphorizon", maxHorizon, "g");
352 drop maxHorizon;
353 end;
354 %end;
355run;
356
357libname _econ_ clear;
358
359/*--------------------------
360 * Create Scenario run cube
361 *--------------------------*/
362%let httpSuccess = 0;
363%let responseStatus =;
364%let ticket_mip =;
365%irm_rest_create_mip_ms_scen_run(host = &mip_protocol.://&mip_host
366 , server = &mip_service
367 , port = &mip_port
368 , tgt_ticket = %superq(rgf_tgt_ticket)
369 , workgroup = &mip_ms_workgroup
370 , modelingSystemName = &mip_ms_name
371 , modelingSystemVersion = &mip_ms_version
372 , preExecutionPgmName =
373 , postExecutionPgmName =
374 , instanceName = &modscen_nm
375 , cubeName = &cube_nm
376 , portfolioDataName = &source_ptf
377 , counterpartyDataName =
378 , economicDataName = scenarios_&base_dt_fmt1._&seg_lvl_model_run_key
379 , interval = %lowcase(&mipinterval)
380 , horizon = &miphorizon
381 , outputCurrency = &mipoutputcurrency
382 , genCodeOnly = false
383 , removeCubeEnabled = false
384 , registerScenarios = false
385 , numberSimulations = 0
386 , reSubmit = true
387 , outputVariables =
388 , computedMethods =
389 , parameterMatrices = &mipParameterMatrices
390 , cashflows =
391 , valueData =
392 , numberNodes = &mipnumbernodes
393 , numberThreads = &mipnumberthreads
394 , runAsOfDate = &base_dt_fmt2
395 , procHpriskArguments =
396 , aggregationLevels =
397 , outputDataSets =
398 , wait_flg = Y
399 , pollInterval = 3
400 , maxWait = &max_wait
401 , outds = work.mip_run_instance_details
402 , outVarTicket = ticket_mip
403 , outSuccess = httpSuccess
404 , outResponseStatus = responseStatus
405 , restartLUA = Y
406 , clearCache = Y
407 )
408
409/*---------------------------------
410 * Create model_trans_matrix table
411 *---------------------------------*/
412%let httpSuccess = 0;
413%let responseStatus = ;
414%let ticket_workgroup = ;
415%irmst_load_trans_matrix_results(run_name = &modscen_nm
416 , workgroup = &mip_ms_workgroup
417 , model_group_map = work.model_group_map_seg
418 , function_package = work.rating_format
419 , scenario_meta = work.scenario_info
420 , tm_to_load = work.model_trans_matrix
421 , debug = &log_debug
422 , mipurl = &mip_protocol.://&mip_host.:&mip_port./&mip_service.
423 , tgt_ticket = %superq(rgf_tgt_ticket)
424 , host = &mip_protocol.://&mip_host
425 , server = &mip_service
426 , port = &mip_port
427 , authMethod = token
428 , outds = work._tmp_workgroups_
429 , outVarTicket = ticket_workgroup
430 , outSuccess = httpSuccess
431 , outResponseStatus = responseStatus
432 , restartLUA = Y
433 , clearCache = Y
434 )
435
436/*--------------------------------------------------
437 * Load TM Results as an RGF Analysis Data Object
438 *--------------------------------------------------*/
439%irmst_load_tm_analysis_data(ad_analysis_data_name = %quote(Transition Matrix Results)
440 , ad_analysis_data_desc = %quote(Transition Matrix Results from Segment-level Analysis Run &analysis_run_id.. \nCreated by user &_metauser. on %sysfunc(datetime(), nldatmw200.).)
441 , ad_analysis_run_id = &analysis_run_id
442 , ad_base_date = &base_dt
443 , ad_cycle_id = &cycle_id
444 , ad_details_root = &sas_risk_workgroup_dir
445 , ad_entity_id = &entity_id
446 , ad_libref = &dr_libref
447 , ad_meta_library_name = &dr_library_name
448 , ad_schema_version = &content_version
449 , debug = &log_debug
450 , in_model_group_map = work.model_group_map_seg
451 , in_model_tm_results = work.model_trans_matrix
452 , in_scenario_meta = work.scenario_info
453 , rgf_host = &rgf_host
454 , rgf_port = &rgf_port
455 , rgf_protocol = &rgf_protocol
456 , rgf_service = &rgf_service
457 , rgf_solution = &rgf_solution
458 , tgt_ticket = %superq(rgf_tgt_ticket)
459 )