# A non parametric study of VaR with kernel density

I'm working in order to compare the calculation of the VaR between the methodology of copulas and kernel density, all this by using the software r.

The process that I follow is:

1. Obtain a sample (which is bivariate)
2. Estimate the density of the data by kernel of Epanechnikov (for X1 and X2 as marginals)
3. Calculate the bandwith with the rule of thumb (Silverman)
4. Fix a copula (Gumbel or Clayton)
5. I calculate the VaR (quantile 0.95)

But if I do this I obtain a value that correspond to the estimated data, I have found a working paper that in relation with the process add another step:

Estimate the pdf of the jth order statistic.

Agarwal, Ravi Kumar and Ramakrishnan, Vignesh, Epanechnikov Kernel Estimation of Value at Risk (January 14, 2010).

(Page 9)

http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1537087

set.seed(1)
data<-rnorm(518,10,3)

#Calculate rule-of-thumb bandwidth
sx<-apply(data,2,sd)
b1 <-1.06*sx[1,]*n^(-1/5)
b2 <-1.06*sx[2,]*n^(-1/5)

#Kernel density estimation "epanechnikov"
d1=density(data[,1],bw=b1,kernel="epanechnikov")
d2=density(data[,2],bw=b2,kernel="epanechnikov")

data_E <- cbind(d1$y,d2$y)

#Fixing a copula (Gumbel)

r<-Kendall(data_E)

P<-1/(1-r[1,2])
m1<- fit.norm(data_E[,1])
m2<- fit.norm(data_E[,2])

rep <- 100000
gcopula <- rcopula.gumbel(rep,theta=P, d=2)
c1 <- qnorm(gcopula[,1],mean=m1$mu,sd=sqrt(m1$Sigma))
c2 <-qnorm(gcopula[,2],mean=m2$mu,sd=sqrt(m2$Sigma))
dataGUM<-cbind(c1, c2)

alfa=0.95
quantile(dataGUM, alfa)


As I have exposed the value of the quantile at 0.95 correspond to my estimated data "data_E" and not to the original one "data", there is a way that I could find it?

• lots of errors in your code Jan 25, 2013 at 1:56
• @pyCthon Don't keep us in suspense, do you want to list some of them? :-) Jan 30, 2013 at 1:44
• @DarrenCook well heres the first one thats easy to fix, pastebin.com/jLSUSQkr Jan 30, 2013 at 3:33
• Suggestion: consider other kernels as well as Epinechnikov: uniform, triangle, quartic, triweight, cosinus, Gaussian.
– user5626
Jul 7, 2013 at 14:03