SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irmst_model_precode_ecl.sas
1/* ******************************************** *
2/* Pre-processing script for the MIP execution *
3/* ******************************************** *
4
5Details:
6 The following SAS macro variables are available to the model at run time:
7 - ticket: SAS authentication service ticket (useful for performing operations that require authentication, i.e. interacting with REST services).
8 - rgf_protocol: Communication protocol (http/https) of the SAS Risk and Governance Framework web application
9 - rgf_host: Hostname of the SAS Risk and Governance Framework web application
10 - rgf_port: Port where the SAS Risk and Governance Framework web application is listening
11 - rgf_service: The service where the SAS Risk and Governance Framework web application is listening
12 - ds_in_portfolio: portfolio table
13 - ds_in_scenario: scenario table
14 - ds_in_counterparty: counterparty table (if used)
15 - ds_in_mitigant: credit risk mitigant table (if used)
16
17 The following libraries are pre assigned:
18 - mipport: MIP portfolio library
19 - mipcpty: MIP counterparty library
20 - mipmit: MIP credit risk mitigant library
21 - mipcf: MIP cashflow library
22 - mippmx: MIP parameter matrix library
23 - mippmx: MIP valueData library
24 - mipfunc: MIP functions library
25
26*/
27
28/* Cashflow data object key */
29%let cashflow_key = ${params.CASHFLOW.key};
30
31/* ******************************************** */
32
33/* Prepare RiskDataMaps parameters for the MIP execution
34 Syntax: <Risk Data Object Name>:<Libname.Dataset> [, <Risk Data Object Name>:<Libname.Dataset>] */
35%let mipParameterMatrices = stresstest_coef : mippmx.st_ecl_parameter_&model_run_key.;
36%let mipCashflows = cashflow_dataset : mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
37
38%macro st_model_prep();
39
40 %local
41 cashflow_flg
42 renameStmt
43 ;
44
45 /* Flag (1/0) to determine if we need to process the cashflow table */
46 %let cashflow_flg = %sysevalf(%superq(cashflow_key) ne, boolean);
47
48 /* Create parameter table for the MIP model */
49 data mippmx.st_ecl_parameter_&model_run_key.;
50 length
51 _NAME_ $100.
52 _VALUE_ 8.
53 ;
54 /* Compute RWA */
55 _NAME_ = "FLAG_RWA_CALCULATION_CMatrix"; _VALUE_ = 1; output;
56 /* Number of credit states */
57 _NAME_ = "STATE_CNT_CMatrix"; _VALUE_ = 9; output;
58 /* Number of active (non-defaulted) credit states */
59 _NAME_ = "ACTIVE_STATE_CNT_CMatrix"; _VALUE_ = 8; output;
60 /* Default credit state */
61 _NAME_ = "DEFAULT_STATE_INDEX_CMatrix"; _VALUE_ = 9; output;
62 /* Use PD at origination to compute the PD deterioration delta */
63 _NAME_ = "FLAG_INITIAL_PD_FROM_PRTF_CMatrix"; _VALUE_ = 1; output;
64 /* Use cashflow data? */
65 _NAME_ = "FLAG_PAYMENTS_AS_CASHFLOWS_CMatrix"; _VALUE_ = &cashflow_flg.; output;
66 run;
67
68 /* Retrieve cashflow data */
69 %if &cashflow_flg. %then %do;
70
71 %let renameStmt = %nrstr(
72 rename
73 cashflow_dt = valDate
74 cashflow_leg = valType
75 cashflow_amt = valAmount
76 ;
77 );
78
79 %let httpSuccess = 0;
80 %let responseStatus =;
81 %irm_rgf_retrieve_analysis_data(key = &cashflow_key.
82 , libref = &dr_libref.
83 , outds = mipcf.cashflow_&base_dt_ymdn._&model_run_key.
84 , outds_partition_list = cashflow_partition_list
85 , out_type = data
86 , custom_code = %superq(renameStmt)
87 , outds_dataInfo = cashflow_dataInfo
88 , outds_dataDef = cashflow_dataDef
89 , host = &rgf_protocol.://&rgf_host.
90 , server = &rgf_service.
91 , solution = &rgf_solution.
92 , port = &rgf_port.
93 , tgt_ticket = &tgt_ticket.
94 , outVarTicket = ticket
95 , outSuccess = httpSuccess
96 , outResponseStatus = responseStatus
97 , restartLUA = Y
98 , clearCache = Y
99 );
100
101 /*It creates the cash-flow data set for the synthetic positions ("Front Book")*/
102 %let reporting_dt=%sysfunc(datepart(&BASE_DTTM.));
103 %irmc_cf_frontbook_generation( ds_in_frontbook = &ds_in_synth_position.
104 , ds_in_cf_config = ST_CFG.SYNTHETIC_TEMPLATE_CF_CONFIG
105 , ds_out = mipcf.frontbook_cf_&base_dt_ymdn._&model_run_key.
106 , balance_var = unpaid_balance_amt
107 , id_var = INSTID
108 , maturity_dt_var = maturity_dt
109 , reporting_dt = &reporting_dt.
110 , interval = ${params.MIPINTERVAL}
111 , debug = FALSE
112 );
113
114 /*It appends the cash-flow for the synthetic instruments to the cash-flow of the portfolio.*/
115 proc append
116 data=mipcf.frontbook_cf_&base_dt_ymdn._&model_run_key.
117 base=mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
118 run;
119
120 %if (%rsk_dsexist(_FRTBK_.short_position) and %rsk_attrn(_FRTBK_.short_position, nlobs) ne 0) %then %do;
121
122 /*It creates the cash-flow data set for the elimnated positions*/
123 %irmc_cf_eliminated_remap( ds_in_cf = mipcf.cashflow_&base_dt_ymdn._&model_run_key.
124 , ds_in_short_position = _FRTBK_.short_position
125 , working_libname = _FRTBK_
126 , ds_out = mipcf.elimnated_CF_&base_dt_ymdn._&model_run_key.
127 );
128
129 /*It appends the cash-flow for the eliminated positions to the cash-flow of the portfolio.*/
130 proc append
131 data=mipcf.elimnated_CF_&base_dt_ymdn._&model_run_key.(drop=ORIG_INSTID)
132 base=mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
133 run;
134
135 %end;
136
137 %end;
138 %else %do;
139 /* Create empty cashflow table */
140 data mipcf.cashflow_&base_dt_ymdn._&model_run_key.;
141 length
142 instid $32.
143 valDate 8.
144 valType $32.
145 valAmount 8.
146 ;
147 stop;
148 run;
149 %end;
150
151%mend;
152
153%st_model_prep();