Specify the Analysis and Create the Project
In this exercise, you examine credit risk, which is the risk of losing money as a function of the creditworthiness of a counterparty. Specifically, you assess the credit risk of a simple forward agreement. A company has agreed to purchase 1000 shares of TechCompany stock at $20 per share from CounterpartyA in July 2014. CounterpartyA is considered a midgrade company with a current credit rating of BBB.
To assess the risk, you simulate 50,000 market states and value the portfolio at each market state over a three-day horizon. Risk measures are computed from the distribution of values. For each market state you calculate the portfolio value, the profit/loss value, and the expected credit loss.
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.
In this code, you use the SAS Macro Language Facility to create the macro variable test_env. You assign the value creditrisk 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 creditrisk in the library RDExamp.
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 $; datalines; |
MidGrade_Cpty cptyid1 CounterPartyA BBB |
; |
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.
Next, identify the risk factors that affect the value of your portfolio and the creditworthiness of the counterparty. Define current risk factor values and the variance-covariance values of the risk factors. Register the market data in the environment.
TEC .02 |
Next, create both a scoring method and a pricing method. The scoring method is used to calculate probability of default (PD) and loss given default (LGD) based on the current credit rating of the counterparty. The outputs of the scoring method are then used by 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: User’s Guide.
Use the COUNTERPARTY statement of the RISK procedure 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.
Set up a project to simulate values for your portfolio based on the current market data and the covariance data. The following code
You need to specify the output variables in the simulation because only Profit/Loss is output by default. Also, to simulate values through time, specify horizons using the HORIZONS option. Specifying HORIZONS = (1 2 3) simulates values one, two, and three weekdays from the base case date. Note that you are not specifying a run date, so the base case date is today and horizon one is the following business day.
Run the project, putting output files in the credit subdirectory of the environment.
Next, analyze your results. You can perform analysis on SAS data sets output from the project.
The following figure shows the SimStat data set. It contains the simulation statistics for the portfolio such as Value at Risk, Expected Shortfall, and Mark to Market.
The following figure shows the SimValue data set. This data set contains the simulated portfolio values.