SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_create_loss_dist_summary.sas
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 SAS Institute Inc. Cary, NC, USA
3*/
4
5/**
6 \file
7\anchor irmst_create_loss_dist_summary
8
9 \brief Create a loss distribution summary table from a value_at_risk_detail table.
10
11 \param [in] host Host url, including the protocol
12 \param [in] server Name of the Web Application Server that provides the REST service (Default: SASRiskGovernanceFramework)
13 \param [in] port Server port (if blank, default port 80 will be used). Default: 7980
14 \param [in] username Username credentials
15 \param [in] password Password credentials: it can be plain text or SAS-Encoded (it will be masked during execution).
16 \param [in] authMethod: Authentication method (accepted values: TOKEN/SSO). Used when Username/Password credentials are left blank to determine the authentication method. (Default: TOKEN).
17 \param [in] tgt_ticket Ticket granting ticket. If provided, this TGT ticket is used to obtain a Service ticket for the requested REST resource
18 \param [in] name Name of the instance of the RGF object that is created with this REST request
19 \param [in] description Description of the instance of the RGF object that is created with this REST request
20 \param [in] cred_risk_detail_key The Rk of the credit_risk_detail table
21 \param [in] analysis_run_key The Rk of the anaysis run that created the credit risk detail table (ignored if cred_risk_detail_key is specified)
22 \param [in] base_date baseDate for the analysis data object
23 \param [in] cycle_id = cycle ID if linking to an analysis run
24 \param [in] entity_id = entity ID for the analysis data object
25 \param [in] status_cd = status code for the analysis data object
26 \param [in] schema_name The schema name of the data definition to link to.
27 \param [in] schema_version The schemaVersion of the data definition to link to.
28 \param [in] libref = irm_rgf_store_analysis_data arg
29 \param [in] logOptions Logging options (i.e. mprint mlogic symbolgen ...)
30 \param [in] restartLUA. Flag (Y/N). Resets the state of Lua code submission for a SAS session if set to Y (Default: Y)
31 \param [in] clearCache Flag (Y/N). Controls whether the connection cache is cleared across multiple proc http calls. (Default: Y)
32 \param [out] out_exceptions = irm_rgf_store_analysis_data arg
33 \param [out] out_analysis_data = irm_rgf_store_analysis_data arg
34 \param [out] out_partition_list = irm_rgf_store_analysis_data arg
35 \param [out] out_data_definition = irm_rgf_store_analysis_data arg
36 \param [out] out_link_instance = irm_rgf_store_analysis_data arg
37 \param [out] outVarTicket Name of the output macro variable which will contain the Service Ticket (Default: ticket)
38 \param [out] outSuccess Name of the output macro variable that indicates if the request was successful (&outSuccess = 1) or not (&outSuccess = 0). (Default: httpSuccess)
39 \param [out] outResponseStatus Name of the output macro variable containing the HTTP response header status: i.e. HTTP/1.1 200 OK. (Default: responseStatus)
40
41 \ingroup econSim
42
43 \author SAS Institute Inc.
44 \date 2020
45*/
46%macro irmst_create_loss_dist_summary(host =
47 , server = SASRiskGovernanceFramework
48 , solution = rmc
49 , port = 7980
50 , username =
51 , password =
52 , authMethod = token
53 , tgt_ticket =
54 , name =
55 , description =
56 , risktype =
57 , cred_risk_detail_key =
58 , analysis_run_key =
59 , base_date =
60 , cycle_id =
61 , entity_id =
62 , status_cd =
63 , libref =
64 , schema_name =
65 , schema_version =
66 , out_exceptions =
67 , out_analysis_data = out_analysis_data
68 , out_partition_list =
69 , out_data_definition =
70 , out_link_instance =
71 , outVarTicket = ticket
72 , outSuccess = httpSuccess
73 , outResponseStatus = responseStatus
74 , logOptions =
75 , restartLUA = Y
76 , clearCache = Y
77 );
78
79 /* Initialize outputs */
80 %let &outVarTicket. =;
81 %let &outSuccess. = 0;
82 %let &outResponseStatus. =;
83
84 /* Set the required log options */
85 %if(%length(&logOptions.)) %then
86 options &logOptions.;
87 ;
88
89 /* Get the current value of mlogic and symbolgen options */
90 %local oldLogOptions;
91 %let oldLogOptions = %sysfunc(getoption(mlogic)) %sysfunc(getoption(symbolgen));
92
93 %if(%length(&port.) = 0) %then
94 %let port = 80;
95
96 %let ticket = ;
97 /* If analysus run key passed in, find the key for the credit risk detail table */
98 %if &cred_risk_detail_key. eq %str() %then %do;
99 %irm_rest_get_rgf_analysis_data(host = &host.
100 , server = &server.
101 , solution = &solution.
102 , port = &port.
103 , tgt_ticket = &tgt_ticket.
104 , filter = filter=hasObjectLinkTo('%upcase(&rgf_solution.)','analysisData_analysisRun_out',&analysis_run_id.,0)
105 , outds = _analysis_data
106 , outVarTicket = &outVarTicket.
107 , outSuccess = &outSuccess.
108 , outResponseStatus = &outResponseStatus.
109 , restartLUA = &restartLUA.
110 , clearCache = &clearCache.
111 );
112 data _null_;
113 set _analysis_data;
114 call symputX('cred_risk_detail_key',key);
115 run;
116 %end;
117
118 /*Fetch the credit risk detail table */
119 %irm_rgf_retrieve_analysis_data(key = &cred_risk_detail_key.
120 , outds = _cred_rsk_detail
121 , host = &host.
122 , server = &server.
123 , solution = &solution.
124 , port = &port.
125 , outSuccess = &outSuccess.
126 , outResponseStatus = &outResponseStatus.
127 , restartLUA = &restartLUA.
128 , clearCache = &clearCache.
129 );
130
131 /*Process the Loss Distribution Detail table in order to extract the required information for the Loss Distribution Summary table*/
132 proc sql noprint;
133 create table _loss_summary as
134 select
135 min(ValueAtRisk_Alpha) as ValueAtRisk_Alpha,
136 min(entity_id) as entity_id,
137 "&risktype." as risk_type,
138 min(reporting_dt) as reporting_dt,
139 min(scenario_id) as scenario_id,
140 sum(ExpectedLoss) as ExpectedLoss,
141 sum(Component_ValueAtRisk) as ValueAtRisk,
142 case
143 %if &risktype.=Credit %then %do;
144 when sum(Component_ValueAtRisk)<0 then 0
145 when sum(ExpectedLoss)>0 then max(sum(Component_ValueAtRisk)-sum(ExpectedLoss),0)
146 when sum(ExpectedLoss)<=0 then sum(Component_ValueAtRisk)
147 else 0
148 %end;
149 %else %do;
150 when sum(Component_ValueAtRisk)<0 then 0
151 else sum(Component_ValueAtRisk) /*sum(ExpectedLoss)<=>0*/
152 %end;
153 end as Economic_Capital
154 from _cred_rsk_detail
155 %if &risktype.=Market %then %do;
156 where simulationpart="Profit and Loss"
157 %end;
158 group by SCENARIO_ID
159 ;
160 run;
161
162 /* Store the result */
163 %irm_rgf_store_analysis_data(ds_in = _loss_summary
164 /* Analysis Data Parameters */
165 , analysis_data_name = &name.
166 , analysis_data_desc = &description.
167 , base_date = &base_dt.
168 , cycle_id = &cycle_id.
169 , entity_id = &entity_id.
170 , status_cd = &status_cd.
171 , analysis_run_id = &analysis_run_key.
172
173 /* Data Definition Parameters */
174 , libref = &libref.
175 , schema_name = &schema_name.
176 , schema_version = &schema_version.
177
178 /* Output tables */
179 , out_exceptions = &out_exceptions.
180 , out_analysis_data = &out_analysis_data.
181 , out_partition_list = &out_partition_list.
182 , out_data_definition = &out_data_definition.
183 , out_link_instance = &out_link_instance.
184
185 /* Connection Parameters */
186 , host = &host.
187 , server = &server.
188 , solution = &solution.
189 , port = &port.
190 , tgt_ticket = &tgt_ticket.
191 , outVarTicket = &outVarTicket.
192 , outSuccess = &outSuccess.
193 , outResponseStatus = &outResponseStatus.
194 );
195
196 /* Check for errors */
197 %if(not &&&outSuccess. or not %rsk_dsexist(&out_analysis_data.)) %then %do;
198 %put ERROR: Something went wrong when trying to create the loss distribution summary table.;
199 %return;
200 %end;
201
202%mend;