This Sample describes a historical simulation analysis that is performed with and without using SAS Risk Dimensions. The objective is to show how a historical simulation analysis perturbs risk factors in SAS Risk Dimensions. A simple example is considered. One interval-level and one ratio-level risk factor are analyzed.
The sample is organized as follows:
A historical simulation analysis perturbs risk factors as follows for the two measurement levels of risk factors:
rf_simi = rf_base + (rfi - rfi-1)where:
rf_ denotes a risk factorFor example, if:
simi = simulation replication i
i = ith observation of the historical time series data
rf_base = base-case value of rf
rf0 = 5.25and if rf_base = 5.55, then:
rf1 = 5.30
rf2 = 5.33
...
rf_sim1 = 5.55 + (5.30 - 5.25) = 5.60
rf_sim2 = 5.55 + (5.33 - 5.30) = 5.58
...
rf_simi = rf_base * (rfi / rfi-1)For example, if:
rf0 = 10.00and if rf_base = 11.50, then:
rf1 = 10.25
rf2 = 10.25
...
rf_sim1 = 11.50 * (10.25 / 10.00) = 11.7875
rf_sim2 = 11.50 * (10.25 / 10.25) = 11.50
...
The following SAS code creates historical time series data for two risk factors, y1 and y2. The time series spans 11 weekdays. Variable y1 is to be defined as an interval-level risk factor, and y2 as ratio-level.
Historical Time Series Data Work.Hist_Vals
Obs date y1 y2 1 03JAN2013 5.25 10.00 2 04JAN2013 5.30 10.25 3 07JAN2013 5.33 10.25 4 08JAN2013 5.30 10.50 5 09JAN2013 5.40 10.60 6 10JAN2013 5.45 10.65 7 11JAN2013 5.50 10.75 8 14JAN2013 5.40 10.80 9 15JAN2013 5.35 11.25 10 16JAN2013 5.50 11.50 11 17JAN2013 5.52 11.40
Current Market (Base Case) Data Work.Current
Obs date y1 y2 1 18JAN2013 5.55 11.5
The following SAS code perturbs each set of risk factors, y1 and y2, without using SAS Risk Dimensions. In the first step, the base-case values for each risk factor are extracted and stored in macro variables for easy reference later:
Simulated Risk Factor Values from Historical Simulation Analysis WITHOUT SAS Risk Dimensions
Obs Date Interval-level
Risk Factor y1Ratio-level
Risk Factor y2Additive change
of y1Relative change
of y2Perturbed
value of
y1 base casePerturbed value
of y2 base case1 03JAN2013 5.25 10.00 . . . . 2 04JAN2013 5.30 10.25 0.05 1.02500 5.60 11.7875 3 07JAN2013 5.33 10.25 0.03 1.00000 5.58 11.5000 4 08JAN2013 5.30 10.50 -0.03 1.02439 5.52 11.7805 5 09JAN2013 5.40 10.60 0.10 1.00952 5.65 11.6095 6 10JAN2013 5.45 10.65 0.05 1.00472 5.60 11.5542 7 11JAN2013 5.50 10.75 0.05 1.00939 5.60 11.6080 8 14JAN2013 5.40 10.80 -0.10 1.00465 5.45 11.5535 9 15JAN2013 5.35 11.25 -0.05 1.04167 5.50 11.9792 10 16JAN2013 5.50 11.50 0.15 1.02222 5.70 11.7556 11 17JAN2013 5.52 11.40 0.02 0.99130 5.57 11.4000
The following SAS code uses SAS Risk Dimensions to perturb the risk factors. In the first step, a simple portfolio is created. The portfolio consists of one unit of each risk factor:
Simulated Risk Factor Values from Historical Simulation Analysis WITH SAS Risk Dimensions
Obs Perturbed value of
y1 base casePerturbed value of
y2 base case1 5.60000 11.78750 2 5.58000 11.50000 3 5.52000 11.78049 4 5.65000 11.60952 5 5.60000 11.55425 6 5.60000 11.60798 7 5.45000 11.55349 8 5.50000 11.97917 9 5.70000 11.75556 10 5.57000 11.40000
The COMPARE procedure is then used to compare the risk factor values that were perturbed by using with SAS Risk Dimensions with the risk factor values that were perturbed by using DATA step. The results are printed to the SAS output window. The results are exactly the same:
Comparison of Perturbed Risk Factors WITH and WITHOUT Using SAS Risk Dimensions
The COMPARE Procedure Comparison of WORK.HIST_PRTRB with WORK.SIMSTATE (Method=EXACT) NOTE: No unequal values were found. All values compared are exactly equal.
For licensed customers of SAS Risk Dimensions, documentation is available at:
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/*** Create sample time series data ***/
* Synthetically produce 11 days of historical time series data for two risk factors;
data dates;
format date date9.;
label date="Date";
do d=1 to 12;
date=intnx('weekday','02jan2013'd,d);
output;
end;
drop d;
run;
data rfs;
input y1 y2;
label y1="Interval-level Risk Factor y1"
y2="Ratio-level Risk Factor y2";
datalines;
5.25 10.00
5.30 10.25
5.33 10.25
5.30 10.50
5.40 10.60
5.45 10.65
5.50 10.75
5.40 10.80
5.35 11.25
5.50 11.50
5.52 11.40
5.55 11.50
;
run;
* Merge the dates with the risk factor data;
data hist_vals;
merge dates rfs;
run;
* Use the last data point as the current market (base case) data;
data current hist_vals;
set hist_vals end=last;
if last then output current;
else output hist_vals;
run;
* Print both data sets;
proc print data=hist_vals;
title1 "Historical Time Series Data";
title2 "Work.Hist_Vals";
proc print data=current;
title1 "Current Market (Base Case) Data";
title2 "Work.Current";
run;
/*** Use historical simulation analysis to perturb risk factors without SAS Risk Dimensions ***/
* Store base-case risk factor values into macro variables;
data _null_;
set current;
call symput('y1base',y1);
call symput('y2base',y2);
run;
* Calculate the interval-level returns for risk-factor y1 and the ratio-level
returns for risk-factor y2 from the historical time series data;
data hist_rets;
set hist_vals;
label ret_y1="Additive change of y1"
ret_y2="Relative change of y2";
ret_y1=dif(y1);
ret_y2=y2/lag(y2);
run;
* Perturb base-case values by applying returns from the historical time series data;
data hist_prtrb;
set hist_rets;*(firstobs=2);
label perturb_y1="Perturbed value of y1 base case"
perturb_y2="Perturbed value of y2 base case";
perturb_y1=&y1base+ret_y1;
perturb_y2=&y2base*ret_y2;
run;
* Print the resulting perturbed risk factor values that are used to calculate VaR;
proc print data=hist_prtrb label;
title1 "Simulated Risk Factor Values from Historical Simulation Analysis";
title2 "WITHOUT SAS Risk Dimensions";
run;
/*** Use historical simulation analysis to perturb risk factors with SAS Risk Dimensions ***/
* Create a portfolio that contains one unit for each risk factor;
data port;
instid='inst1';
instindex='y1';
insttype='asset';
output;
instid='inst2';
instindex='y2';
insttype='asset';
output;
run;
* Create new risk environment. Register risk factor and instrument variable definitions;
proc risk;
env new=work.env;
declare riskfactors=(y1 num var mlevel=interval label="Interval-level Risk Factor y1",
y2 num var mlevel=ratio label="Ratio-level Risk Factor y2");
declare instvars=(instindex char 15 var);
env save;
run;
* Define a pricing method in which the instrument value equals the risk factor value;
proc compile env=work.env outlib=work.env;
method pricing_method kind=price;
_value_=riskfactor.instindex;
endmethod;
run;
* Create and run a historical simulation analysis project;
proc risk;
env open=work.env;
instrument asset variables=(instindex) methods=(price pricing_method);
instdata port file=port format=simple;
sources port port;
read sources=port out=port;
marketdata current file=current type=current;
marketdata hist file=hist_vals type=timeseries;
simulation histsim_analysis
data=hist
method=historical
seed=54321;
project histsim_project
data=current
portfolio=port
analysis=histsim_analysis
options=(simstate);
runproject histsim_project
outlib=work
endproject=states;
env save;
run;
* Print perturbed base-case values from SAS Risk Dimensions historical simulation;
proc print data=simstate label;
title1 "Simulated Risk Factor Values from Historical Simulation Analysis";
title2 "WITH SAS Risk Dimensions";
label y1="Perturbed value of y1 base case"
y2="Perturbed value of y2 base case";
var y1 y2;
run;
/*** Compare the two sets of results ***/
* Compare the two sets of perturbed risk factor values;
proc compare data=hist_prtrb(firstobs=2) compare=simstate brief;
title "Comparison of Perturbed Risk Factors WITH and WITHOUT Using SAS Risk Dimensions";
var perturb_y1 perturb_y2;
with y1 y2;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Historical Time Series Data |
Work.Hist_Vals |
Obs | date | y1 | y2 |
---|---|---|---|
1 | 03JAN2013 | 5.25 | 10.00 |
2 | 04JAN2013 | 5.30 | 10.25 |
3 | 07JAN2013 | 5.33 | 10.25 |
4 | 08JAN2013 | 5.30 | 10.50 |
5 | 09JAN2013 | 5.40 | 10.60 |
6 | 10JAN2013 | 5.45 | 10.65 |
7 | 11JAN2013 | 5.50 | 10.75 |
8 | 14JAN2013 | 5.40 | 10.80 |
9 | 15JAN2013 | 5.35 | 11.25 |
10 | 16JAN2013 | 5.50 | 11.50 |
11 | 17JAN2013 | 5.52 | 11.40 |
Simulated Risk Factor Values from Historical Simulation Analysis |
WITHOUT SAS Risk Dimensions |
Obs | Date | Interval-level Risk Factor y1 |
Ratio-level Risk Factor y2 |
Additive change of y1 |
Relative change of y2 |
Perturbed value of y1 base case |
Perturbed value of y2 base case |
---|---|---|---|---|---|---|---|
1 | 03JAN2013 | 5.25 | 10.00 | . | . | . | . |
2 | 04JAN2013 | 5.30 | 10.25 | 0.05 | 1.02500 | 5.60 | 11.7875 |
3 | 07JAN2013 | 5.33 | 10.25 | 0.03 | 1.00000 | 5.58 | 11.5000 |
4 | 08JAN2013 | 5.30 | 10.50 | -0.03 | 1.02439 | 5.52 | 11.7805 |
5 | 09JAN2013 | 5.40 | 10.60 | 0.10 | 1.00952 | 5.65 | 11.6095 |
6 | 10JAN2013 | 5.45 | 10.65 | 0.05 | 1.00472 | 5.60 | 11.5542 |
7 | 11JAN2013 | 5.50 | 10.75 | 0.05 | 1.00939 | 5.60 | 11.6080 |
8 | 14JAN2013 | 5.40 | 10.80 | -0.10 | 1.00465 | 5.45 | 11.5535 |
9 | 15JAN2013 | 5.35 | 11.25 | -0.05 | 1.04167 | 5.50 | 11.9792 |
10 | 16JAN2013 | 5.50 | 11.50 | 0.15 | 1.02222 | 5.70 | 11.7556 |
11 | 17JAN2013 | 5.52 | 11.40 | 0.02 | 0.99130 | 5.57 | 11.4000 |
Simulated Risk Factor Values from Historical Simulation Analysis |
WITH SAS Risk Dimensions |
Obs | Perturbed value of y1 base case |
Perturbed value of y2 base case |
---|---|---|
1 | 5.60000 | 11.78750 |
2 | 5.58000 | 11.50000 |
3 | 5.52000 | 11.78049 |
4 | 5.65000 | 11.60952 |
5 | 5.60000 | 11.55425 |
6 | 5.60000 | 11.60798 |
7 | 5.45000 | 11.55349 |
8 | 5.50000 | 11.97917 |
9 | 5.70000 | 11.75556 |
10 | 5.57000 | 11.40000 |
Type: | Sample |
Topic: | Analytics ==> Financial Analysis Analytics ==> Simulation Analytics ==> Time Series Analysis |
Date Modified: | 2013-10-03 16:17:16 |
Date Created: | 2013-10-02 12:55:31 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS Risk Dimensions Enterprise Edition | 64-bit Enabled HP-UX | ||
64-bit Enabled AIX | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft® Windows® for x64 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows 7 Ultimate x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Professional x64 | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
64-bit Enabled Solaris | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
Linux | ||||
Linux for x64 | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |