bug related to error message "root not bracketed"

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

bug related to error message "root not bracketed"

Jinping Shi
Hi,
 
I came across a bug in Quantlib and not sure where to report.  Sorry for the intrusion.
 
in file ./ql/math/solver1d.hpp, the following bug causes error like
 
"root not bracketed: f[2.22045e-16,3] -> [-1.534964e-04,-5.486424e-02]"
 
 
    185             fxMin_ = f(xMin_);
    186             //if (fxMin_ == 0.0)        // Bugfix JSHI
    187             if (fxMin_ <= accuracy)
    188                 return xMin_;
    189
    190             fxMax_ = f(xMax_);
    191             //if (fxMax_ == 0.0)        // Bugfix JSHI
    192             if (fxMax_ <= accuracy)
    193                 return xMax_;
 
I am using version 0.9.9.
 
 
Thanks and Regards,
Jinping Shi


The New Busy is not the old busy. Search, chat and e-mail from your inbox. Get started.
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: bug related to error message "root not bracketed"

Luigi Ballabio
On Thu, 2010-06-03 at 18:37 +0000, Jinping Shi wrote:

> in file ./ql/math/solver1d.hpp, the following bug causes error like
>  
> "root not bracketed: f[2.22045e-16,3] ->
> [-1.534964e-04,-5.486424e-02]"
>  
>  
>     185             fxMin_ = f(xMin_);
>     186             //if (fxMin_ == 0.0)        // Bugfix JSHI
>     187             if (fxMin_ <= accuracy)
>     188                 return xMin_;
>     189
>     190             fxMax_ = f(xMax_);
>     191             //if (fxMax_ == 0.0)        // Bugfix JSHI
>     192             if (fxMax_ <= accuracy)
>     193                 return xMax_;

Yes, I remember this.  The problem is, in this method we don't know if
the accuracy was requested on x of f(x); that differs from solver to
solver.  If f(xMin_) < accuracy, we can return xMin_ if the accuracy was
requested on f(x), since f(xMin_) is close enough to 0; but if it was on
x, we can't return as we're not sure that xMin_ is close enough to the
actual root X (i.e., that xMin_ - X < accuracy.)  The only case in which
we can return is when f(xMin_) is precisely 0, because we found the
root. So, as of now, it's correct for the solver not to return
immediately.  To fix the problem, we could add some logic later (when
the error message is thrown) to ensure that the missing bracketing is
not due to numerical error; or we could add some property to the solvers
so that we know whether the accuracy is on x or f(x), and return when
possible.  Would you mind trying to code that?

Thanks,
        Luigi


--

Quote me as saying I was misquoted.
-- Groucho Marx



------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: bug related to error message "root not bracketed"

Jinping Shi
My further investigation shows that the problem is somewhere else.
 
I was using <Forward, Linear> in the boostraping and when the input data is noisy (or too many data points), the forward rate can be negative.  So the change should be in
 
/ql/termstructures/iterativebootstrap.hpp

 157 // bracket
 158 Real min = Traits::minValueAfter(i, ts_->data_);// -2.0;  //JSHI, allow negative if using forward linear
                                                     
 
But when one uses <Discount, LogLinear>, it should be strictly positve.
 
 
 

> Subject: Re: [Quantlib-users] bug related to error message "root not bracketed"
> From: [hidden email]
> To: [hidden email]
> CC: [hidden email]
> Date: Tue, 8 Jun 2010 11:30:29 +0200
>
> On Thu, 2010-06-03 at 18:37 +0000, Jinping Shi wrote:
> > in file ./ql/math/solver1d.hpp, the following bug causes error like
> >
> > "root not bracketed: f[2.22045e-16,3] ->
> > [-1.534964e-04,-5.486424e-02]"
> >
> >
> > 185 fxMin_ = f(xMin_);
> > 186 //if (fxMin_ == 0.0) // Bugfix JSHI
> > 187 if (fxMin_ <= accuracy)
> > 188 return xMin_;
> > 189
> > 190 fxMax_ = f(xMax_);
> > 191 //if (fxMax_ == 0.0) // Bugfix JSHI
> > 192 if (fxMax_ <= accuracy)
> > 193 return xMax_;
>
> Yes, I remember this. The problem is, in this method we don't know if
> the accuracy was requested on x of f(x); that differs from solver to
> solver. If f(xMin_) < accuracy, we can return xMin_ if the accuracy was
> requested on f(x), since f(xMin_) is close enough to 0; but if it was on
> x, we can't return as we're not sure that xMin_ is close enough to the
> actual root X (i.e., that xMin_ - X < accuracy.) The only case in which
> we can return is when f(xMin_) is precisely 0, because we found the
> root. So, as of now, it's correct for the solver not to return
> immediately. To fix the problem, we could add some logic later (when
> the error message is thrown) to ensure that the missing bracketing is
> not due to numerical error; or we could add some property to the solvers
> so that we know whether the accuracy is on x or f(x), and return when
> possible. Would you mind trying to code that?
>
> Thanks,
> Luigi
>
>
> --
>
> Quote me as saying I was misquoted.
> -- Groucho Marx
>
>


The New Busy think 9 to 5 is a cute idea. Combine multiple calendars with Hotmail. Get busy.
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Building Apps on iPhone or Android

Billy Ng-5
Hi,
 
I am a student planning to develope an application using quantlib under iPhone or Android.
Anything to watch out and any experience to share?
 
Furthermore, how portable is the Java version of quantlib under different platform?
 
Two models in mind, Server based with mobile phone as a front end or simply an App in the phone
Many Thanks
 
Billy

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Building Apps on iPhone or Android

Billy Ng-5
          Hi,
 
I am a student planning to develope an application using quantlib under iPhone or Android.
Anything to watch out and any experience to share?
 
Furthermore, how portable is the Java version of quantlib under different platform?
 
Two models in mind, Server based with mobile phone as a front end or simply an App in the phone
Many Thanks
 
Billy

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Building Apps on iPhone or Android

Andreas Spengler-2
Hi,

Billy Ng wrote

> Furthermore, how portable is the Java version of quantlib under
> different platform?

Quantlib under Java uses SWIG, so you would most probably need to get ql
itself ported to the target platform natively...

Rgds,

Anderas


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Building Apps on iPhone or Android

Billy Ng-5

Hi Anderas,

Thank you for  your reply

>Quantlib under Java uses SWIG, so you would most probably need to get ql
>itself ported to the target platform natively...

Has anyone done it before?
Is it straight forward or need much fine tuning?

There is a JQuantlib http://www.jquantlib.org/index.php/Main_Page which is based on quantlib 0.9.7
It is rewritten instead of a direct translation using SWIG
Any comment on this too?

Billy Ng
-----Original Message-----
From: Andreas Spengler [mailto:[hidden email]]
Sent: Monday, June 14, 2010 9:56 PM
To: [hidden email]
Subject: Re: [Quantlib-users] Building Apps on iPhone or Android


Hi,

Billy Ng wrote

> Furthermore, how portable is the Java version of quantlib under
> different platform?

Quantlib under Java uses SWIG, so you would most probably need to get ql
itself ported to the target platform natively...

Rgds,

Anderas


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.829 / Virus Database: 271.1.1/2936 - Release Date: 06/14/10 14:35:00
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Building Apps on iPhone or Android

Peter Toke Heden Ahlgren
Hi Billy

I do not know how new you are to this forum. But a month ago the following was posted here. I guess you should try to get in touch with Tawanda.

Peter

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

From: Tawanda Gwena [mailto:[hidden email]]
Sent: Saturday, May 01, 2010 3:24 PM
To: [hidden email]
Subject: [Quantlib-users] A small video of QuantLib on the iPhone

I've put up a small video showing QuantLib in action on the iPhone.

http://tgwena.blogspot.com/

Work continues on exposing the whole quantlib library intuitively.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Building Apps on iPhone or Android

Billy Ng-5
Hi Peter,

Many Thanks and his video is very good.
I emailed Tawanda already
I joined this group just yesterday.

I did search in the archive before posting.
However, I mistakenly "selected" the user mailing list before search, which actually means "do not search the selected archive"
My apology

There seems like no porting to Android yet

Billy

-----Original Message-----
From: Peter Toke Heden Ahlgren [mailto:[hidden email]]
Sent: Tuesday, June 15, 2010 3:58 PM
To: 'Billy Ng'; [hidden email]
Subject: SV: [Quantlib-users] Building Apps on iPhone or Android


Hi Billy

I do not know how new you are to this forum. But a month ago the following was posted here. I guess you should try to get in touch with Tawanda.

Peter

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

From: Tawanda Gwena [mailto:[hidden email]]
Sent: Saturday, May 01, 2010 3:24 PM
To: [hidden email]
Subject: [Quantlib-users] A small video of QuantLib on the iPhone

I've put up a small video showing QuantLib in action on the iPhone.

http://tgwena.blogspot.com/

Work continues on exposing the whole quantlib library intuitively.
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.829 / Virus Database: 271.1.1/2936 - Release Date: 06/15/10 02:35:00
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: bug related to error message "root not bracketed"

Luigi Ballabio
In reply to this post by Jinping Shi
On Fri, 2010-06-11 at 14:23 +0000, Jinping Shi wrote:

> My further investigation shows that the problem is somewhere else.
>  
> I was using <Forward, Linear> in the boostraping and when the input
> data is noisy (or too many data points), the forward rate can be
> negative.  So the change should be in
>  
> /ql/termstructures/iterativebootstrap.hpp
>
>  157 // bracket
>  158 Real min = Traits::minValueAfter(i, ts_->data_);// -2.0;  //JSHI,
> allow negative if using forward linear

There's no need to do that (especially since the modification should
affect only the forwards, while the code above is generic.)  If the
problem is negative rates, you can enable them.  On Windows, open
<ql/userconfig.hpp> and uncomment the line

#   define QL_NEGATIVE_RATES

on Linux and any other platform where you run configure, run it as:

./configure --enable-negative-rates

In both cases, recompile the library after the modification.

Luigi

P.S. Maybe we should enable negative rates by default.  People, what do
you think?


--

The young man knows the rules, but the old man knows the exceptions.
-- O. W. Holmes



------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit.  See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: bug related to error message "root not bracketed"

Ferdinando M. Ametrano-2
On Thu, Jun 24, 2010 at 11:59 AM, Luigi Ballabio
<[hidden email]> wrote:
> P.S. Maybe we should enable negative rates by default.  People, what do
> you think?

Negative rates are an alert that your curve is wrong (besides few
extreme cases as JPY very short tenor). A lot of people is stumbling
into negative rates just because they have obsolete curve definitions
which are not adequate with the current market conditions (multiple
Libor curves, collateral discounting, etc)

So I'll personally keep negative rates turned off when compiling the library.
Anyway we could allow negative rate just to shake off naive users'
questions... ;-D

ciao -- Nando

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Quantlib Error: time (30.0037) is past max curve time (30.001)

Jinping Shi
In reply to this post by Luigi Ballabio
I am using the sample code swapvaluation.cpp to build termstructure, and made two changes for USD
 
(1) Calendar swap_calendar = UnitedStates(UnitedStates::GovernmentBond);
 
(2) boost::shared_ptr<IborIndex> swap_FloatingLegIndex(new USDLibor(3*Months) );
 
There seems some inconsistency between these two and I see the following type error message for certain dates:
20090825, 20090826, 20091222, 20100330, 20100523, 20100504, 20100505, 20100823, 20100824, 20100825
 
It seems a 30 year swap rate, by using some day count, becomes more than 30 years.  My swapr ates are quoted as Thirty360(), as in class SwapRateHelper, and the termstructure day count is using ActualActual(ActualActual::ISDA) as in class PiecewiseYieldCurve<Discount,LogLinear>.
 
Where is the problem and how to correct it?
 
If in (1) I use UnitedKingdom(UnitedKingdom::Exchange), the problem goes away.  Is that the right thing to do?
 
 
 
 
run date : 2010-8-25 16:0:00
Swap Settlement date: Friday, August 27th, 2010
 running 14040H
terminate called after throwing an instance of 'QuantLib::Error'
  what(): 
