http://quantlib.414.s1.nabble.com/Statistics-Value-at-risk-tp15687p15746.html
> Many thanks, I thought QuantLib method is more close to the function of
> excel 2010 percentile.inc, right?
>
> Alex
>
>
> 2014-08-09 18:02 GMT+08:00 Peter Caspers <
[hidden email]>:
>
>> interesting. yes, at first sight the one in ql seems to be of type 1.
>> maybe we should think about adding type 5 to attract some hydrologists
>> ?
>> Peter
>>
>> On 8 August 2014 11:53, Luigi Ballabio <
[hidden email]> wrote:
>> > Yes, it rather depends on the distribution you assume. In R, there are
>> > 9 different quantile algorithms:
>> >
>> > <
http://stat.ethz.ch/R-manual/R-patched/library/stats/html/quantile.html>.
>> > I think the one in QuantLib is one of the first three.
>> >
>> > Luigi
>> >
>> >
>> > On Fri, Aug 8, 2014 at 10:05 AM, Peter Caspers <
[hidden email]>
>> > wrote:
>> >> the "correct" answer depends on how you estimate your distribution
>> >> from your sample data, doesn't it ? if you use a discrete distribution
>> >> just assuming equal probability for each observation (like
>> >> GeneralStatistics, if no weight is given), then the 1% quantile (which
>> >> by definition = 99% VaR)
>> >>
>> >> q = inf ( x | F(x) >= 0.01 )
>> >>
>> >> is equal to the third loss (-0.04), because (assuming 250 losses
>> >> -0.06, -0.05, -0.04, ...) F(-0.06) = 1 / 250 < 0.01, F(-0.05) = 2 /
>> >> 250 < 0.01, F(-0.04) = 3 / 250 >= 0.01, I think. So QuantLib seems to
>> >> do a good job here ?
>> >>
>> >> Peter
>> >>
>> >> On 8 August 2014 02:34, Yuanhao Zhang <
[hidden email]> wrote:
>> >>> Thanks, Luigi. But, I have made the test, the result should be between
>> >>> 0.04,
>> >>> and 0.05, not exactly the 0.04. But, lower than 0.045. I donot know
>> >>> why.
>> >>>
>> >>> regards
>> >>>
>> >>> Alex
>> >>>
>> >>>
>> >>> 2014-08-07 22:51 GMT+08:00 Luigi Ballabio <
[hidden email]>:
>> >>>
>> >>>> The code below doesn't interpolate. In your case, if you ask for 0.99
>> >>>> VaR, the second loss is 0.05 and the third is 0.04, it just returns
>> >>>> 0.04.
>> >>>>
>> >>>> I don't think I remember the reason for that, though.
>> >>>>
>> >>>> Luigi
>> >>>>
>> >>>>
>> >>>> On Thu, Aug 7, 2014 at 1:19 PM, Yuanhao Zhang
>> >>>> <
[hidden email]>
>> >>>> wrote:
>> >>>> > 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>
>> >>>> >
>> >>>> >
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> <
https://implementingquantlib.blogspot.com>
>> >>>> <
https://twitter.com/lballabio>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> ------------------------------------------------------------------------------
>> >>> Want fast and easy access to all the code in your enterprise? Index
>> >>> and
>> >>> search up to 200,000 lines of code with a free copy of Black Duck
>> >>> Code Sight - the same software that powers the world's largest code
>> >>> search on Ohloh, the Black Duck Open Hub! Try it now.
>> >>>
http://p.sf.net/sfu/bds>> >>> _______________________________________________
>> >>> QuantLib-users mailing list
>> >>>
[hidden email]
>> >>>
https://lists.sourceforge.net/lists/listinfo/quantlib-users>> >>>
>> >
>> >
>> >
>> > --
>> > <
https://implementingquantlib.blogspot.com>
>> > <
https://twitter.com/lballabio>
>
>