copula

copulaSimulate

Description

The copulaSimulate action simulates data from a specified copula model. A copula model is a multivariate distribution function whose marginal distributions are uniform on the interval [0, 1]. This action is useful for Monte Carlo simulations in finance, risk management, and other fields where modeling the dependence structure of multiple variables is crucial. You can define the copula by its type and parameters, or restore a previously fitted model from a CAS table (item store). The action can generate simulated data with either uniform marginals or empirical marginals derived from a reference dataset.

copula.copulaSimulate { define={...}, display={...}, margApproxOpts={...}, ndraws=long, outempirical={...}, outputTables={...}, outuniform={...}, plot={...}, restore={...}, seed=integer, table={...}, tolerance=double, var={...} }
Settings
ParameterDescription
defineSpecifies the relevant information about the copula to be used for the simulation, such as type, parameters, and correlation matrix.
displaySpecifies which ODS (Output Delivery System) tables to generate for display.
margApproxOptsSpecifies options for approximating the empirical marginal distribution function when transforming uniform variates to the original scale.
ndrawsSpecifies the number of observations to generate in the simulation.
outempiricalSpecifies the output CAS table to store the simulated data with empirical marginals (transformed from uniform).
outputTablesSpecifies which of the generated ODS tables to save as CAS tables.
outuniformSpecifies the output CAS table to store the simulated data with uniform marginals.
plotSpecifies options for generating diagnostic plots, such as scatter plots or tail dependence plots.
restoreSpecifies an item store (a CAS table) from which to restore a previously fitted copula model for simulation.
seedSpecifies the random number seed for the simulation to ensure reproducibility.
tableSpecifies the input data table, which is required when you want to simulate data with empirical marginals.
toleranceSpecifies the tolerance for the simulation calculations.
varSpecifies the list of variable names for the output data set.
Data Preparation View data prep sheet
Data Creation: Sample Correlation and Data Tables

First, we create two CAS tables. 'mycorr' holds a Pearson correlation matrix for a 2-dimensional Normal copula. 'mycas.empdata' contains empirical data that will be used to define the marginal distributions for the simulation.

Copied!
1DATA mycorr;
2 _name_ = 'y1'; _type_='CORR'; y1=1; y2=0.6; OUTPUT;
3 _name_ = 'y2'; _type_='CORR'; y1=0.6; y2=1; OUTPUT;
4RUN;
5 
6DATA empdata;
7 DO i = 1 to 1000;
8 y1 = rannor(12345);
9 y2 = 0.5 * y1 + sqrt(1 - 0.5**2) * rannor(12345);
10 OUTPUT;
11 END;
12RUN;
13 
14PROC CASUTIL;
15 load DATA=mycorr casout='mycorr' replace;
16 load DATA=empdata casout='empdata' replace;
17QUIT;

Examples

This example simulates 10,000 observations from a 2-dimensional Normal copula. The dependence structure is defined by the 'mycorr' correlation table. The simulated data with uniform marginals is saved to the 'unifsim' CAS table.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 copula.copulaSimulate /
3 define={copulaType='NORMAL', corrTable={name='mycorr'}},
4 ndraws=10000,
5 seed=123,
6 var={'y1', 'y2'},
7 outuniform={name='unifsim', replace=true};
8RUN;
9QUIT;
Result :
A CAS table named 'unifsim' is created containing 10,000 rows and 2 columns ('y1', 'y2') with simulated data that follows a Normal copula structure and has uniform marginal distributions.

This example simulates 5,000 observations from a 2-dimensional t-copula with 5 degrees of freedom. The correlation is defined by the 'mycorr' table. The marginal distributions are derived empirically from the 'empdata' table. The final simulated data (with empirical marginals) is saved to 'empirsim'. The data with uniform marginals is saved to 'unifsim_t'. Additionally, a scatter plot matrix of the simulated data is requested.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 copula.copulaSimulate /
3 TABLE={name='empdata'},
4 define={copulaType='T', df=5, corrTable={name='mycorr'}},
5 ndraws=5000,
6 seed=54321,
7 var={'y1', 'y2'},
8 outuniform={name='unifsim_t', replace=true},
9 outempirical={name='empirsim', replace=true},
10 plot={scatter=true};
11RUN;
12QUIT;
Result :
Two CAS tables are created: 'unifsim_t' with uniform marginals and 'empirsim' with marginals matching the 'empdata' table. ODS graphics showing the scatter plot matrix of the simulated variables are also generated.

This example first fits a Clayton copula to the 'empdata' table and saves the model to an item store named 'clayton_store'. Then, it uses the 'copulaSimulate' action with the 'restore' parameter to simulate 2,000 new observations from that fitted model. This is useful for scenario analysis based on an existing fitted dependence structure.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 copula.copulaFit /
3 TABLE={name='empdata'},
4 define={copulaType='CLAYTON', var={'y1', 'y2'}},
5 store={name='clayton_store', replace=true};
6 copula.copulaSimulate /
7 restore={name='clayton_store'},
8 ndraws=2000,
9 seed=987,
10 outuniform={name='sim_from_store', replace=true};
11RUN;
12QUIT;
Result :
An item store 'clayton_store' is created with the fitted model details. Then, a CAS table 'sim_from_store' is generated, containing 2,000 simulated observations based on the restored Clayton copula model.

FAQ

What does the copulaSimulate action do?
What is the purpose of the 'define' parameter?
Which copula types can be specified with the 'copulatype' parameter?
How do I specify the correlation matrix for elliptical copulas?
What is the 'df' parameter used for?
How can I specify the parameter for Archimedean copulas?
What does the 'ndraws' parameter control?
How can I save the simulation results?
What is the 'seed' parameter for?
Can I use a previously fitted model for simulation?
What are the options for approximating the empirical marginal distribution function?