../../../../utility_sys/bin2/include/ql/termstructures/iterativebootstrap.hpp:199: In function `void QuantLib::IterativeBootstrap<Curve>::calculate() const [with Curve = QuantLib::PiecewiseYieldCurve<QuantLib::Discount, QuantLib::LogLinear, QuantLib::IterativeBootstrap>]':
1st iteration: failed at 10th instrument, maturity August 27th, 2040, reference date August 27th, 2010:
termstructure.cpp:84: In function `void QuantLib::TermStructure::checkRange(QuantLib::Time, bool) const':
time (30.0037) is past max curve time (30.001)
Abort
 
 
Thanks,
Jinping Shi
 

------------------------------------------------------------------------------
Automate Storage Tiering Simply
Optimize IT performance and efficiency through flexible, powerful,
automated storage tiering capabilities. View this brief to learn how
you can reduce costs and improve performance.
http://p.sf.net/sfu/dell-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Quantlib Error: time (30.0037) is past max curve time (30.001)

Jinping Shi
Found the solution and please ignore the early message.  I just need to add one more line:
 
swapTermStructure->enableExtrapolation();
 
(Maybe it is worth it to add this line to the example code swapvaluation.cpp)
 
Thanks!

 

From: [hidden email]
To: [hidden email]
CC: [hidden email]
Subject: Quantlib Error: time (30.0037) is past max curve time (30.001)
Date: Thu, 9 Sep 2010 14:35:49 +0000

I am using the sample code swapvaluation.cpp to build termstructure, and made two changes for USD
 
(1) Calendar swap_calendar = UnitedStates(UnitedStates::GovernmentBond);
 
(2) boost::shared_ptr<IborIndex> swap_FloatingLegIndex(new USDLibor(3*Months) );
 
There seems some inconsistency between these two and I see the following type error message for certain dates:
20090825, 20090826, 20091222, 20100330, 20100523, 20100504, 20100505, 20100823, 20100824, 20100825
 
It seems a 30 year swap rate, by using some day count, becomes more than 30 years.  My swapr ates are quoted as Thirty360(), as in class SwapRateHelper, and the termstructure day count is using ActualActual(ActualActual::ISDA) as in class PiecewiseYieldCurve<Discount,LogLinear>.
 
Where is the problem and how to correct it?
 
If in (1) I use UnitedKingdom(UnitedKingdom::Exchange), the problem goes away.  Is that the right thing to do?
 
 
 
 
run date : 2010-8-25 16:0:00
Swap Settlement date: Friday, August 27th, 2010
 running 14040H
terminate called after throwing an instance of 'QuantLib::Error'
  what(): 
../../../../utility_sys/bin2/include/ql/termstructures/iterativebootstrap.hpp:199: In function `void QuantLib::IterativeBootstrap<Curve>::calculate() const [with Curve = QuantLib::PiecewiseYieldCurve<QuantLib::Discount, QuantLib::LogLinear, QuantLib::IterativeBootstrap>]':
1st iteration: failed at 10th instrument, maturity August 27th, 2040, reference date August 27th, 2010:
termstructure.cpp:84: In function `void QuantLib::TermStructure::checkRange(QuantLib::Time, bool) const':
time (30.0037) is past max curve time (30.001)
Abort
 
 
Thanks,
Jinping Shi
 

------------------------------------------------------------------------------
Automate Storage Tiering Simply
Optimize IT performance and efficiency through flexible, powerful,
automated storage tiering capabilities. View this brief to learn how
you can reduce costs and improve performance.
http://p.sf.net/sfu/dell-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Quantlib Error: time (30.0037) is past max curve time (30.001)

Luigi Ballabio
On Thu, 2010-09-09 at 15:25 +0000, Jinping Shi wrote:
> Found the solution and please ignore the early message.  I just need
> to add one more line:
>  
> swapTermStructure->enableExtrapolation();

Yes, that works, but it shouldn't be necessary.
It's probably a calendar issue. You're using UnitedStates, while
USDLibor uses a joint calendar of UnitedStates and UnitedKingdom.

Luigi


--

There is no such thing as public opinion. There is only published
opinion.
-- Winston Churchill



------------------------------------------------------------------------------
Automate Storage Tiering Simply
Optimize IT performance and efficiency through flexible, powerful,
automated storage tiering capabilities. View this brief to learn how
you can reduce costs and improve performance.
http://p.sf.net/sfu/dell-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users