SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_market_agg_bep_analysis.sas
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 SAS Institute Inc. Cary, NC, USA
3 */
4
5/**
6 \file
7\anchor irmst_market_agg_bep_analysis
8 \anchor irmst_market_agg_bep_analysis_key
9
10 \brief It stresses risk measurements (VaR, EC and Expected Shortfall) at the aggregate level
11
12 \param[in] ds_in_portfolio Input portfolio table.
13 \param[in] ds_in_projection Input projection table. Provides assumptions about future volumes for each portfolio segment
14 \param[out] ds_out Output table containing the stressed exposure.
15 \param[in] target_var Name of the target variable that must satisfy the projection requirements specified by the <i>DS_IN_PROJECTION</i> table
16 \param[in] absoluteValue_var Nmae of the variable containing the absolute BEP changes with respect to the base period
17 \param[in] by_vars Space separated list of variables that define the segmentation. A separate Copula analysis is performed for each distinct segmentation
18 \param[in] id_var Name of the primary key (Identifier) variable in the <i>DS_IN_PORTFOLIO</i> table.
19 \param[in] horizon_var Name of the horizon variable in the <i>DS_IN_PROJECTION</i> table.
20 \param[in] scenario_var (Optional) Name of the scenario variable in the <i>DS_IN_PROJECTION</i> table.
21 \param[in] debug Debug mode: True/False. If True, intermediate temporary tables are preserved. (Default: false)
22 \details
23
24 \ingroup DynamicPortfolio
25
26 \author SAS Institute INC.
27 \date 2021
28
29*/
30
31
32%macro irmst_market_agg_bep_analysis( ds_in_portfolio =
33 , ds_in_projection =
34 , ds_out =
35 , target_var =
36 , absoluteValue_var =
37 , by_vars =
38 , id_var =
39 , horizon_var =
40 , scenario_var =
41 , debug =false
42 );
43
44 %local
45 ;
46
47 %put NOTE: The market risk analysis will be stressed at the aggregate level.;
48
49 %if %UPCASE(&target_var.) NE EXPOSURE_DELTA_MULTIPLIER %then %do;
50 %put ERROR: the model defined in irmst_market_agg_bep_analysis.sas requires the BEP to be defined on the variable EXPOSURE_DELTA_MULTIPLIER.;
51 %return;
52 %end;
53
54 /*Do we have by-variables? If so set the corresponding flag.*/
55 %if (%sysevalf(%superq(by_vars) ne, boolean)) %then %do;
56 %let byvars_flg = Y;
57 %end;
58 %else %do;
59 %let byvars_flg = N;
60 %end;
61
62 /*Do we have a scenario var? If so set the corresponding flag.*/
63 %if (%sysevalf(%superq(scenario_var) ne, boolean)) %then %do;
64 %let scenario_flg = Y;
65 %end;
66 %else %do;
67 %let scenario_flg = N;
68 %end;
69
70 /* Create an unquoted list of the by variables separated by commas */
71 %let unquoted_csv_byvar_list = %sysfunc(prxchange(s/\s+/%str(, )/i, -1, &by_vars.));
72 /* Create a quoted list of the by variables separated by commas */
73 %let quoted_csv_byvar_list = %sysfunc(prxchange(s/(\w+)/"$1"/i, -1, %bquote(&unquoted_csv_byvar_list.)));
74
75 /*sort projection table*/
76 proc sort data = &ds_in_projection
77 out = _tmp_analysis_proj_srt_;
78 by &by_vars. &scenario_var. &horizon_var.;
79 run;
80
81 /*If the user did not specify a scenario var, add a temporary one*/
82 %if (&scenario_flg. = N) %then %do;
83 %let scenario_var=_tmp_scenario_var_;
84 data _tmp_analysis_proj_srt_;
85 length &scenario_var. $32.;
86 set _tmp_analysis_proj_srt_;
87 &scenario_var.="_tmp_scenario_name_";
88 run;
89 %end;
90
91 /*Sort the original data-set*/
92 proc sort data=&ds_in_portfolio.
93 out=_tmp_analysis_ds_in_;
94 by &by_vars. &scenario_var. forecast_time;
95 run;
96
97 /*Check that the projection table is not empty*/
98 proc sql noprint;
99 select count(*) into: proj_cnt
100 from _tmp_analysis_proj_srt_;
101 quit;
102
103 %if &proj_cnt.<1 %then %do;
104 %put ERROR: Not enough valid projections: skip the market risk stress analysis.;
105 %return;
106 %end;
107
108 data &ds_out.;
109 set _tmp_analysis_ds_in_;
110 length changeType $10.;
111 by &by_vars. forecast_time;
112 if _N_=1 then do;
113 declare hash h(dataset: "_tmp_analysis_proj_srt_(rename=(&horizon_var.=forecast_time)");
114 h.definedata("&absoluteValue_var.","changeType");
115 h.definekey(&quoted_csv_byvar_list.,"forecast_time");
116 h.defineDone();
117 end;
118 call missing(&absoluteValue_var.);
119 rc=h.find();
120 bep_factor=1;
121 if changeType="abs_add" then do;
122 if absoluteValue ne 0 and forecast_time=0 then do;
123 put "ERROR: EXPOSURE_DELTA_MULTIPLIER must be 0 in the market Business Evolution Plan for forecast time 0 if change type is 'Absolute'";
124 abort cancel;
125 end;
126 /*For absolute BEP assumption we use bep_factor=(1+BEP_assumption)*/
127 bep_factor=(1+COALESCE(&absoluteValue_var.,0));
128 end;
129 else do;
130 if changeType="rel_add" then do;
131 if absoluteValue ne 1 and forecast_time=0 then do;
132 put "ERROR: EXPOSURE_DELTA_MULTIPLIER must be 1 in the market Business Evolution Plan for forecast time 0 if change type is 'Relative'";
133 abort cancel;
134 end;
135 /*For relative BEP assumption we use bep_factor=BEP_assumption*/
136 bep_factor=COALESCE(&absoluteValue_var.,0);
137 end;
138 end;
139 ValueAtRisk =ValueAtRisk *bep_factor;
140 Component_ValueAtRisk =Component_ValueAtRisk *bep_factor;
141 ExpectedShortfall =ExpectedShortfall *bep_factor;
142 Component_ExpectedShortfall =Component_ExpectedShortfall*bep_factor;
143 Economic_Capital =Economic_Capital *bep_factor;
144 Component_Economic_Capital =Component_Economic_Capital *bep_factor;
145 EXPECTEDLOSS =EXPECTEDLOSS *bep_factor;
146 drop rc changeType bep_factor;
147 run;
148
149 /* General clean-up */
150 %if %upcase(&debug.) ne TRUE %then %do;
151 proc datasets library = work nolist nodetails;
152 delete
153 _tmp_analysis_proj_srt_
154 _tmp_analysis_ds_in_
155 ;
156 quit;
157 %end;
158
159%mend;
160
161
162