**Overview of the Coupon Bond Portfolio Example**

**Create Instrument Types and Register the Instrument Data**

**Create Analysis Specifications**

**Create and Run an Analysis Project**

- Overview to Viewing Results
- View Mark-to-Market Analysis Results
- View Profit/Loss Analysis Results
- View Sensitivity Analysis Results

**Perform a VaR Analysis of a Coupon Bond Portfolio**

- Overview of VaR Analysis
- Create Fitted Models
- Overview to Creating Fitted Models
- Model 1: Mean Model
- Model 2: Difference Model

- Create a Delta-Normal Analysis Specification
- Create a Monte Carlo Analysis Specification
- Create and Run Analysis Projects
- View Results
- View Delta-Normal Analysis Results
- Monte Carlo Simulation Results (Mean Model)
- Monte Carlo Simulation Results (Difference Model)

**Perform a Cash Flow Analysis of a Coupon Bond Portfolio**

- Overview of Analysis
- Create Instrument Data
- Create a Time Grid and Cross-Classification Specification
- Create and Register a Cash Flow Instrument
- Create a Static Cash Flow Analysis Specification
- Create a Covariance Simulation Analysis Specification
- Create and Run an Analysis Project
- View Results

In this example, you create and analyze a portfolio of coupon bonds. Coupon bonds entitle a bond holder to receive cash payments in specified time periods in addition to repayment of the principal. The risk factors that affect portfolio value are short-term interest rates, intermediate-term interest rates, long-term interest rates, and exchange rates.

The risk analyses that you perform are as follows:

Analysis |
Description |

mark-to-market (MtM) | Given the required pricing information, what is the market value of these bonds? |

sensitivity | To which risk factors is the value of these bonds most sensitive? |

profit/loss curves | How does the value of these bonds vary when each risk factor varies? |

profit/loss surfaces | How does the value of these bonds vary when a pair of risk factors vary? |

scenario | Given pricing information that corresponds to a specific scenario, what is the market value of these bonds? |

Monte Carlo | Given simulation models for the risk factors, how does the portfolio value change with different simulated risk factor values? Specifically, what is the value at risk (VaR) for the 1% worst-case scenario? |

**Note:** Throughout this example, code samples are provided to show how to code specific program elements. Do not run these samples by themselves. Run the program provided in the ZIP file..

- 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.
/* Define the working directory */ %let loc = C:\Users\sasdemo\RD_Examples ; libname rdexamp "&loc";

- Set up instrument data, which provides values for instrument attributes such as a maturity date, and market data, which provides values for risk factors such as interest rates or exchange rates.
The following code creates sample instrument and market data:

/* Create sample instrument data*/ data RDexamp.Inst_Data; informat Mat_Date date7.; format Mat_Date date7.; length Currency $3.; input InstType $ InstID $ Par_LC Coup_Freq Coupon Mat_Date Company $ Currency $; datalines; CoupBond bond1 100000 6 0.05 01JAN15 EuroCorp EUR CoupBond bond2 100000 6 0.05 01JAN16 BritCorp GBP CoupBond bond3 100000 6 0.05 01JAN17 AmerCorp USD ;

The following code fragment declares instrument variables:

/* Declare Instrument Variables */ declare instvars = ( Par_LC num var label = "Par Value (Local Currency)", Coup_Freq num var label = "Coupon Frequency", Coupon num var label = "Coupon Rate", Mat_Date date var label = "Maturation Date", Company char 15 class label = "Issuing Company" );

Risk factor variables are those that affect the value of the defined financial instruments in the portfolio. The portfolio consists of three bonds: one denominated in euros (EUR), one denominated in British pounds (GBP), and one denominated in US dollars (USD). Therefore, the analysis of the portfolio requires interest rates for each bond, a dollar-euro exchange rate, and a dollar-pound exchange rate. Any risk factor variable that you create must have a corresponding variable in the market data set.

For SAS Risk Dimensions to run properly, the variable names in the market data set and the risk factor names must be identical. This is true regardless of the order in which you perform the tasks. The following code fragment shows the definition of two risk factors:

