Crashing error in bootstrap

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Crashing error in bootstrap

Chak Jack Wong
Hi,
If I build 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.

However, I haven't understood gone through the code in detail yet, please see whether this revision is appropriate.

Jack
 

 DiscountFactor FuturesRateHelper::discountGuess() const {
            QL_REQUIRE(termStructure_ != 0, "term structure not set");
            // extrapolation shouldn't be needed if the input makes sense
            // but we'll play it safe
            return termStructure_->discount(ImmDate_,true) /
                   (1.0+(100.0-quote_->value())/100.0*yearFraction_);
        }
 

DiscountFactor PiecewiseFlatForward::discountImpl(
            Time t, bool extrapolate) const {
                if (needsBootstrap_)
                    bootstrap();
                if (t == 0.0) {
                    return discounts_[0];
                } else {
                    int n = referenceNode(t, extrapolate);
                    if (t == times_[n]) {
                        return discounts_[n];
                    } else {
                        //n may be zero here!!!!!!!!!!!!!!!
                        return discounts_[n-1] *
                            QL_EXP(-forwards_[n] * (t-times_[n-1]));
                    }
                }
                QL_DUMMY_RETURN(DiscountFactor());
        }