Forgot to attach the excel file there.
Hi, I am totally confused by the quantlib percentile function, the code is listed below. I have attached an excel file, you can find the issue in sheet1. If I have 250 sample pnl, the 0.99 percentile is just between the second and third one, use the interpolated function the value I have highlighted there. But, the result of QL is smaller than the highlighted one. And I thought the result of Excel is right, I have read the code, but i can not understand it, could you explain it for me. thanks!
Real GeneralStatistics::percentile(Real percent) const {
QL_REQUIRE(percent > 0.0 && percent <= 1.0,
"percentile (" << percent << ") must be in (0.0, 1.0]");
Real sampleWeight = weightSum();
QL_REQUIRE(sampleWeight>0.0,
"empty sample set");
sort();
std::vector<std::pair<Real,Real> >::iterator k, l;
k = samples_.begin();
l = samples_.end()-1;
/* the sum of weight is non null, therefore there's
at least one sample */
Real integral = k->second, target = percent*sampleWeight;
while (integral < target && k != l) {
k++;
integral += k->second;
}
return k->first;
}