/* Declare Risk Factor Variables */ declare riskfactors = ( USD_EUR num FX_Spot fromcur = EUR tocur = USD group = "Risk Factor" label = "USD/EUR Exchange Rate", ... EUR_6M num IR currency = EUR maturity = 6 month group = "Risk Factor" label = "6-month interest rate (EUR)", ...

Reference variables enable you to select values based on the value of an instrument variable. By using reference variables, you can price different instruments of the same type by using a single pricing program.

/* Declare a Reference Variable */ declare reference = ( loccur array IR group = "Risk Factor" label = "Int. Rate Curve in Local Currency" );

Risk factor curves are arrays of risk factors. Use the REFMAP option to define a key to the LOCCUR reference variable.

Suppose that for a specific bond, LOCCUR resolves to the value EUR. In that case, the data array EUR_RATES is selected and the variables EUR_6M and EUR_12M are used to value the bond.

/* Define Risk Factor Curves */ array EUR_Rates IR currency = EUR elements = (EUR_6M EUR_12M) group = "Risk Factor" label = "Euro Interest Rates" refmap = (loccur = "EUR"),

The following SAS statement creates a cross-classification to group bonds by a currency:

/* Create a Cross-Classification */ crossclass cc1 (Currency);

After you declare the variables, create a pricing method by using the COMPILE procedure.

In the SAS program in the ZIP file, the FUNCTION statement starts the creation of a pricing function GovBondPrc. This pricing function uses information about the bond (interest rate and time to maturity) to mark it to the market.

The METHOD statements create the instrument pricing methods Coup_Bond_Prc and CF_Bond_Prc. The Coup_Bond_Prc instrument pricing method uses the GovBondPrc pricing function that you defined
to value the bonds. The CF_Bond_Prc instrument pricing method uses the PV_CashFlow function that is included with SAS Risk Dimensions to find the present value of the cash flows.
For more information about how PV_CashFlow works, see *SAS Risk Dimensions: Procedures Guide*.

After you create the pricing methods, create the instrument types.

The following SAS program creates an instrument type:

proc risk; environment open = RDExamp.Example3; /* Create an Instrument Template */ instrument Bond_Root label = "Bond Common Variables" variables = (currency, holding) defaults = (holding 1); /* Create a Coupon Bond Instrument */ instrument CoupBond label = "Coupon Bond" basetype = Bond_Root variables = (Par_LC, Coup_Freq, Coupon, Mat_Date) methods = (price Coup_Bond_Prc); /* Register the Instrument Data */ instdata Coup_Bond_Data file = RDExamp.Inst_Data format = simple variables = ( Par_LC Coup_Freq Coupon Mat_Date Company ); environment save; run;

The following SAS program statements create a portfolio list and a portfolio file:

proc risk; environment open = RDExamp.Example3; /* Create Portfolio List */ sources Coup_List Coup_Bond_Data; /* Create Portfolio File */ read sources = Coup_List out = Coup_Bond; environment save; run;

The following SAS program registers market data:

proc risk; environment open = RDExamp.Example3; /* Register Market Data */ marketdata Mkt_Data file = RDExamp.Mkt_Data type = current; environment save; run;

Analysis specifications are descriptions of the analyses that are to be performed. An MtM analysis is performed by default. Additional specifications for this example are as follows:

Specification |
Description |

Profit/loss curve | A single risk factor is varied, and the portfolio value for each value of the risk factor is plotted. For example, in the first profit/loss curve specified in the code that follows, the portfolio is valued and plotted for 21 different values of the US 6-month interest rate between 0.5% and 2.5%. |

Profit/loss surface | Two risk factors are varied, and the portfolio value for the value of each risk factor pair is plotted. For example, in the profit/loss surface specified in the code that follows, both the US dollar-British pound exchange rate and the British 12-month interest rate are varied. The portfolio is valued and plotted for each of the 441 (21 x 21 = 441) possible combinations of these risk factors. |

sensitivity | In a sensitivity analysis, various statistics are calculated that enable you to gauge the sensitivity of the portfolio to the risk factors that you specify. |

The following code fragment defines the three analysis specifications described in the table above:

/* Profit/Loss Curve Analysis */ plcurve Bond_Curve curves = (USD_6M min = 0.005 max = 0.025 n = 21 value, USD_12M min = 0.005 max = 0.025 n = 21 value, USD_36M min = 0.015 max = 0.035 n = 21 value); /* Profit/Loss Surface Analysis */ plsurface Bond_Surface USD_GBP (min = 1 max = 2 n = 21 value)* GBP_12M (min = 0.01 max = 0.07 n = 21 value); /* Sensitivity Analysis */ sensitivity Bond_Sensitivity vars = (USD_GBP GBP_6M GBP_12M USD_6M USD_12M USD_36M ) hessian;

An analysis project gathers the elements needed to perform the analyses. In this case, the analysis project includes elements such as the market data, the portfolio file, the analysis specifications, and the cross-classification variable.

The following code fragment creates and runs an analysis project:

/* Create an analysis project */ project Coup_Bonds data = (Mkt_Data) portfolio = Coup_Bond analysis = (Bond_Curve Bond_Surface Bond_Sensitivity ) numeraire = USD crossclass = cc1 rundate = "01NOV14"d out = Bond_Results; /* Run the analysis project */ runproject Coup_Bonds; environment save; run;

After you run the project, view the results using the SAS Risk Dimensions UI. Open the RDExamp.Example3 environment and expand the Results tree. Then, expand the Bond_Results tree. The data files are listed first, and then the reports are listed.

**Analysis Tab**

To view the MtM analysis results:

- Expand the Data Files tree.
- Double-click Summary Results.

You can drag columns within the table to move them to where you want. The MtM analysis results are arranged as follows:

- The first three rows are the analysis of the individual instrument.
- The last row contains the results for the entire portfolio.

**Summary Results—MtM Value**

To view the profit/loss curve analysis results:

- In the Bond_Results tree under Reports, right-click ProfitLoss CurvePlot and select View.
- Select 1. Bond_Curve from the Analysis Name list. You can view the profit/loss associated with changing the US 6-month interest rate.

**ProfitLoss CurvePlot Window – USD_6M — Distribution Tab**

**Profit/Loss Curve Plot Window – USD_6M — Statistics Tab**

To view the profit/loss curve and statistics associated with other interest rates, select a different value for **Analysis Name**

You can also view the profit/loss surface analysis results through JMP. On the **Analysis** tab, click **Analysis in JMP**. The Project Results window appears. Select **PL Surface Plot**.
Click **Run**. The Profit Loss Surface Analysis window appears.

**Profit/Loss Surface Plot in JMP**

For more information about exploring results in JMP, see *Using JMP*.

In the **Bond_Results** tree under **Data Files**, double-click **Sensitivity Analysis**.

In the Sensitivity Analysis table, you can view the portfolio MtM values as well as cross-classification-specific MtM values. In this example, each value of the cross classification variable (Currency) corresponds to a specific bond. In addition, the table provides the following sensitivity measures of price with respect to risk factors: deltas, gammas, and cross-gammas:

The _Type_ variable indicates the type of information that is displayed and takes on the following values:

- VALUE: The MtM values and the base case market value of the risk factors.
- DELTA, GAMMA: Sensitivity measures.

Although the following description focuses on the entire portfolio (the value of Currency is +), similar statements can be made for each level of the cross-classification variable. In the following figure, columns of the Sensitivity Analysis table are reorganized to display the information relevant to this example.

**Sensitivity Analysis Table**

- MtM Values
Row 28 displays the current market value of the risk factors (GBP_12M,GBP_6M, USD_12M, USD_36M,USD_6M, USD_GBP) and the portfolio value that is based on these risk factors.

**Note**: The Sensitivity Analysis table does not display all risk factors, but only those used in the sensitivity analysis. - Delta
- Gamma
- Cross-Gamma

Portfolio value at risk (VaR) is a quantile value of the distribution of profit and loss. For example, if the 95% VaR is $10,000, then over many trials loss is expected to exceed $10,000 only 5% of the time. SAS Risk Dimensions provides several ways to calculate VaR. This example focuses on two methods:

- Delta-Normal analysis assumes that a set of risk factors is jointly normal (or lognormal) with mean 0 and a covariance matrix. It approximates the variance of the distribution of the change in portfolio value. This estimated portfolio variance is used to compute the portfolio VaR.
- Monte Carlo simulation uses models of risk factor behavior to generate predicted values for the risk factors at a specified future date. A complete set of predicted values (that is, one for each risk factor) is a market state, which you use to reprice the portfolio. By generating a large number of market states and the associated portfolio values, you can estimate the distribution of the change in the portfolio value at the time horizon that you specify. You calculate VaR from this estimated distribution. For example, to find the 95% VaR, you select the simulated change in the portfolio value that is exceeded by only 5% of the simulated distribution.

The major steps that are covered in this section are:

- creating fitted models
- creating analysis specifications and running an analysis project
- viewing analysis project results

**Overview to Creating Fitted Models**

Monte Carlo analysis is based on the assumption that the risk factors can be accurately modeled mathematically. Use the MODEL procedure, which provides a wide range of estimation, testing, and output capabilities to estimate these models. In the code that follows, two models are estimated and registered for use.

For additional information about the MODEL procedure, see *SAS/ETS User's Guide*.

**Model 1: Mean Model**

It is assumed that the rate of change of each risk factors is a constant. Under the typical regression assumption of normally distributed errors, this specification implies that the rate of change is normally distributed with a mean equal to the parameter value. If the estimated parameters equal zero, then this model is equivalent to the model used in the delta-normal analysis.

The following code estimates the equations as a system. The fitted model is registered in the environment Example3 as model Mean_Model. The interval in the FIT statement must match the interval of the actual data. In this case, the data is a series of monthly observations. Therefore, the following code sets INTERVAL=MONTH. If the interval was not specified, the default value of INTERVAL=WEEKDAY would be used.

proc model data = RDExamp.Hist_Data; id Date; endo USD_6M USD_12M USD_36M GBP_6M GBP_12M EUR_6M EUR_12M USD_EUR USD_GBP; parms a1-a9; eq.one = (EUR_6M - lag(EUR_6M)) /lag(EUR_6M) - (a1); eq.two = (EUR_12M - lag(EUR_12M))/lag(EUR_12M) - (a2); eq.three = (GBP_6M - lag(GBP_6M)) /lag(GBP_6M) - (a3); eq.four = (GBP_12M - lag(GBP_12M))/lag(GBP_12M) - (a4); eq.five = (USD_6M - lag(USD_6M)) /lag(USD_6M) - (a5); eq.six = (USD_12M - lag(USD_12M))/lag(USD_12M) - (a6); eq.seven = (USD_36M - lag(USD_36M))/lag(USD_36M) - (a7); eq.eight = (USD_EUR - lag(USD_EUR))/lag(USD_EUR) - (a8); eq.nine = (USD_GBP - lag(USD_GBP))/lag(USD_GBP) - (a9); label a1="EUR_6M Mean" a2="EUR_12M Mean" a3="GBP_6M Mean" a4="GBP_12M Mean" a5="USD_6M Mean" a6="USD_12M Mean" a7="USD_36M Mean" a8="USD_EUR Mean" a9="USD_GBP Mean"; fit one two three four five six seven eight nine / outcat = (RDExamp.example3 interval = month modname = Mean_Model modlabel = "Mean Model"); quit;

**Model 2: Difference Model**

The second model assumes that exchange rate values depend on interest rate differentials. Because countries with higher interest rates tend to attract capital, differences in interest rates between countries produce capital flows. These capital flows, in turn, generate movements in exchange rates.

**Note**: This data set does not contain British or euro zone 36-month interest rates. Therefore, the US 36-month interest rate (USD_36M) is included as a level. Also, in the FIT statement,
notice that INTERVAL = MONTH.

/* Create a "difference" model for use in Monte Carlo analysis */ proc model data = RDExamp.Hist_Data; id Date; endo USD_6M USD_12M USD_36M GBP_6M GBP_12M EUR_6M EUR_12M USD_EUR USD_GBP; parms a1-a7 b0-b3 g0-g3; eq.a = (EUR_6M - lag(EUR_6M)) /lag(EUR_6M) - (a1); eq.b = (EUR_12M - lag(EUR_12M))/lag(EUR_12M) - (a2); eq.c = (GBP_6M - lag(GBP_6M)) /lag(GBP_6M) - (a3); eq.d = (GBP_12M - lag(GBP_12M))/lag(GBP_12M) - (a4); eq.e = (USD_6M - lag(USD_6M)) /lag(USD_6M) - (a5); eq.f = (USD_12M - lag(USD_12M))/lag(USD_12M) - (a6); eq.g = (USD_36M - lag(USD_36M))/lag(USD_36M) - (a7); eq.h = USD_EUR - (b0 + b1*(USD_6M-EUR_6M) + b2*(USD_12M-EUR_12M) + b3*USD_36M); eq.j = USD_GBP - (g0 + g1*(USD_6M-GBP_6M) + g2*(USD_12M-GBP_12M) + g3*USD_36M); label a1="EUR_6M Mean" a2="EUR_12M Mean" a3="GBP_6M Mean" a4="GBP_12M Mean" a5="USD_6M Mean" a6="USD_12M Mean" a7="USD_36M Mean" b0="Constant (EUR)" b1="6M Diff (EUR)" b2="12M Diff (EUR)" b3="36M Level (EUR)" g0="Constant (GBP)" g1="6M Diff (GBP)" g2="12M Diff (GBP)" g3="36M Level (GBP)"; fit a b c d e f g h j / outcat = (RDExamp.example3 interval = month modname = Diff_Model modlabel = "Difference Model"); quit;

The following DELTANORMAL statement creates an analysis named Delta, based on Hist_Data. By default, VaR is calculated for one period ahead, where the period is determined by the INTERVAL statement.
Therefore, the interval specified in the DELTANORMAL statement must match the interval specified for the market data. For more information about the DELTANORMAL statement, see
*SAS Risk Dimensions: Procedures Guide*.

proc risk; environment open = RDexamp.example3; /* Create a Delta-Normal analysis */ deltanormal Delta data = Hist_Data interval = month;

In a Monte Carlo analysis, the VaR is calculated by repeatedly simulating the risk factor values according to a fitted model. In SAS Risk Dimensions, this type of analysis is created by the SIMULATION statement with METHOD=MONTECARLO. The following options are specified:

Option |
Description |

INTERVAL | The time interval of the historical data used in the simulation. This interval must match the one that you specified when you registered the historical data. |

SEED | The seed value for random number generation. |

NDRAW | The number of simulations to be performed. |

ERRORMODEL | The distribution from
which the model errors should be drawn. When `ERRORMODEL=ASFIT` ,
the errors for this analysis are the same as those used for the estimation
of the model in the MODEL procedure. |

HORIZON | The date for which
the VaR is calculated. With `INTERVAL=MONTH` ,
setting `HORIZON=1` makes the evaluation
date for the Monte Carlo analysis one month in the future, which is
the same evaluation date as for the Delta-Normal analysis. |

At this point, you have not identified models for use in the Monte Carlo analysis. You can use the same SIMULATION statement for multiple models, which makes it easy to create several
Monte Carlo analyses with the same parameters. You select the models in the PROJECT statement. For more information about the SIMULATION statement, see *SAS Risk Dimensions: Procedures Guide*.

/* Create a Monte Carlo analysis */ simulation MonteCarlo interval = month method = montecarlo seed = 12345 ndraw = 1500 errormodel = asfit horizon = (1);

After you create analysis specifications, you create and run three analysis projects:

- Delta-Normal analysis
- Monte Carlo analysis with the mean model
- Monte Carlo analysis with the difference model

In each case, the numeraire currency is US dollars. Therefore, the values of instruments denominated in other currencies are converted to US dollars before they are reported.

**Note**: Several components such as the market data and the portfolio file were defined and registered earlier in this example.

/* Create an Analysis Project for the */ /* Delta Normal analysis */ project Delta data = (Mkt_Data) portfolio = Coup_Bond_File analysis = (Delta) numeraire = USD crossclass = cc1 rundate = "01NOV14"d out = Delta; /* Create an Analysis Project for the */ /* mean model Monte Carlo */ project MeanMC data = (Mkt_Data Hist_Data) portfolio = Coup_Bond_File analysis = (MonteCarlo) model = (RDexamp.example3.Mean_Model) crossclass = cc1 numeraire = USD rundate = "01NOV14"d out = MeanMC; /* Create an Analysis Project for the */ /* difference model Monte Carlo */ project DiffMC data = (Mkt_Data Hist_Data) portfolio = Coup_Bond_File analysis = (MonteCarlo) model = (RDexamp.example3.Diff_Model) crossclass = cc1 numeraire = USD rundate = "01NOV14"d out = DiffMC;

Use RUNPROJECT statements to run the project and to set options as needed. In this code, the option ALPHA determines the significance level of VaR. That is, by setting ALPHA=0.05, SAS Risk Dimensions returns the 95% VaR.

/* Run an Analysis Project */ runproject Delta options = (alpha = 0.05); runproject MeanMC options = (alpha = 0.05); runproject DiffMC options = (alpha = 0.05); environment save; run;

After you have created and run the analysis projects, view the results in the SAS Risk Dimensions UI. The results of the projects are shown in the **Results** tree on the **Analysis** tab.
Each project has its own heading.

To access the Delta-Normal analysis results:

- Double-click
**Delta**in the**Results**tree. - Expand the
**Data Files**tree. - Double-click
**Summary Results**. The Summary table opens. The following figure displays summary statistics from the delta-normal analysis (columns have been re-arranged):

**Delta-Normal Analysis Results**

Click **OK** to close the analysis results table.

To access the Monte Carlo simulation results based on the mean model:

- Double-click MeanMC in the Results tree.
- Expand the Data Files tree.
- Double-click Simulation Statistics. The Simstat table opens. The following figure shows the Simstat table (columns have been re-arranged).

**Simulation Statistics—Mean Model**

To access the Monte Carlo simulation results based on the mean model:

- Double-click DiffMC in the Results tree.
- Expand the Data Files tree.
- Double-click Simulation Statistics. The Simstat table opens. The following figure shows the Simstat table (columns have been re-arranged).

**Simulation Statistics—Difference Model**

Often, the instruments in a portfolio generate cash flows to and from various counterparties. You should monitor these cash inflows and outflows in order to maintain a stable balance sheet. If the net cash flow at a point in time is negative, additional cash is needed to meet financial obligations. Conversely, if the net cash flow is positive, you might redistribute cash to locations that provide a better return.

Cash flow analysis examines cash inflows and outflows at points in the future to determine net cash flows. SAS Risk Dimensions enables you to perform cash flow analysis for a wide range of instruments using a variety of cash flow analysis methods.

This example focuses on one particular method, a gap analysis. In a gap analysis, cash flows are collected into groups, or cash flow buckets, which represent different time periods. The sum of the positive and negative cash flows in each bucket is treated as a single flow and provides an estimate of the liquidity in each future period.

The method that you choose to value the cash flow buckets depends on the assumptions about the behavior of the risk factors (for example, interest and exchange rates).

- If it is appropriate to assume that risk factors are constant over time, you can use a static approach. In that approach, the current market values of the risk factors are used to value all future periods.
- If the risk factors vary over time, the static approach is not appropriate. For example, because the future values of exchange rates are unknown, the future values of any cash flows to or from other countries cannot be determined exactly. One widely used alternative is to simulate the risk factors based on their past values. From each set of simulated values, known as a market state, cash flow buckets are valued. Repeated simulation generates a distribution for the value of each bucket.

For the instrument data in the coupon bond analysis, you used the SIMPLE format and you defined an individual bond as a single record. The value was determined by a pricing method and the instrument attributes. In this analysis, the instrument data CASH_FLOW format is used. A coupon bond is viewed as a collection of cash flows. Each cash flow is listed separately in the instrument data set.

For example, the bond denominated in British pounds has three coupon payments and the principal payment remaining. SAS Risk Dimensions groups these cash flows by their InstID variable to create a single financial instrument. To create the bond denominated in British pounds, all of the records with INSTID equal to bond3 are used. Here, we include negative cash flows in the portfolio. Two liabilities have been added, bond4 and bond5.

The following variables are required in an CASH_FLOW format data set:

Variable |
Description |

InstType | The instrument type variable |

InstID | The name of the instrument |

_cfcur_ | The currency code of the cash flow |

_cfdate_ | The date of the cash flow |

_cfamnt_ | The amount of the cash flow. This value is positive for receipts and negative for payments. All cash flows should be in their local currency. |

/* Create cash flow data*/ data RDexamp.Inst_Data; informat _cfdate_ date7.; informat Mat_Date date7.; format Mat_Date date7.; format _cfdate_ date7.; length Currency $3.; length _cfcur_ $3.; input InstType $ InstID $ Par_LC Coup_Freq Coupon Mat_Date Company $ Currency $ _cfcur_ $ _cfdate_ _cfamnt_; datalines; CF_Bond bond1 100000 6 0.05 01Jan15 EuroCorp EUR EUR 01Jan15 2500 CF_Bond bond1 100000 6 0.05 01Jan15 EuroCorp EUR EUR 01Jan15 100000 CF_Bond bond2 100000 6 0.05 01Jan16 BritCorp GBP GBP 01Jan15 2500 . . . CF_Bond bond5 50000 3 0.08 01Jan17 SelfCorp USD USD 01Jan17 -50000 ;

For more information about the cash flow instrument data set, see *SAS Risk Dimensions: Procedures Guide*.

Now you create a time grid that defines periods known as buckets. Cash flow buckets can be based on any date.

All cash flows that are in the same bucket are grouped together for the cash flow analysis. For example, you could specify Bucket 1 to contain all cash flows that are 0–6 months from today. You could specify Bucket 2 to contain all cash flows that are 6–12 months from today. Then, if a portfolio has two cash flows occurring at 7 and 8 months in the future, both would be placed in Bucket 2.

**Note**: SAS Risk Dimensions uses CFBucket_1, CFBucket_2, CFBucket_3, and so on, to hold the cash flows. CFBucket_1 holds all cash flows that occur before the simulation run date or for
which no cash flow dates are specified.

In this example, the time grid Grid1 defines the following buckets:

Bucket 1

0–6 months (falls in CFBucket_2)

Bucket 2

6–12 months (falls in CFBucket_3)

Bucket 3

12–18 months (falls in CFBucket_4)

Bucket 4

18–24 months (falls in CFBucket_5)

**Note**: Cash flows before the evaluation date fall in CFBucket_1.

Set the base date for the time grid in the CASHFLOW statement or by using the RUNDATE option in the PROJECT statement. Placement of cash flows into buckets is governed by the value of the CFDIST option to the PROJECT statement. By default, CFDIST = BACKWARD, so when a cash flow falls outside the range defined by a time grid, it is allocated to the previous bucket. Thus, in this case a cash flow of 24.2 months would fall into CFBucket_5.

For more information about the use of CFDIST to place cash flows into buckets, see the *SAS Risk Dimensions: Procedures Guide*.

A cross-classification variable groups instruments based on the value of the specified instrument variable. When you analyze the portfolio, SAS Risk Dimensions performs analyses for each level and combination of the cross-classification specification, in addition to the whole portfolio.

proc risk; /* Create a time grid and a cross-classification */ environment open = RDexamp.example3; /* Create a time grid */ timegrid Grid1 (6 month, 12 month, 18 month, 24 month); /* Create a cross-classification */ crossclass cc2 (Company); /* Save the environment */ environment save; run;

Create a cash flow instrument and register that instrument with SAS Risk Dimensions. Use the INSTRUMENT statement to create the cash flow instrument type CF_Bond. Use the INSTDATA statement to register the CF_Data data set. After you create the instruments and register the instrument data, create a new portfolio file to make the data available for use in cash flow analyses. Use the SOURCES statement to read the instruments and instrument data into the CF_List portfolio list. Use the READ statement to make the portfolio list into a portfolio file, CF_File, which SAS Risk Dimensions can use.

**Note**:

- In the INSTRUMENT statement, set the VALRECORD to CASHFLOWS. This value informs SAS Risk Dimensions that the new instrument contains a list of cash flows. The instrument value is determined from these cash flows by discounting them and converting them into the reporting currency.
- In the INSTDATA statement, set FORMAT=CASH_FLOW. This value matches VALRECORD=CASHFLOWS in the preceding INSTRUMENT statement.

proc risk; environment open = RDExamp.example3; /* Create a Coupon Bond Instrument */ instrument CF_Bond label = "Cash Flow Bond" basetype = Bond_Root variables = (Par_LC, Coup_Freq, Coupon, Mat_Date, Company) valrecord=cashflows methods = (price CF_Bond_Prc); /* Register the Instrument Data */ instdata CF_Data file = RDexamp.Inst_Data format = cash_flow variables = (InstType InstID Par_LC Coup_Freq Coupon Mat_Date Company Currency _cfcur_ _cfdate_ _cfamnt_); environment save; run; proc risk; environment open = RDexamp.example3; /* Create Portfolio List for Bonds */ sources CF_List CF_Data; /* Create Portfolio File for Bonds */ read sources = CF_List out = CF_File; environment save; run;

Specify a cash flow analysis with a CASHFLOW statement. The following CASHFLOW statement creates an analysis named CFStat and specifies the following options:

Option |
Description |

ANALYSIS | The type of cash flow
analysis to be performed. `ANALYSIS=TRADITIONAL` provides
gap analysis of cash flow buckets, durations, and interest incomes.
The ANALYSIS option is required. |

BUCKETTYPE | The cash flow bucketing method. If BUCKETTYPE is specified in a CASHFLOW statement, the CFBUCKET option must be specified in an accompanying PROJECT statement. |

EVALDATE | The evaluation date for the analysis. |

For more information about the CASHFLOW statement, see *SAS Risk Dimensions: Procedures Guide*.

proc risk; environment open = RDExamp.example3; /* Create a traditional analysis */ cashflow cfstat analysis = traditional buckettype = simple evaldate = "01NOV02"d;

A covariance simulation creates market states by simulating risk factors as dependent draws from a normal distribution. You provide the covariance of the distribution in the form of a covariance format market data set.

A covariance simulation is not equivalent to a Delta-Normal analysis. Although both require a covariance matrix, the Delta-Normal analysis is an analytical method that requires only one market state. In contrast, a covariance simulation analysis is a simulation method and therefore requires multiple market states.

In the following code fragment, the SIMULATION statement creates a covariance simulation analysis named COVSIM.

The CASHFLOW statement uses ANALYSIS=COVSIM as the basis of a cash flow analysis named CFCOV.

For more information about covariance simulations, see *SAS Risk Dimensions: Procedures Guide*.

In the following code, the two previously specified analyses are placed in a project named SimProj. The analysis results appear in the output directory CF_Sim.

In the PROJECT statement, the CFBUCKET option specifies the time grid to be used to define the cash flow buckets. By specifying (REL), the time grid dates are measured from the evaluation date. For example, if the evaluation date is November 1, 2002, then the end date of the first element of the time grid Grid1 is 6 months from that date (May 1, 2003). Cash flows that correspond to this grid element fall in CF_Bucket_2.

In the following code fragment, the statement SETOPTIONS ALLCASHFLOW instructs SAS Risk Dimensions to create the ALLCASHFLOW data view.

/* Create a covariance simulation analysis */ simulation covsim method = covariance data = Hist_Data interval = month seed = 12345 ndraw = 1500 horizon = (1); /* Create a cash flow analysis based on COVSIM */ cashflow cfcov analysis = covsim buckettype = simple evaldate = "01NOV02"d;

The ALLCASHFLOW data view contains variables describing the results of your analyses. If you include a simulation analysis, ALLCASHFLOW contains information for every market state that is generated, which can make the size of the data view large.

After you create and run the analysis project, view the results in the SAS Risk Dimensions UI. Find the results in the **Results** tree on the **Analysis** tab. The output
folder is CF_Sim, as you specified in the OUT= option of the PROJECT statement.

To access the static cash flow analysis results:

- Double-click
**CF_Sim**. - Expand the
**Data Files**tree. - Double-click
**Summary Results**. The results table opens.

**Summary Results—Covariance Simulation Analysis**

To access the covariance simulation analysis results:

- Double-click
**Reports**in the**CF_Sim**results tree. - Under Reports, right-click
**Simulation Statistics**and select**View**. The Simulation Statistics window appears. Here, you can view the simulation distribution for the net cash flows for each bucket. - For example, in the
**Analysis Name**field, select the fourth analysis from the menu. The simulation distribution for the net cash flow for the third bucket is displayed.

**Probability Distribution—CFBucket_3**

**Simulation Statistics—CFBucket_3**

Click **OK** to close the Simulation Statistics window.