Matlab has a built-in function to simulate from copulas: copularnd
I need to have a conditional Gaussian Copula.
I had a suggestion for Clayton Copula by another user:
Clayton Copula Sampling
for which the code is :
Can anybody by an example show, how the coding can be done, using GAUSSIAN Copula?
%% Simulations of Clayton copulas using conditional cdf
%Example for theta=4
n=3000;
theta=5;
u=rand(1,n);
y=rand(1,n);
v=((y.^(1/(1+theta)).*u).^(-theta)+1-u.^(-theta)).^(-1/theta);
x1=norminv(u);
x2=norminv(v);
plot(x1,x2,'.')
I just found this code:
%%Simulations of bivariate Gaussian copulas
%Example for rho=0.5
n=30000;
rho=0.5;
x1=norminv(rand(1,n));
x2=norminv(rand(1,n));
X = [x1; x2];
C = [1, rho; rho,1]; %2x2 Correlation matrix
cholesky = chol(C,'lower'); %lower triangular matrix of C using Cholesky decomposition
Copsims = cholesky*X;
c1 = Copsims(1,:);
c2 = Copsims(2,:);
plot(c1,c2,'.')
corrcoef(c1,c2) %check for empirical rho, not on point the initial rho because of sampling error