Specify the Analysis and Create the Project

Risk measures help us understand how data is distributed. A commonly consulted risk measure is expected value, which helps us understand what happens on average. As informative as expected value can be, it can fail to convey the full risk picture. For example, consider two scenarios. In the first, you get $0 with 100% certainty. In the second, you lose $100 50% of the time and win $100 50% of the time. Both scenarios have an expected value of $0, but the second is considerably riskier with regard to loss. We need other risk measures to better understand the occurrence and magnitude of loss.

That is where distortion risk measures prove useful. A distortion risk measure provides the expected value of a probability distribution after it has been altered with a distortion function. Distortion functions essentially re-weight a distribution to put more emphasis on particular outcomes. For example, value at risk (VaR) is a distortion risk measure. The VaR distortion function puts all of the weight on the occurrence of loss at a given percentile and puts no weight on the other outcomes. Conditional value at risk (CVaR) is also a distortion risk measure. Its distortion function assigns equal weights to all loss outcomes worse than a given percentile and zero weight to all other outcomes.

Some common distortion risk measures, including VaR and CVaR, are provided by SAS Risk Dimensions. You can define others and register them in a risk environment.

Suppose you simulate the value of a portfolio that contains two shares of stock (see "Assessing Market Risk" for more information about this simulation). You generate 50,000 market states and calculate the portfolio's value and profit/loss at each market state.

The following figure shows the distribution of simulated losses.

This loss distribution has the corresponding cumulative distribution function (CDF) plotted below. This figure shows the probability that the portfolio loss will be less than or equal to the value on the x-axis. For example, approximately 90% of the losses will be less than $400,000, which means that approximately 10% of the losses will exceed $400,000.

When you use distortion functions to assess risk, you re-weight the distribution to emphasize unfavorable outcomes. The figure below shows the application of the beta distortion function to the CDF. With this transformation, there is now a ~25% chance that the loss exceeds $400,000. The expected loss of the distorted distribution is $107,939 versus the $3,167 expected loss of the original distribution

Different distortion functions distort the CDF in different ways. Further, most distortion risk measures have parameters that affect how the CDF is distorted. For example, by varying the alpha and beta parameters in the beta distortion function, you can choose the type of losses to emphasize.

In the following figure, the beta distortion function illustrated by the green line gives heavier weight to losses greater than $200,000 while the beta distortion function illustrated by the blue line gives more weight to losses less than $200,000.

In the following example, you apply the beta distortion function with an alpha parameter of 0.7 and a beta parameter of 0.5. Because this distortion function is not provided with SAS Risk Dimensions, you need to define it in your environment. For comparison, you examine two familiar built-in distortion risk measures, value at risk (VaR) and conditional value at risk (CVaR).

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 = distortionmeasures;

%let test_env = distortionmeasures;

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

proc risk;

env new=RDExamp.&test_env;

env save;

run;
env save;

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. Use the RISK procedure to register three instrument variables: InstType, InstID, and Holding.

data RDExamp.instdata;

BankCompany instid2 1000000

;

input insttype $12. instid $8. holding;

datalines;

TechCompany instid1 1000000datalines;

BankCompany instid2 1000000

;

proc risk;

env open=RDExamp.&test_env;

instdata Instruments file=RDExamp.instdata format=simple;

env save;

run;
instdata Instruments file=RDExamp.instdata format=simple;

env save;

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;
BNK=30;

data RDExamp.covdata;
TEC .0004 .00006

BNK .00006 .0001

;

length _name_ _type_ $8;

_type_ = "COV";

input _name_ $ TEC BNK;

datalines;

_type_ = "COV";

input _name_ $ TEC BNK;

datalines;

BNK .00006 .0001

;

proc risk;
run;

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;

declare riskfactors=(TEC num var, BNK num var);

marketdata Market file=RDExamp.mktdata type=current;

marketdata Cov file=RDExamp.covdata type=covariance;

env save;

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: User’s Guide*.

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;
_value_ = TEC;

endmethod;

method Bank_Price kind=price;

_value_ = BNK;

endmethod;

proc compile env=RDExamp.&test_env package = pkt1 outlib=RDExamp.&test_env;
run;

function BetaDistortion(x,a,b) label = "Beta Distortion Measure";
endsub;

g = CDF('BETA',x,a,b);

return(g);

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;
instrument TechCompany methods=(Price Tech_Price)variables = (holding);

instrument BankCompany methods=(Price Bank_Price)variables = (holding);

env save;

Set up a project to simulate values for your portfolio based on the current market data and the covariance data. Use the DISTORTION statement to specify distortion risk measures. The distortion risk measures are output to the SimStat data set.

proc risk;
run;

env open=RDExamp.&test_env;

sources InstDataSource (Instruments);

read sources=InstDataSource out=Portfolio;

crossclass InstTypeCC (Insttype);

simulation Covariance method=covariance

sources InstDataSource (Instruments);

read sources=InstDataSource out=Portfolio;

crossclass InstTypeCC (Insttype);

simulation Covariance method=covariance

ndraws=50000

outvars=(pl)

data=Cov;outvars=(pl)

distortion DistortionVaR funcname=_var_ funcparm=0.99

desc="Distortion Risk Measure VaR .99";

distortion DistortionCVaR funcname=CVaR95

desc="Distortion Risk CVaR .95";

distortion DistortionBeta funcname=BetaDistortion
funcparm = (.7 .5) desc="Distortion Risk Beta .7 .5";

project Project

analysis=(Covariance)

portfolio=Portfolio

crossclass=InstTypeCC

data=( Market )

;

env save;
portfolio=Portfolio

crossclass=InstTypeCC

data=( Market )

;

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

proc risk;

env open=RDExamp.&test_env;

setoptions keeplib;

runproject Project

run;
setoptions keeplib;

runproject Project

out= DistOut

options=( outall)

;

env save;
options=( outall)

;

Next, analyze your results. You can perform analysis on SAS data sets output from the project and you can view results graphically in the SAS Risk Dimensions GUI. Here is a brief introduction to the
analysis tools. For further information, see the *SAS Risk Dimensions: User’s Guide*.

The following figure shows the SimStat data set generated by the project run. The distortion risk measures specified in the environment appear in the data set.

You can further explore the results of your project through the SAS Risk Dimensions GUI. From there you can view data sets and perform analysis with JMP. For more information, see the
*SAS Risk Dimensions: User’s Guide*.

The following plot generated by JMP compares the distortion risk measures from the SimStat data set.