Dear Community,
I am struggling with an error since yesterday. Basically, I am trying to set up a small interface where input data are spreads which get converted into QL::SpreadCdsHelpers, and then a hazard rate curve gets bootstrapped from these instruments in a piecewise fashion. The steps of my code are the following: 1) creating and initiating the helpers: void CreditCurvefromCDSHelpers::CreateHelpers(const vector<Real>& spreads, const Date& reference_date, const DayCounter& dc, const Calendar& cal, Real rr, const Frequency& freq, const boost::shared_ptr<YieldTermStructure>& discountCurve) { for (int i = 0; i<_number_CDS_contracts_; ++i) { /* create instrument helpers */ helpers_.push_back(boost::shared_ptr<HazardRate::helper>(new SpreadCdsHelper(spreads[i],tenors_[i],2,cal, freq,convention_bd_,rule_dates_,dc, rr, Handle<YieldTermStructure>(discountCurve)))); } this->attachInitialDefaultTermStructwithHelpers(reference_date); } // here we set the initial value for hazard rate curves to a dummy value of 1% to be able to initiate the bootstrapping process: void CreditCurvefromCDSHelpers::attachInitialDefaultTermStructwithHelpers(const Date& reference_date) { std::vector<Date> pillars; for (int i = 0; i< helpers_.size();++i) { pillars.push_back(((this->helpers_)[i])->pillarDate()); } pillars.insert(pillars.begin(),reference_date); /* we set the dummy value of the hazard rate to 1% */ std::vector<Real> h0rates(pillars.size(),0.01); InterpolatedHazardRateCurve<Linear>* h0 = new InterpolatedHazardRateCurve<Linear>(pillars,h0rates,Thirty360()); for (int i = 0; i< helpers_.size();++i) { (boost::dynamic_pointer_cast<SpreadCdsHelper>(helpers_[i]))->setTermStructure(h0); } } 2) Using the constructor for PiecewiseDefaultCurve<HazardRate,Linear,IterativeBootstrap>, I construct a piecewise curve for hazard rates based on the above instruments: defaultcurve_ = boost::make_shared<piecewisedefcurve>(ref_date, helpers_, dc) where piecewisedefcurve is a typedef of QL::PiecewiseDefaultCurve<HazardRate,Linear,IterativeBootstrap> I get the following error: QuantLib::Error: protection can not start after accrual, which is an exception raised in the code line: QL_REQUIRE(protectionStart_ <= schedule[0], ”protection can not start after accrual”) in the CreditDefaultSwap constructor. This effectively means that the program is stuck in the building of the helpers. Any help from fellow members who have seen this error in the past is greatly appreciated ! Thanks, Amine ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Amine,
I assume your rule_dates_ is CDS or CDS0215, i.e. one of the rules that will generate a schedule with a full first coupon? This can not be handled correctly in the current QuantLib (the protection start will be set to “today+1d”, but the accrual start is typically in the past, so the check that throws the exception is just wrong in this context). I think you have two options - use OldCDS or TwentiethIMM for the date rule. Although the first coupon won’t be correct the bootstrapped curve will be ok I think, because the accrual rebate plus the full coupon has approximately the same NPV as the short first coupon. - look at https://github.com/lballabio/QuantLib/pull/112 which updates the CDS framework to the post big bang conventions. However it seems that the branch now doesn’t even build any more. We should really try to clean this up and merge soon. Best Regards Peter
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |