Insightful

Forum Navigation:


FORUMS > Programming and Software Forum < refresh >
Topic Title: Quantlib error for 0/0 evaluation
Created On Sun Sep 07, 03 11:12 PM
Topic View:

View thread in raw text format


asd
Senior Member

Posts: 660
Joined: Aug 2002

Sun Sep 07, 03 11:12 PM
User is offline


I get an exception when I try to run the Quantlib example application BermudanSwaption(Release 0.3.3),after compiling it with Borland C++ compiler on Win 98.(Though it works fine on some other box using MSVC++/NT).
I found the problem to be in the function TermStructure::zeroCoupon , when the first swap is evaluated. It occurs at the instruction :

return Rate((1.0/df-1.0)/t);

When t=0 and (1.0/df-1.0)=0 ,0/0 is evaluated and exception occurs.

My question is , how it runs in other environments without problem? Also, can I avoid it by tweaking some configuration paramers ?


Thanks,
asd

-------------------------
Life is a journey and not a destination
quant code directory
 
Reply
   
Quote
   
Top
   
Bottom
     



ametrano
Member

Posts: 144
Joined: Jul 2002

Mon Sep 08, 03 01:28 PM
User is offline View users profile

This is a genuine bug. I will look into it, but it will take some time.

I will probably try to make the QuantLib (cppunit) test-suite run under Borland before, since this might reveal more issues with the Borland compiler.

While I try to read the Wilmott forum regularly, you might consider posting the bug to the QuantLib-users mailing list, or even better to submit it to the QuantLib Bug Tracker

Thank you for the report

ciao -- Nando
 
Reply
   
Quote
   
Top
   
Bottom
     



mj
Senior Member

Posts: 3030
Joined: Dec 2001

Mon Sep 08, 03 02:04 PM
User is offline View users profile

the borland compiler is pickier about floating point exceptions than g++ or Visual C++, they tend to silently ignore things which Borland protests about.



-------------------------
Quant Job Interview Questions and Answers now available on lulu.com and amazon.com
 
Reply
   
Quote
   
Top
   
Bottom
     



asd
Senior Member

Posts: 660
Joined: Aug 2002

Mon Sep 08, 03 06:11 PM
User is offline


Ametrano & MJ,

Thanks a lot for your replies and the tips. For the moment, I just modified the implementation of TermStructure::zeroCoupon in my box, to use a macro for safe divide - which returns 1 for 0/0 and it works fine .



Regards,
asd




-------------------------
Life is a journey and not a destination
quant code directory
 
Reply
   
Quote
   
Top
   
Bottom
     



ametrano
Member

Posts: 144
Joined: Jul 2002

Mon Sep 08, 03 06:28 PM
User is offline View users profile

Quote

Originally posted by: asd
Ametrano & MJ,
I just modified the implementation of TermStructure::zeroCoupon in my box, to use a macro for safe divide - which returns 1 for 0/0 and it works fine.



That's OK, of course... talk about the open source magic

The point is the code should never run into 0/0...

Anyway... today I worked on the QuantLib test-suite for Borland and it now runs (with CppUnit 1.9.10). You know what? All the term-structure related tests fail, pointing to the bug you discovered. I should have done this before releasing 0.3.3, but hey, you're the first one to use the Borland compiler (QuantLib developers excluded)!

I will keep you updated

ciao -- Nando
 
Reply
   
Quote
   
Top
   
Bottom
     



ametrano
Member

Posts: 144
Joined: Jul 2002

Thu Oct 09, 03 05:27 PM
User is offline View users profile

The problem has been fixed in the current CVS.

As promised it's now also available a working test-suite for Borland. It is actually "almost working", since there is still one test that fails with an unpleasant crash. Hopefully it will be fixed for the next release planned before this year end.

ciao -- Nando
 
Reply
   
Quote
   
Top
   
Bottom
     



mj
Senior Member

Posts: 3030
Joined: Dec 2001

Thu Oct 09, 03 05:32 PM
User is offline View users profile

can i recommend adding

_controlfp(_EM_INEXACT, _MCW_EM ) ;


to the visual C++ version, then you'll get the crash in visual C++ too.


-------------------------
Quant Job Interview Questions and Answers now available on lulu.com and amazon.com
 
Reply
   
Quote
   
Top
   
Bottom
     



ametrano
Member

Posts: 144
Joined: Jul 2002

Fri Nov 21, 03 07:03 PM
User is offline View users profile

QuantLib 0.3.4 has been released today, and also includes a full test suite for Borland. All the Borland problems I did know of have been fixed.

As for the _controlfp in VC++, I will add it. Is there something equivalent for gcc?

thank you

ciao -- Nando
 
Reply
   
Quote
   
Top
   
Bottom
     



mj
Senior Member

Posts: 3030
Joined: Dec 2001

Sat Nov 22, 03 01:39 PM
User is offline View users profile

dont know


-------------------------
Quant Job Interview Questions and Answers now available on lulu.com and amazon.com
 
Reply
   
Quote
   
Top
   
Bottom
     



RedeR
Member

Posts: 75
Joined: Mar 2002

Mon May 29, 06 02:05 PM
User is offline View users profile

_control87 does it for gcc.

One can also install its own FPU exception using signal. It works for msvc as well (without SEH). It does not behave the way you would like when used in a dll called from excel (crashes the latter, whereas SEH behaves nicely).

By the way, could you make the automatic linking (#pragma comment(lib,ql) ) optional ? Also, make "errors.cpp" inlined (ok, off topic).

Thanks for the QL. Very usefull.

Quote

Originally posted by: ametrano
Q

As for the _controlfp in VC++, I will add it. Is there something equivalent for gcc?



 
Reply
   
Quote
   
Top
   
Bottom
     



lballabio
Senior Member

Posts: 882
Joined: Jan 2004

Mon May 29, 06 02:26 PM
User is offline View users profile

Quote

Originally posted by: RedeR
Also, make "errors.cpp" inlined (ok, off topic).


I don't think it would make much of a difference. The functions are not so lightweight, and besides, they're only called when an exception occur, and the gained cycles would probably be drowned into those used for stack unwinding and stuff.

Luigi
 
Reply
   
Quote
   
Top
   
Bottom
     



RedeR
Member

Posts: 75
Joined: Mar 2002

Mon May 29, 06 04:06 PM
User is offline View users profile

Not a speed concern, rather a "small app with no lib/cpp include" problem.

Quote

Originally posted by: lballabio
Quote

Originally posted by: RedeR
Also, make "errors.cpp" inlined (ok, off topic).


I don't think it would make much of a difference. The functions are not so lightweight, and besides, they're only called when an exception occur, and the gained cycles would probably be drowned into those used for stack unwinding and stuff.

Luigi


 
Reply
   
Quote
   
Top
   
Bottom
     



lballabio
Senior Member

Posts: 882
Joined: Jan 2004

Mon May 29, 06 05:27 PM
User is offline View users profile

Quote

Originally posted by: RedeR
Not a speed concern, rather a "small app with no lib/cpp include" problem.


Hard to do, unless you're using just errors.cpp and very little else...
 
Reply
   
Quote
   
Top
   
Bottom
     

View thread in raw text format
FORUMS > Programming and Software Forum < refresh >

Forum Navigation:

© All material, including contents and design, copyright Wilmott Electronic Media Limited - FuseTalk 4.01 © 1999-2010 FuseTalk Inc.