Re: Cannot bootstrap a yieldcurve

Posted by Leon Sit on
URL: http://quantlib.414.s1.nabble.com/Cannot-bootstrap-a-yieldcurve-tp8530p8542.html

I am using Quantlib 1.0

The actual code is mangled with other code so it is hard to show. The
function in question is

int yield_curve_setup(YieldCurve* yieldcurve, const unsigned& quote_size,
                      const long& settlementDate_int, const string*
maturitiesLabel,
                      const double* quotes, const RateTypeEnum_C* rateTypes) {
    try {

        yieldcurve->rateTypes = new RateTypeEnum_C[quote_size];
        std::copy(rateTypes, rateTypes + quote_size, yieldcurve->rateTypes);

        //for now assume that we have the quote with the same format as quantlib
        yieldcurve->calendar = TARGET();
        DayCounter depositDayCounter = Actual360();

        Date settlementDate(settlementDate_int);
        int fixingDays = 0;
        boost::shared_ptr<RateHelper> rate;

        std::vector<boost::shared_ptr<RateHelper> >
depositeFutureSwapInstruments;
        Date imm = IMM::nextDate(settlementDate, true);
        boost::shared_ptr<IborIndex> swFloatingLegIndex(new Euribor6M);
        boost::shared_ptr<std::vector<boost::shared_ptr<RateHelper> >
>  depositFutureSwapInstruments(new
std::vector<boost::shared_ptr<RateHelper> >);
        for( unsigned i = 0; i < quote_size; ++i) {
            TimeUnit timeunit;
            int length;
            parseLabel(maturitiesLabel[i], length, timeunit);
            if(rateTypes[i] == DepositQuote) {
                boost::shared_ptr<Quote> depositRate(new
SimpleQuote(quotes[i]));
                rate.reset( new DepositRateHelper(
                                Handle<Quote>(depositRate),
                                length* timeunit, fixingDays,
                                yieldcurve->calendar, ModifiedFollowing,
                                true, depositDayCounter));
            } else if(rateTypes[i] == SwapQuote) {
                Frequency swFixedLegFrequency = Annual;
                BusinessDayConvention swFixedLegConvention = Unadjusted;
                DayCounter swFixedLegDayCounter = Thirty360(Thirty360::USA);
                boost::shared_ptr<Quote> swapRate(new SimpleQuote(quotes[i]));
                rate.reset( new SwapRateHelper(
                                Handle<Quote>(swapRate), length*timeunit,
                                yieldcurve->calendar, swFixedLegFrequency,
                                swFixedLegConvention, swFixedLegDayCounter,
                                swFloatingLegIndex));
            } else if(rateTypes[i] == FutureQuote) {
                Integer futMonths = 3;
                boost::shared_ptr<Quote> futurePrice(new
SimpleQuote(quotes[i]));
                rate.reset(new FuturesRateHelper(
                               Handle<Quote>(futurePrice),
                               imm,
                               futMonths, yieldcurve->calendar,
ModifiedFollowing,
                               true, depositDayCounter));
                imm = IMM::nextDate(imm+1);
            }
            depositFutureSwapInstruments->push_back(rate);
        }

        boost::shared_ptr<YieldTermStructure> depoFutureSwapStructure(
            new PiecewiseYieldCurve<Discount, LogLinear>(
                settlementDate, *depositFutureSwapInstruments,
                depositDayCounter, 10e-5));

        yieldcurve->discountingTermStructure.linkTo(depoFutureSwapStructure);

        return 1;
    } catch(std::exception& e) {
        std::cerr << e.what() << std::endl;
        return 0;
    } catch (...) { // have to catch all the pokemon exception
        std::cerr << "Unknown Yield Curve Exception" << std::endl;
        return 0;
    }
};

with YieldCurve defined as

typedef struct
{
//  double* quotes;
  RateTypeEnum_C* rateTypes;
//  boost::shared_ptr<std::vector<boost::shared_ptr<RateHelper> > >
depositFutureSwapInstruments;
  Calendar calendar;
  RelinkableHandle<YieldTermStructure> discountingTermStructure;
}YieldCurve;

When the data above passed to this function, everything is fine and
runs without a problem. However then I try to call maxDate() from this
curve, I get a bootstrap exception like stated

1st iteration: failed at 15th instrument, maturity October 21st, 2011,
reference date August 15th, 2010: root not bracketed:
f[2.22045e-016,0.992176] -> [-4.501710e+015,-2.753185e-003]




On Tue, Oct 19, 2010 at 9:38 AM, Luigi Ballabio
<[hidden email]> wrote:

> On Tue, 2010-10-19 at 09:32 -0500, Leon Sit wrote:
>> I am using the following set of rates to bootstrap a yieldcurve [...] Does
>> anybody know what I might have missed?
>
> Can you show the rest of the code?
>
> Luigi
>
>
> --
>
> Hofstadter's Law:
> It always takes longer than you expect, even when you take
> Hofstadter's Law into account.
>
>
>

------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users