## Pseudo Random number generation in sas risk dimension

Occasional Contributor
Posts: 5

# Pseudo Random number generation in sas risk dimension

Hello,

I am trying to configure co-variance based simulation in SAS Risk Dimension. I have used seed value as 54321 and have considered the twister random number generator. But the output is not getting tallied with the values generated by using RAND function in sas coding. Below is the piece of code which I tried to execute in SAS -

``````data test;
call streaminit(54321);
do i=1 to 10;
var1=rand('normal');
output;
end;
run;``````

Can anyone help me with the issue. I would like to know how SAS risk dimension is using the seed value for generating the random numbers and why the same is not getting tallied while generating the random numbers in base sas.

SAS Employee
Posts: 10

## Re: Pseudo Random number generation in sas risk dimension

I am looking into this for you. I'll have a response soon, I hope.

Simon

SAS Employee
Posts: 10

## Re: Pseudo Random number generation in sas risk dimension

What you are trying to do is very challenging.

The random normals that we are producing are correlated random normals. The data step code you provide would

only work if you had a single risk factor in your covariance matrix and that risk factor had a variance of 1 and the risk factor is MLEVEL=interval  (The default is ratio). If you have multivariate problem you will need to multiply the random normal shocks by the cholesky  root of the covariance matrix L where L’L =covariance matrix. You will need

to know the order of the risk factors used in SAS Risk Dimensions, and whether the cholesky root is rank deficient. Pseudo random draws are made in the order of the risk factors and, furthermore, risk factors that are strict linear functions of other risk factors (rank deficient) are skipped.

Occasional Contributor
Posts: 5

## Re: Pseudo Random number generation in sas risk dimension

I have generated the random numbers both for monte carlo - covariance based method and monte carlo - model based method.
For the model based approach I have used single risk factor and for model based method I have used multiple risk factors. But then also both of the analysis are generating the same set of random numbers. I am not sure if it is referring to the covariance matrix or not.

Here I have attached the random numbers generated by system (only first 10 random numbers have been attached). I believe this will help to look into the matter in depth.

Below is the RD code that has been used -

``````SIMULATION MonteCarloSim_model
METHOD=montecarlo
DATA = HistoricalMarketData
HORIZON = (   1   )
INTERVAL = WeekDay
GENERATOR = twister
NDRAW = 251
SEED = 54321
ERRORMODEL = NORMAL
;

SIMULATION MonteCarloSim
METHOD=covariance
DATA = Covar_matrix_new
HORIZON = (   1   )
INTERVAL = WeekDay
GENERATOR = twister
NDRAW = 251
SEED = 54321
ERRORMODEL = ASFIT
;``````

I am not able to understand the methodology that system is following to generate these random numbers. I am able to validate the sas - covarinace based monte carlo model in excel but not able to tally the random numbers (with constant seed value).

SAS Employee
Posts: 10

## Re: Pseudo Random number generation in sas risk dimension

There is an output option called SHOCKS that might help.

On the RUNPROJECT statement put

options=(shocks states …)

When the project is run, you get a dataset called “shocks” that contain the raw random normal shock that SAS Risk Dimensions used in that analysis. These are

the shocks before multiplying with the cholesky root.

For example:

Let me know if this helps.

Yours

Simon

Occasional Contributor
Posts: 5