bugs in quantlib in bootstrap and CumulativeNormalDistribution

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

bugs in quantlib in bootstrap and CumulativeNormalDistribution

Xavier.Abulker
Hello Quantlib,
we found 2 bugs in Quanlib and I would like to know if the Quantlib user
group could do something:

Bug 1: already reported  :

"Crashing error in bootstrap:
Building piecewiseFlatForward curve with futures and swaps only, the
function crash.
As far as I understand,  This is because in FuturesRateHelper'
discountGuess()
function it calls discountImpl which try to get a value with array index
-1.
As a safety guard, I think in bootstrap() of PiecewiseFlatForward, we
should have
 double guess= ( (i==1)? Null< double >() : instrument->discountGuess() );
instead of
double guess = instrument->discountGuess();
To prevent this from happening. "

Bug2: Europeanoption pricing on Unix:
On windows the example Europeanoption gives:
Method          Value   EstimatedError  Discrepancy     Rel. Discr.
Black Scholes   5.8308  0.0000          0.000000        0.000000
Call-Put parity 5.8308  N/A             4.44089e-15     0.000000

Now on unix the same EuropeanOption gives:

Method          Value   EstimatedError  Discrepancy     Rel. Discr.
Black Scholes   3.2422  0.0000          0.000000        0.000000
Call-Put parity 3.2422  N/A             0       0.000000

You see that the result is not the same.
We check the code and found that in "europeanoption.hpp" the following
const static member is declared:

   static const Math::CumulativeNormalDistribution f_;

This variable "f_" is never explicitly initialized, thus it is up to the
compilor
to decide what to do when it is first used.

In VC++, "f_" is initialized through its' only construtor, and "sigma"
value is set to "1".
However, with gcc under UNIX, "f_" has not gone through any constructor,
and "sigma" value
is set to "0".  So, the difference caused the error output on UNIX.

For the moment we found we could fix it with
Math::CumulativeNormalDistribution EuropeanOption::f_
               = Math::CumulativeNormalDistribution(0,1);

in europeanoption.cpp but this is not a clean fix.

Could you please report that a bug and tell me if a fix is possible?

Thanks a lot

Xavier


*************************************************************************
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration.
La FIMAT et ses filiales declinent toute responsabilite au
titre de ce message s'il a ete altere, deforme ou falsifie.
                    ********
This message and any attachments (the "message") are confidential and
intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
E-mails are susceptible to alteration.
Neither FIMAT nor any of its subsidiaries or affiliates shall
be liable for the message if altered, changed or falsified.
*************************************************************************



Reply | Threaded
Open this post in threaded view
|

Re: bugs in quantlib in bootstrap and CumulativeNormalDistribution

Luigi Ballabio-2
Hi Xavier,
         sorry for the delay, but we're having some hectic weeks and
QuantLib has to get behind...

At 07:21 PM 9/11/02 +0200, [hidden email] wrote:

>Bug 1: already reported  :
>
>"Crashing error in bootstrap:
>Building piecewiseFlatForward curve with futures and swaps only, the
>function crash.
>As far as I understand,  This is because in FuturesRateHelper'
>discountGuess() function it calls discountImpl which try to get a value
>with array index -1.
>As a safety guard, I think in bootstrap() of PiecewiseFlatForward, we
>should have
>  double guess= ( (i==1)? Null< double >() : instrument->discountGuess() );
>instead of
>double guess = instrument->discountGuess();
>To prevent this from happening. "

I haven't been able to reproduce this (and besides, I've had a look at
discountImpl and it seems sound---i.e., steps are taken to ensure that
the array is not accessed out of bounds).
Can you send me a set of data for which the bootstrapping fails?


>Bug2: Europeanoption pricing on Unix:
>We check the code and found that in "europeanoption.hpp" the following
>const static member is declared:
>
>    static const Math::CumulativeNormalDistribution f_;
>
>This variable "f_" is never explicitly initialized, thus it is up to the
>compilor to decide what to do when it is first used.

Argh. I'm tempted to blame the compiler for this, as the above is
initialized in europeanoption.cpp as
     const Math::CumulativeNormalDistribution EuropeanOption::f_;
which should be equivalent to
     const Math::CumulativeNormalDistribution EuropeanOption::f_ =
         Math::CumulativeNormalDistribution();
which in turn should properly initialize f_ with a sigma=1.
However, I'm too lazy to look up the C++ standard, so I might be wrong.

