How can I simulate data from two different distribution using Copulas?
Show older comments
Hi!
I have been trying to create a Monte Carlo simulation model based on two set of data. Data X seem to fit a gamma distribution and data Y seem to fit either gumbel or lognormal distribution (lets assume it is lognormal for the sake of it).
So I basically tried to follow the guide "Simulating dependent random variables using copulas" but I can't seem to make it work. Probably because I don't fully get the whole concept behind it, but I know it should work for what I want to get. Right now I just seem to generate random values from 0 to 1 but I need it to do this in correlation to my data.
This is my code:
n=1000;
X=xlsread('XXXXXX.xlsx');
Y=xlsread('YYYYYY.xlsx');
rho=corr(X,Y)
Z = mvnrnd([0 0],[1 rho;rho 1], n);
U = normcdf(Z);
Q = [gaminv(U(:,1),2,1) exp(U(:,2))];
So what is left is to insert my data to the simulation, and I also assume I would have to fit my data using the gamfit and lognfit function.
Accepted Answer
More Answers (1)
Jeff Miller
on 5 Dec 2019
The question is a little confusing because the U values are from 0 to 1 but the Q values aren't.
Q(1,:) looks like a gamma but Q(2,:) doesn't look like either gumbel or lognormal.
Maybe you want :
Q = [gaminv(U(:,1),2,1) exp(Z(:,2))]; % to get variable 2 as a lognormal
5 Comments
Jeff Miller
on 6 Dec 2019
Not sure I understand what you mean by "combine it with my own data." Is this a fair summary of your situation?
- You have observed values of X & Y pairs, where X seems to be a gumbel and Y seems to be a lognormal.
- The correlation of the observed values is rhoXY.
- For simulation purposes, you want to generate new X/Y pairs from the same 2 distributions that will give approximately the same correlation.
In this summary, your own data are only used to estimate distribution parameters and correlation, but maybe you mean something more by "combine with".
Side note: the rhoXY that you compute from your non-normal data is probably not the value that you want to pass to mvnrnd. Due to the nonlinear transformation, the generated XY data will have a different correlation than the mvn rho.
Punto
on 6 Dec 2019
Jeff Miller
on 6 Dec 2019
Writing a program for monte carlo simulation could mean 100 different things...you are not specifying any of the details, and these matter.
Let me try again: See my question about (1) - (3) above: Is this a fair summary of your situation. Please just answer yes if it is, and explain why if it is not.
Punto
on 6 Dec 2019
Categories
Find more on Copula Distributions and Correlated Samples in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!