SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_script_risk_aggregation.sas
1/* ********************************************* */
2/* Risk Aggregation: Input Parameters */
3/* ********************************************* */
4
5/* TGT Authentication Ticket */
6%let 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_key = ${context.cycle.key};
13
14/* Cycle Name */
15%let cycle_name = %nrbquote(${context.cycle.name});
16
17/* Analysis Run Id */
18%let analysis_run_key = ${context.analysisRun.key};
19
20/* Analysis Run Name */
21%let analysis_run_name = ${context.analysisRun.name};
22
23/* Model Run Key */
24%let model_run_key = ${params.AGGREGATIONMODEL.rels("context").modelRun.key};
25
26/* Create the Capital Adequacy Report */
27%let cap_adq_rpt_flg = ${params.CAPITALADEQUACYRPT};
28
29/* LASR load method (Append/Replace) */
30%let lasr_load_method = ${params.LASRLOADMETHOD};
31
32/* Log Level: 1-4 */
33%let log_level = ${params.LOGLEVEL};
34
35/* Get scenarios and financial statement projection information */
36%let adverse_scenario = ${params.ADVERSESCENARIO};
37%let basecase_scenario = ${params.BASECASESCENARIO};
38
39%let fsp_basecase_key = ${params.FSPBASECASE.key};
40%let fsp_adverse_key = ${params.FSPADVERSE.key};
41
42/* rgf solution calling the model */
43%let rgf_solution = ${globals.contentId};
44
45/* Model name and ID of the aggregation model */
46%let modelId = ${params.AGGREGATIONMODEL.custObj1Id};
47%let modelName = ${params.AGGREGATIONMODEL.name};
48
49%let run_date = %sysfunc(date(), yymmddp10.);
50%let run_time = %sysfunc(prxchange(s/(\d+):(\d+):(\d+)/$1h$2m$3s/i, -1, %sysfunc(time(), tod8.)));
51
52/* Output dataset name */
53%let outDsName = ${params.OUTSUMMARYNAME};
54%if %sysevalf(&outDsName. eq %str(),boolean) %then %do;
55 %let outDsName = Aggregation Results &run_date._&run_time.;
56%end;
57
58/* ********************************************* */
59
60/* Initialize the environment */
61%include "&sas_risk_workgroup_dir./groups/Public/SASRiskManagementCore/cycles/&cycle_key./init.sas" / lrecl = 32000 source2;
62
63/* IRM Configuration Set Id */
64%let config_set_id = EWST;
65
66/* Set logging options (based on the value of LOG_LEVEL macro variable) */
67%irm_set_logging_options();
68
69/*-----------------------------
70 * Retrieve connection details
71 *-----------------------------*/
72%irm_get_service_info(SWCName = Risk Gov Frwk Mid-Tier
73 , DeployedComponentName = Registered SAS Application
74 , ds_out = work.rgf_info
75 )
76
77data _null_;
78 set work.rgf_info;
79 call symputx("rgf_protocol", protocol, "L");
80 call symputx("rgf_host", host, "L");
81 call symputx("rgf_port", port, "L");
82 call symputx("rgf_service", ksubstr(service, 2), "L");
83run;
84
85/* Process LASR load method */
86%let reload_lasr_flg = %irmc_process_lasr_load_method(&lasr_load_method.);
87
88/*Retrieve the code of the aggregation model*/
89
90%let ticket =;
91%let httpSuccess = 0;
92%let responseStatus =;
93%irm_rest_get_rgf_model_run(host = &rgf_protocol.://&rgf_host.
94 , server = &rgf_service.
95 , solution = &rgf_solution.
96 , port = &rgf_port.
97 , tgt_ticket = &tgt_ticket.
98 , key = &model_run_key.
99 , outds = model_run
100 , outds_params = model_run_params
101 , fout_code = fcode
102 , outVarTicket = ticket
103 , outSuccess = httpSuccess
104 , outResponseStatus = responseStatus
105 );
106
107/* Exit in case of errors */
108%if(not &httpSuccess. or not %rsk_dsexist(model_run)) %then %do;
109 %put ERROR: Could not retrieve model information for modelId &modelId.;
110 %abort cancel;
111%end;
112
113/* Execute the code of the choosen aggregation model. */
114%include fcode /source2 lrecl = 32000;
115
116/* Store Loss Distribution Summary and Capital Adeqaucy Summary Results */
117%macro store_results;
118 %local var_exist;
119
120 /*******************************************/
121 /* Store Loss Distribution Summary Results */
122 /*******************************************/
123 /*Register the loss distribution summary in analysis data */
124 %if %rsk_dsexist(RISKAGG_SUMMARY_RESULTS) %then %do;
125
126 /*In some risk aggregation models RISK_TYPE might not be needed/created. This will cause a problem because RISK_TYPE is a primary key in the ddl for loss distribution summary.
127 For example this could happen when running hierarchical aggregation for 1-level on entity.
128 When this happens, make sure that RISK_TYPE is created with a "+" sign*/
129 %let var_exist=%rsk_varexist(&out_libref..RISKAGG_SUMMARY_RESULTS, RISK_TYPE );
130
131 data RISKAGG_SUMMARY_RESULTS RISKAGG_SUMM_ENTITY;
132 set RISKAGG_SUMMARY_RESULTS;
133 %if &var_exist.=0 %then %do;
134 length RISK_TYPE $32.;
135 RISK_TYPE="+";
136 %end;
137 drop
138 _NAME_
139 index
140 ;
141 if entity_id="&entity_id." then output RISKAGG_SUMM_ENTITY;
142 output RISKAGG_SUMMARY_RESULTS;
143 run;
144
145 %let ticket =;
146 %let httpSuccess = 0;
147 %let responseStatus =;
148 %irm_rgf_store_analysis_data(ds_in = RISKAGG_SUMMARY_RESULTS
149 /* Analysis Data Parameters */
150 , analysis_data_name = &outDsName.
151 , analysis_data_desc = Risk aggregation results with the &modelName. model executed on &run_date. at server time: &run_time.
152 , base_date = &base_dt.
153 , cycle_id = &cycle_key.
154 , entity_id = &entity_id.
155 , status_cd = Preliminary
156 , analysis_run_id = &analysis_run_key.
157
158 /* Data Definition Parameters */
159 , libref = &dr_libref.
160 , schema_name = st_loss_distribution_sumry
161 , schema_version = &content_version.
162
163 /* Output tables */
164 , out_exceptions = data_exceptions
165 , out_analysis_data = new_analysis_data
166 , out_partition_list = new_partitions
167 , out_data_definition = data_definition
168 , out_link_instance = link_instance
169
170 /* Connection Parameters */
171 , host = &rgf_protocol.://&rgf_host.
172 , server = &rgf_service.
173 , solution = &rgf_solution.
174 , port = &rgf_port.
175 , tgt_ticket = &tgt_ticket.
176 , outVarTicket = ticket
177 , outSuccess = httpSuccess
178 , outResponseStatus = responseStatus
179 );
180 %end;
181 %else %do;
182 %put ERROR: The aggregation model failed to produce a RISKAGG_SUMMARY_RESULTS dataset;
183 %end;
184
185 /************************************************************************************/
186 /* Get the Financial Statement Projection Analysis Basecase and Adverse Run Results */
187 /* to create the Capital Adequacy Report Results */
188 /************************************************************************************/
189
190 /* If the Capital Adequacy Report Flag = Yes, get the financial statement projection */
191 /* datasets and add them to the RISKAGG_SUMMARY_RESULTS */
192 %if %upcase(&cap_adq_rpt_flg) = YES %then
193 %do;
194 %let ticket = ;
195 %let httpSuccess = 0;
196 %let responseStatus = ;
197 /* If Basecase FS Projection analysis run key passed in, retrieve the Basecase FS Projection table */
198 %if &fsp_basecase_key. ne %str() %then %do;
199 /* Fetch the basecase financial statement table */
200 %irm_rgf_retrieve_analysis_data(key = &fsp_basecase_key.
201 , outds = _fin_st_proj_base_dtl
202 , host = &rgf_protocol.://&rgf_host.
203 , server = &rgf_service.
204 , solution = &rgf_solution.
205 , port = &rgf_port.
206 , tgt_ticket = &tgt_ticket.
207 , outVarTicket = ticket
208 , outSuccess = httpSuccess
209 , outResponseStatus = responseStatus
210 );
211
212 /* Get the Basecase scenario_name */
213 data _null_;
214 set _fin_st_proj_base_dtl(obs=1);
215 call symputx("base_scenario", scenario_name, "L");
216 run;
217 %end;
218 %else %do;
219 %put ERROR: The financial statement projection - basecase results dataset does not exist;
220 %end;
221
222 %let ticket = ;
223 %let httpSuccess = 0;
224 %let responseStatus = ;
225 /* If Adverse FS Projection analysis run key passed in, retrieve the Adverse FS Projection table */
226 %if &fsp_adverse_key. ne %str() %then %do;
227 /* Fetch the adverse financial statement table */
228 %irm_rgf_retrieve_analysis_data(key = &fsp_adverse_key.
229 , outds = _fin_st_proj_adverse_dtl
230 , host = &rgf_protocol.://&rgf_host.
231 , server = &rgf_service.
232 , solution = &rgf_solution.
233 , port = &rgf_port.
234 , tgt_ticket = &tgt_ticket.
235 , outSuccess = httpSuccess
236 , outResponseStatus = responseStatus
237 );
238
239 /* Get the Basecase scenario_name */
240 data _null_;
241 set _fin_st_proj_adverse_dtl(obs=1);
242 call symputx("adverse_scenario", scenario_name, "L");
243 run;
244 %end;
245 %else %do;
246 %put ERROR: The financial statement projection - adverse results dataset does not exist;
247 %end;
248
249 /* If all datasets are available, generate the Capital Adequacy Summary analysis data */
250 %if %rsk_dsexist(_fin_st_proj_base_dtl) and %rsk_dsexist(_fin_st_proj_adverse_dtl) and %rsk_dsexist(RISKAGG_SUMM_ENTITY) %then %do;
251 %let status=Unknown;
252 %irmst_create_capital_adq_summary(fsp_base_ds = _fin_st_proj_base_dtl
253 , fsp_adverse_ds = _fin_st_proj_adverse_dtl
254 , loss_dist_ds = RISKAGG_SUMM_ENTITY
255 , reload_lasr_method = &lasr_load_method.
256 , config_set = &config_set_id.
257 , tgt_ticket = &tgt_ticket.
258 , scenario_nm = %str(&base_scenario. - &adverse_scenario.)
259 , analysis_run_nm = &analysis_run_name.
260 , cycle_nm = &cycle_name.
261 , outVarStatus = status
262 );
263
264 %if %rsk_dsexist(RISKAGG_SUMM_ENTITY) and (&status. = Successful) %then %do;
265 /* Refresh the Star Schema Views */
266 %irmc_refresh_lasr_schema_view(lasr_lib = &lasr_libref.
267 , mart_table_name = &solutionId._CAPITAL_ADEQUACY_SUMMARY
268 , rls_table_name = &solutionId._CAPITAL_ADEQUACY_SUMMARY_RLS
269 , meta_repository = &meta_repository.
270 , lasr_library_name = &lasr_library_name.
271 , lasr_meta_folder = &lasr_meta_folder.
272 );
273 %end;
274 %end;
275 %end;
276%mend store_results;
277%store_results;
278
279/* Update the Cycle control table */
280%irmc_update_ctrl_table(cycle_id = &cycle_key.
281 , analysis_run_id = &analysis_run_key.
282 , dr_libref = &dr_libref.
283 , entry_type = RGF
284 , entry_id = &analysis_run_key.
285 , entry_name = Risk Aggregation
286 , entry_location = analysisRuns
287 );