# 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?

-

## migrated from stackoverflow.comJan 24 '13 at 15:36

This question came from our site for professional and enthusiast programmers.

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

## 1 Answer

I will start by saying that the paper that recommends the procedure is rather badly written, but since the issue is not of high difficulty I would dare to give a few hints that could suggest the answer.

First of all, Michelle was trying to do this estimation of the VaR using a non-parametric procedure based on kernel estimation of the real density of the data generating process. This is similar to the basic estimation of the VaR from the historical data but in the same time has a small twist of complication.

In the "historical" estimation of the VaR you take the data order it by value and look at the point from where it starts the 5% worst block of data points. That will be your estimate of the 5% VaR.

In this kernel estimation you want to get to the "same" result but you want it to make it a bit more fancy by adding some probability to it. This bit of probability regards the distribution of the estimate of the VaR. That is, we consider the historical realisations as one of many possible realisations of the process of the price, and so, the VaR estimate from the historical data is one of the possible many values that this estimator takes, and all of this possible values would make a distribution.This is the distribution that he was looking for (the jth order distribution). To compute that, he just needed to apply some formula given in the above cited article. And in the end, the mean of that distribution would give him the estimate of the VaR. The benefit of having that distribution is that you can give some credibility to that estimator by computing for example the confidence interval of that estimate of the VaR.

-