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.
| Parameter | Description |
|---|---|
| define | Specifies the relevant information about the copula to be used for the simulation, such as type, parameters, and correlation matrix. |
| display | Specifies which ODS (Output Delivery System) tables to generate for display. |
| margApproxOpts | Specifies options for approximating the empirical marginal distribution function when transforming uniform variates to the original scale. |
| ndraws | Specifies the number of observations to generate in the simulation. |
| outempirical | Specifies the output CAS table to store the simulated data with empirical marginals (transformed from uniform). |
| outputTables | Specifies which of the generated ODS tables to save as CAS tables. |
| outuniform | Specifies the output CAS table to store the simulated data with uniform marginals. |
| plot | Specifies options for generating diagnostic plots, such as scatter plots or tail dependence plots. |
| restore | Specifies an item store (a CAS table) from which to restore a previously fitted copula model for simulation. |
| seed | Specifies the random number seed for the simulation to ensure reproducibility. |
| table | Specifies the input data table, which is required when you want to simulate data with empirical marginals. |
| tolerance | Specifies the tolerance for the simulation calculations. |
| var | Specifies the list of variable names for the output data set. |
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.
| 1 | DATA mycorr; |
| 2 | _name_ = 'y1'; _type_='CORR'; y1=1; y2=0.6; OUTPUT; |
| 3 | _name_ = 'y2'; _type_='CORR'; y1=0.6; y2=1; OUTPUT; |
| 4 | RUN; |
| 5 | |
| 6 | DATA 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; |
| 12 | RUN; |
| 13 | |
| 14 | PROC CASUTIL; |
| 15 | load DATA=mycorr casout='mycorr' replace; |
| 16 | load DATA=empdata casout='empdata' replace; |
| 17 | QUIT; |
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.
| 1 | PROC 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}; |
| 8 | RUN; |
| 9 | QUIT; |
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.
| 1 | PROC 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}; |
| 11 | RUN; |
| 12 | QUIT; |
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.
| 1 | PROC 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}; |
| 11 | RUN; |
| 12 | QUIT; |