Anyway, let's try to code around this. What happens on Unix if you:
a) remove the line
         static const Math::CumulativeNormalDistribution f_;
    from europeanoption.hpp
b) replace the line
         const Math::CumulativeNormalDistribution EuropeanOption::f_;
    in europeanoption.cpp with
         namespace {
             const Math::CumulativeNormalDistribution f_;
         }
and leave the rest unmodified?

Later,
         Luigi



Reply | Threaded
Open this post in threaded view
|

Re: bugs in quantlib in bootstrap andCumulativeNormalDistribution

Chak Jack Wong
Hi,
I actually discover this bug.
To reproduce the bug is not difficult.  Simply build the curve using futures and
swaps only will give crash.

Jack

Luigi Ballabio wrote:

> Hi Xavier,
>          sorry for the delay, but we're having some hectic weeks and
> QuantLib has to get behind...
>
> At 07:21 PM 9/11/02 +0200, [hidden email] wrote:
> >Bug 1: already reported  :
> >
> >"Crashing error in bootstrap:
> >Building piecewiseFlatForward curve with futures and swaps only, the
> >function crash.
> >As far as I understand,  This is because in FuturesRateHelper'
> >discountGuess() function it calls discountImpl which try to get a value
> >with array index -1.
> >As a safety guard, I think in bootstrap() of PiecewiseFlatForward, we
> >should have
> >  double guess= ( (i==1)? Null< double >() : instrument->discountGuess() );
> >instead of
> >double guess = instrument->discountGuess();
> >To prevent this from happening. "
>
> I haven't been able to reproduce this (and besides, I've had a look at
> discountImpl and it seems sound---i.e., steps are taken to ensure that
> the array is not accessed out of bounds).
> Can you send me a set of data for which the bootstrapping fails?
>
> >Bug2: Europeanoption pricing on Unix:
> >We check the code and found that in "europeanoption.hpp" the following
> >const static member is declared:
> >
> >    static const Math::CumulativeNormalDistribution f_;
> >
> >This variable "f_" is never explicitly initialized, thus it is up to the
> >compilor to decide what to do when it is first used.
>
> Argh. I'm tempted to blame the compiler for this, as the above is
> initialized in europeanoption.cpp as
>      const Math::CumulativeNormalDistribution EuropeanOption::f_;
> which should be equivalent to
>      const Math::CumulativeNormalDistribution EuropeanOption::f_ =
>          Math::CumulativeNormalDistribution();
> which in turn should properly initialize f_ with a sigma=1.
> However, I'm too lazy to look up the C++ standard, so I might be wrong.
>
> Anyway, let's try to code around this. What happens on Unix if you:
> a) remove the line
>          static const Math::CumulativeNormalDistribution f_;
>     from europeanoption.hpp
> b) replace the line
>          const Math::CumulativeNormalDistribution EuropeanOption::f_;
>     in europeanoption.cpp with
>          namespace {
>              const Math::CumulativeNormalDistribution f_;
>          }
> and leave the rest unmodified?
>
> Later,
>          Luigi
>
> -------------------------------------------------------
> This SF.NET email is sponsored by: AMD - Your access to the experts
> on Hammer Technology! Open Source & Linux Developers, register now
> for the AMD Developer Symposium. Code: EX8664
> http://www.developwithamd.com/developerlab
> _______________________________________________
> Quantlib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users



Reply | Threaded
Open this post in threaded view
|

Re: bugs in quantlib in bootstrap andCumulativeNormalDistribution

Luigi Ballabio-2
At 02:36 PM 9/18/02 +0100, you wrote:
>Hi,
>I actually discover this bug.
>To reproduce the bug is not difficult.  Simply build the curve using
>futures and swaps only will give crash.

Well, that's what I tried, but the thing worked. However, I've used the cvs
version of the library. Are you using cvs or 0.3.0?

Later,
         Luigi



Reply | Threaded
Open this post in threaded view
|

Re: bugs in quantlib in bootstrap andCumulativeNormalDistribution

Chak Jack Wong
I used 0.3.

Jack

Luigi Ballabio wrote:

> At 02:36 PM 9/18/02 +0100, you wrote:
> >Hi,
> >I actually discover this bug.
> >To reproduce the bug is not difficult.  Simply build the curve using
> >futures and swaps only will give crash.
>
> Well, that's what I tried, but the thing worked. However, I've used the cvs
> version of the library. Are you using cvs or 0.3.0?
>
> Later,
>          Luigi



