Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

I have successfully chosen and estimate a copula for the ranks of the log-returns of my actions. My question is, since I have worked with the ranks instead of directly the log-returns (in order to be in $[0,1]$) how can I simulate new data for the log-returns from my copula?

To be more clear, here is the code commented:

library(copula)
library(quantmod)
#stocks chosen: Microsoft, General Electric
stocks<-c("MSFT","GE")
start="1996-01-01"
end="2000-12-31"
ALL<-NULL
dailyLogReturns<-NULL
cours<-NULL
for(i in stocks){
  #get quotes from Yahoo
  temp<-getSymbols(i,from=start,to=end,auto.assign=FALSE)
  #store adjusted quotes
  #adjusted quotes are used due to split actions in the past
  cours<-cbind(cours,Ad(temp))
  #calculate daily log return for adjusted quotes
  dailyLogReturns<-cbind(dailyLogReturns,coredata(dailyReturn(Ad(temp),type='log')))
}
colnames(cours)<-stocks
colnames(dailyLogReturns)<-stocks
#ALL is the ranks of the log-returns, in [0,1]
ALL<-pobs(dailyLogReturns)

#Here is the graph of the daily log-returns
plot(dailyLogReturns)

Plot of bivariate log-returns

#Here is the graph of the ranks of the daily log-returns
plot(ALL)

Plot of bivariate ranks

#Estimate the copula
#here i only show the Student, others have been tried without success.
#degres of freedom have been chosen independently
tc<-tCopula(param=c(0),dim=2,dispstr="un",df=7, df.fixed=TRUE)
ftc <- fitCopula(tc,ALL,method="mpl")

#Goodness of fit for the copula, p-value is about 40%
time.start=Sys.time()
GOF<-gofCopula(tc, ALL, estim.method="mpl", simulation="mult")
Sys.time()-time.start
(GOF$p.value>0.05)

#New data sample from the copula
Copula.data<-rCopula(1000,tCopula(0.417,df=7))
plot.new()
par(oma=c(1,1,1,1),mar=c(1,1,1,1))
plot(Copula.data,main="",xlab="",ylab="",col="red",pch="*");points(ALL,col="blue",pch="*")

#Here is the plot: new data from copula (red) vs initial data (blue)

Comparaison of data from copula (red) vs initial data (blue)

So, what have I tried?

I used the quantile function based on 1000 observations of daily log-returns to calibrate and 263 observations for back-testing

nb.calibration<-1000
nb.backtesting<-nrow(dailyLogReturns)-nb.calibration
a<-matrix(0,nb.backtesting,nb.calibration)
b<-matrix(0,nb.backtesting,nb.calibration)
for(i in 1:nb.backtesting){
  j=1+i;k=nb.calibration+i
  a[i,]=dailyLogReturns[j:k,1]
  b[i,]=dailyLogReturns[j:k,2]
  rmtc<-quantile(a[i,],Copula.data[,1])+quantile(b[i,],Copula.data[,2])
}

plot(rmtc,type='l')
lines(dailyLogReturns[,1],col='red')
lines(dailyLogReturns[,2],col='blue')
#Here is the plot obtained: new data from the copula (black), Microsoft (blue), GE (red)

Comparaison of log-returns generated vs historical

Finally: Am I doing the right thing, is that correct ?

Sources:
- Estimation of Portfolio Value-at-Risk using Copula
- Some nonparametric tests for copulas with emphasis on goodness-of-fit tests

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.