Resources

SAS Products

SAS Risk Dimensions - Stressing Instrument and Counterparty Variables



Objective

Set Up Your Environment

Register Your Portfolio Data

Register Market Data

Define Valuation Methods

Specify the Analysis and Create the Project

Run the Project

View Results

Example Code (ZIP file)



Objective

This example demonstrates how to stress instrument and counterparty variables the same way that you can stress risk factor variables. Stresses can be defined as relative changes, absolute changes, or value changes.

This example demonstrates this capability in the context of credit risk (See "Assessing Credit Risk"). You stress the instrument variables' contract price and interest rate. Here interest rate is an instrument variable rather than a risk factor. You also stress the counterparty variable loss given default (LGD).



Set Up Your Environment

First, set up the library for analysis and the name of the SAS Risk Dimensions environment. Use the directory C:\users\sasdemo\RD_Examples. You can assign the libref to any path as long as you have Write access to that directory.

libname RDExamp "C:\users\sasdemo\RD_Examples";
%let test_env = instscen;

In this code, you use the SAS Macro Language Facility to create the macro variable test_env. You assign the value instscen to the variable test_env. Using macro variables in this way gives you the flexibility to change the physical location of the target library and environment name in just two lines of code.

Next, create a new SAS Risk Dimensions environment assigned the name instscen in the library RDExamp.

proc risk;
env new=RDExamp.&test_env;
env save;
run;


Register Your Portfolio Data

Next, define the assets in your portfolio and provide information about the counterparty. The following code creates a data set called instdata that stores information about the forward agreement in your portfolio. It specifies the characteristics of the instrument:

data RDExamp.instdata;
format maturity date9.;
length insttype $12. cpty_name $16. contract_type $16.;
input insttype $ instid $ cpty_name $ CounterpartyID $ maturity date9.
int_rate contract_type $ contract_price holding;
datalines;
FwdContract instid1 CounterPartyA cptyid1 01JUL2014 0.02 TechCompany 20 1000
;

The following code creates the data set cptydata that stores information about the counterparty including the counterparty's current credit rating, which is BBB.

data RDExamp.cptydata;
length CounterPartyType $16. cpartyname $16. rating $3.;
input CounterPartyType $ CounterpartyID $ cpartyname $ rating $ loss_default;
datalines;
MidGrade_Cpty cptyid1 CounterPartyA BBB 0.20
;

The following code registers the instrument data and counterparty data in the environment. It also defines the output variable creditloss, the value of which is computed in the pricing method.

proc risk;
env open=RDExamp.&test_env;
instdata Instruments file=RDExamp.instdata format=simple;
cptydata Counterparties file=RDExamp.cptydata;
declare
instvars = (
cpty_name char 16 var,
maturity num var,
int_rate num var,
contract_type char 16 var,
contract_price num var
)
cptyvars = (
rating char 3 var,
cpartyname char 16 var,
loss_default num var,
prob_default num computed
)
outvars = (creditloss num computed comptype = exposure)
;
env save;
run;


Register Market Data

Next, define current risk factor values and create the scenario data sets for the instrument and counterparty variable stresses.

data RDExamp.mktdata;
TEC = 19.75;
run;

data RDExamp.ContractPrice;
_name_ = "contract_price";
_value_ = -0.10;
_type_ = "abs";
run;

data RDExamp.LossDefault;
_name_ = "loss_default";
_value_ = 0.5;
_type_ = "value";
run;

The code below identifies the risk factors that affect the value of your portfolio and the credit worthiness of the counterparty. It registers the market data in the environment. It also defines the instrument and counterparty stresses as scenarios. The stresses can be specified as scenario data sets or can be specified using the changes option in the SCENARIO statement. You do both in this example. When you specify an instrument or counterparty stress, the stress is applied to all instruments or counterparties.

proc risk;
env open=RDExamp.&test_env;
declare riskfactors =(TEC num var label = "TechCompany Share Price");
marketdata Market file=RDExamp.mktdata type=current;
marketdata ContractPrice_Dec10Pct file=RDExamp.ContractPrice
type=scenarioanalysis;
marketdata LossDefault_40 file=RDExamp.LossDefault
type=scenarioanalysis;
scenario LossDefault_100 changes=(loss_default .8)
type=abs outvars = (PL Exposure CreditLoss);
scenario ContractPrice_18_IntRate_05
changes=(contract_price 18 value, int_rate .05 value)
outvars = (PL Exposure CreditLoss);
scenario ContractPrice_Dec10Pct
data=ContractPrice_Dec10Pct
outvars = (PL Exposure CreditLoss);
scenario LossDefault_40 data=LossDefault_40
outvars = (PL Exposure CreditLoss);
env save;
run;


Define Valuation Methods

Next, create both a scoring method and a pricing method. The scoring method is used to calculate probability of default and loss given default based on the current credit rating of the counterparty. The outputs of the scoring method are then used in the pricing method to calculate the output variable creditloss. Create methods using the COMPILE procedure, which is similar to and supports the functionality and syntax of the FCMP procedure. For more information, see the SAS Risk Dimensions and SAS High-Performance Risk: Procedures Guide.

proc compile env=RDExamp.&test_env outlib=RDExamp.&test_env;
method Score_Method kind = scoring;
if rating = 'BBB' then do;
prob_default = .10;
end;
else do;
prob_default = .15;
end;
endmethod;

method Fwd_Contract kind=price;

time_yrs = (maturity - _date_)/365.25;
curr_fwd = TEC * exp(int_rate * time_yrs);
_value_ = (curr_fwd - contract_price)*exp(-1 * int_rate * time_yrs); creditloss = max(0,_value_) * loss_default * prob_default ;
endmethod;
run;

Use the COUNTERPARTY statement to assign the scoring method to the counterparty type MidGrade_Cpty. Identify the counterparty variables needed for scoring by specifying the variables option. Use the INSTRUMENT statement to assign the pricing method to the instrument type FwdContract and to identify the instrument variables needed for pricing.

proc risk;
env open=RDExamp.&test_env;
counterparty MidGrade_Cpty variables = (rating, prob_default, loss_default)
method = Score_Method;
instrument FwdContract variables=(int_rate, maturity, contract_price,
counterpartyid, holding) methods=(Price Fwd_Contract);
env save;
run;


Specify an Analysis and Create the Project

Set up a project to calculate the portfolio mark-to-market (MtM) value and to calculate the portfolio value under the stress scenarios. The following code creates a portfolio file from the instrument data set and identifies the cross classifications for portfolio aggregation. The scenarios are specified in the analysis option of the PROJECT statement. MtM is calculated by default. Note that you do not specify a run date, so the base case date is today and horizon one is the following business day.

proc risk;
env open=RDExamp.&test_env;
sources DataSources (Instruments Counterparties);
read sources=DataSources out=Portfolio;
crossclass InstScenCC (Insttype);
project Project
analysis=(LossDefault_100 ContractPrice_18_IntRate_05
ContractPrice_Dec10Pct LossDefault_40)
portfolio=Portfolio
crossclass=InstScenCC
data=( Market )
;
env save;
run;


Run the Project

Run the project, putting output files in the InstScen subdirectory of the environment.

proc risk;
env open=RDExamp.&test_env;
runproject Project
out=InstScen
options=(outall)
;
env save;
run;


View Results

Next, analyze your results. You can perform analysis on SAS data sets output from the project.

The following figure shows the Scen data set. This data set contains the output variable values for each of the scenarios and for the base case.


Scen data set




Back to Examples index page