Amine Ifri
2017-06-28 10:41:29 UTC
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
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