Bugs in TermStructure::zeroCoupon() discussed on www.Wilmott.com
Posted by Liguo Song on Sep 09, 2003; 2:02pm
URL: http://quantlib.414.s1.nabble.com/Bugs-in-TermStructure-zeroCoupon-discussed-on-www-Wilmott-com-tp10347.html
Hi, Nando,
I noticed the discussion about the 0/0 bug in the TermStructure::zeroCoupon() on
the forum at www.Wilmott.com. So, I checked the source code and find that the
following code is problematic.
inline Rate TermStructure::zeroCoupon(Time t, int f,
bool extrapolate) const {
DiscountFactor df = discountImpl(t, extrapolate);
if (f > 0 && t <= (1.0/(double)f))
return Rate((1.0/df-1.0)/t);
if (t == 0.0)
t = 1.0;
return Rate((QL_POW(1.0/df,1.0/(t*f))-1.0)*f);
}
The "if (t == 0.0) " will never be processed as as t <= 1.0/(double)f is always
true when f > 0 and t=0.0. Thus, 0/0 or x/0 will happen as long as f > 0 and t =
0.0.
I am just quite curious about why it didn't happen to any compiler other than
Borland.
I am not knowledgable enough to offer any remedy here. Anyone up for a patch?
Later.
Liguo