Re: Statistics Value at risk

Posted by jojogh on
URL: http://quantlib.414.s1.nabble.com/Statistics-Value-at-risk-tp15687p15733.html

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;
    }



2014-08-07 18:10 GMT+08:00 Luigi Ballabio <[hidden email]>:
What are you getting instead? May you post some sample code that
reproduces the issue?

Luigi

On Wed, Aug 6, 2014 at 6:20 PM, Yuanhao Zhang <[hidden email]> wrote:
> Does any one used Statistics Value at risk function in QuantLib? I try to
> use the simple 250 PnL sample to test this function. The confidence level is
> 0.99, so the value should be between the second one and the third one. If
> the second one is -0.04 and the third one is -0.05, so the value is
> -(-0.04+(-0.05))/2=0.045. But, the quantlib value is always smaller than
> 0.045. Is that wrong with the calculation logic? I can not figure it out why
> the value is different. Any one could help me figure it out?
>
> Best regards
>
> Alex
>
> ------------------------------------------------------------------------------
> Infragistics Professional
> Build stunning WinForms apps today!
> Reboot your WinForms applications with our WinForms controls.
> Build a bridge from your legacy apps to the future.
> http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>



--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>


------------------------------------------------------------------------------

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

FX20140730v2_USDCNY_VaR.rar (236K) Download Attachment