Solved – How to obtain real observation from simulated pseudo observation? (from the copula)

I have fitted a normal copula to my data in R using the copula package and generated pseudo observations in the unit square [0,1]^2.
I am having trouble retrieving the simulated values: how can I get x and y from u1?

from my understanding of the process, assuming x and y are normally distributed (for the sake of simplicity), I should do the following

x <- qnorm(u1[,1],mean(mat[,1]),sd(mat[,2])) y <- qnorm(u1[,1],mean(mat[,1]),sd(mat[,2])) 

and these x and y should be my simulated real observations right? For some reason they do not fit that well my data as you can see below (simulated data are in RED and skewed upwards, and actual data are in BLUE).

enter image description here

What I need to know is: is the process correct or am I missing something? Is the use of qnorm correct as it is above or should I've used it differently?

By trying to use qnorm with the default mean=0 and sd=1 the simulated x and y seem to fit better, which I find odd since I thought actual mean and sd of x and y should be used. Am I correct?

Converting x and y using qnorm(mean=0,sd=1)

Here is my code (except for the last part which is above)

library(copula)  x <- read.table("x.txt") y <- read.table("y.txt")  mat <- matrix(nrow=100,ncol=2)  for(i in 1:100) {     mat[i,1] <- x[,1][i]     mat[i,2] <- y[,1][i] }  #Actual observations plot(mat[,1],mat[,2],main="Returns",xlab="x",ylab="y",col="blue")  #Copula fitting normal.cop <- normalCopula(dim=2) fit.cop<- fitCopula(normal.cop,pobs(mat),method="ml")  #Coefficients rho <- coef(fit.cop) print(rho)  #Simulate data u1 = rCopula(500,normalCopula(coef(fit.cop),dim=2)) points(u1[,1],u1[,2],col="red") 

Here you can find the data for x and y should you need it to run the code.

x and y are returns from two stocks

While I'm not really sure what your goal is with this analysis there is an alternative way to use copulas to generate new correlated data.

Figure out marginal distributions for each stock to generate returns data that "looks" like your existing market data, ignoring for the moment their dependence structure. Do this for both stocks and apply the sort function to each of them. (I'm not sure about the efficacy of this but you might even just sort your existing returns data, as a form of bootstrapping)

Then go off to your copula,

  • generate correlated observations on [0,1]
  • convert them into ranks using

        rankedData <- data.frame(apply(<<Copula Output Here>>,2,function(x){ rank(x,ties.method="first") } )) 
  • Use the ranks to order the newly generated stock observations.

Now you have appropriately generated data with the desired dependence structure.

Remember to make sure the order used by the sort function and the rank function are the same and not inverse of each other.

Similar Posts:

Rate this post

Leave a Comment