Resources

SAS Products

SAS Risk Dimensions - Assessing Market Risk



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

In the following exercise, you create a portfolio that consists of shares of stock in two companies. You run a simulation of stock prices based on the known variances and covariances of the stock price returns. Then you calculate risk statistics based on the simulated portfolio values.



Set Up Your Environment

First, specify 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 = marketrisk;

In this code, you use the SAS Macro Language Facility to create the macro variable test_env. You assign the value marketrisk 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 named marketrisk in the library RDExamp.

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


Register Your Portfolio Data

Next, describe the assets in your portfolio. The following code creates a data set called instdata that stores information about the two instruments in your portfolio. There are three instrument variables: InstType, InstID, and Holding.

data RDExamp.instdata;
input insttype $12. instid $8. holding;
datalines;
TechCompany instid1 1000000
BankCompany instid2 1000000
;

The following code registers the instrument data in the environment.

proc risk;
env open=RDExamp.&test_env;
instdata Instruments file=RDExamp.instdata format=simple;
env save;
run;


Register Market Data

There are two risk factors, TEC and BNK, which represent the prices of TechCompany stock and BankCompany stock. Define the current risk factor values and covariances. Declare the risk factors and register the market data in the environment.

data RDExamp.mktdata;
TEC=15;
BNK=30;
run;

data RDExamp.covdata;
length _name_ _type_ $8;
_type_ = "COV";
input _name_ $ TEC BNK;
datalines;
TEC .0004 .00006
BNK .00006 .0001
;

proc risk;
env open=RDExamp.&test_env;
declare riskfactors=(TEC num var, BNK num var);
marketdata Market file=RDExamp.mktdata type=current;
marketdata Cov file=RDExamp.covdata type=covariance; env save;
run;



Define Valuation Methods

Create pricing methods using the COMPILE procedure for use in this environment. The COMPILE procedure is similar to and supports the functionality and syntax of the FCMP procedure. For more information, see the SAS Risk Dimensions: Procedures Guide.

Tell the RISK procedure which pricing methods to use for each of the instrument types through assignment in the INSTRUMENT statement. Also specify the instrument variables needed for pricing; insttype and instid do not need to be specified as they are included by default.

proc compile env=RDExamp.&test_env outlib=RDExamp.&test_env;
method Tech_Price kind=price;
_value_ = TEC;
endmethod;
method Bank_Price kind=price;
_value_ = BNK;
endmethod;
run;

proc risk;
env open=RDExamp.&test_env;
instrument TechCompany methods=(Price Tech_Price) variables = (holding);
instrument BankCompany methods=(Price Bank_Price) variables = (holding);
env save;
run;



Specify the Analysis and Create the Project

Set up an analysis project to simulate values for your portfolio based on the current market data and the covariance data. The following code creates a portfolio file from the instrument data set and identifies the cross classifications for portfolio aggregation. Then it creates a covariance simulation analysis. Lastly, it creates the project, specifying the portfolio and assigning the covariance simulation analysis.

proc risk;
env open=RDExamp.&test_env;
sources InstDataSource (Instruments);
read sources=InstDataSource out=Portfolio;
crossclass MarketRiskCC (Insttype);
simulation Covariance method=covariance
ndraws=50000
outvars=(pl)
data=Cov;
project Project
analysis=(Covariance)
portfolio=Portfolio
crossclass=MarketRiskCC
data=( Market );
env save;
run;


Run the Project

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

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


View Results

You can explore the results using the SAS Risk Dimensions GUI. From here you can view data sets and perform analysis with JMP. For more information, see the SAS Risk Dimensions: Userís Guide.

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.

SimStat data set


Here is the SimValue data set. Here you can inspect observations for each simulation of each cross classification.

SimValue data set


The following JMP plot compares the Contribution Value at Risk statistic from the SimStat data set.

Contribution Value at Risk statistic from the SimStat data set


In the JMP plots that follow, the first is a density plot, which is a representation of the probability density function and the green line represents the Value at Risk. The second plot shows a histogram plot, this compares the frequency of simulated values. The histogram plot leverages the distribution analysis tools available with JMP so you can perform analysis such as fitting a distribution to the data.

JMP plots




Back to Examples index page