Reply | Threaded
Open this post in threaded view
|

Re: bugs in quantlib in bootstrap andCumulativeNormalDistribution

Luigi Ballabio-2
At 03:48 PM 9/18/02 +0100, Chak Jack Wong wrote:
>I used 0.3.

Ok, I used 0.3.0 and got the crash. The good news are that the current cvs
version doesn't crash, so next version will be safe to use. The bad news
are that the current cvs version is, well, only on cvs. However, I might
send you a tarball if you need it and can't/don't want get through cvs...

Bye,
         Luigi




Reply | Threaded
Open this post in threaded view
|

Re: bugs in quantlib in bootstrap and CumulativeNormalDistribution

Xavier.Abulker
In reply to this post by Xavier.Abulker
Hi Luigi,
thanks for your answer.
Unfortunately your  guess:
a) remove the line
         static const Math::CumulativeNormalDistribution f_;
    from europeanoption.hpp
b) replace the line
         const Math::CumulativeNormalDistribution EuropeanOption::f_;
    in europeanoption.cpp with
         namespace {
             const Math::CumulativeNormalDistribution f_;
         }
and leave the rest unmodified
gives me the same wrong pricing on Unix.

We finally found a way to fix this problem, I'm going to send another email
with our fix proposal.
Thanks




doesn't work and


                                                                                                               
                    Luigi Ballabio                                                                              
                    <luigi.ballabio@fast       To:     [hidden email],                                
                    webnet.it>                  [hidden email]                            
                                               cc:                                                              
                    18/09/2002 15:31           Subject:     Re: [Quantlib-users] bugs in quantlib in bootstrap  
                                                and  CumulativeNormalDistribution                              
                                                                                                               





Hi Xavier,
         sorry for the delay, but we're having some hectic weeks and
QuantLib has to get behind...

At 07:21 PM 9/11/02 +0200, [hidden email] wrote:

>Bug 1: already reported  :
>
>"Crashing error in bootstrap:
>Building piecewiseFlatForward curve with futures and swaps only, the
>function crash.
>As far as I understand,  This is because in FuturesRateHelper'
>discountGuess() function it calls discountImpl which try to get a value
>with array index -1.
>As a safety guard, I think in bootstrap() of PiecewiseFlatForward, we
>should have
>  double guess= ( (i==1)? Null< double >() : instrument->discountGuess()
);
>instead of
>double guess = instrument->discountGuess();
>To prevent this from happening. "

I haven't been able to reproduce this (and besides, I've had a look at
discountImpl and it seems sound---i.e., steps are taken to ensure that
the array is not accessed out of bounds).
Can you send me a set of data for which the bootstrapping fails?


>Bug2: Europeanoption pricing on Unix:
>We check the code and found that in "europeanoption.hpp" the following
>const static member is declared:
>
>    static const Math::CumulativeNormalDistribution f_;
>
>This variable "f_" is never explicitly initialized, thus it is up to the
>compilor to decide what to do when it is first used.

Argh. I'm tempted to blame the compiler for this, as the above is
initialized in europeanoption.cpp as
     const Math::CumulativeNormalDistribution EuropeanOption::f_;
which should be equivalent to
     const Math::CumulativeNormalDistribution EuropeanOption::f_ =
         Math::CumulativeNormalDistribution();
which in turn should properly initialize f_ with a sigma=1.
However, I'm too lazy to look up the C++ standard, so I might be wrong.

Anyway, let's try to code around this. What happens on Unix if you:
a) remove the line
         static const Math::CumulativeNormalDistribution f_;
    from europeanoption.hpp
b) replace the line
         const Math::CumulativeNormalDistribution EuropeanOption::f_;
    in europeanoption.cpp with
         namespace {
             const Math::CumulativeNormalDistribution f_;
         }
and leave the rest unmodified?

Later,
         Luigi






*************************************************************************
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses destinataires.
Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration.
La Fimat et ses filiales declinent toute responsabilite au
titre de ce message s'il a ete altere, deforme ou falsifie.
                    ********
This message and any attachments (the "message") are confidential and
intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
E-mails are susceptible to alteration.
Neither Fimat nor any of its subsidiaries or affiliates shall
be liable for the message if altered, changed or falsified.
*************************************************************************