|
From: Luca B. <luc...@gm...> - 2008-07-15 16:22:08
|
Hi all,
the following code throws an exception when
bond.cleanPriceFromZSpread(...) is called.
The issue comes from the fact that, in this example, there's no
settlement adjustment, so the function
ZeroSpreadedTermStructure::zeroYieldImpl(Time t) needs to be evaluated
for t=0.
I got around this issue by adding the seemingly harmless
if(t==0.) return 1.;
at line 86 of file ql/termstructures/yield/zeroyieldstructure.hpp
Anyone has a better idea?
Luca
#include <ql/quantlib.hpp>
using namespace QuantLib;
int main(int, char* [])
{
try {
Calendar calendar = TARGET();
Date todaysDate(30, Jun, 2008);
Settings::instance().evaluationDate() = todaysDate;
Schedule schedule = MakeSchedule(todaysDate, todaysDate + 10*Years,
Period(Annual), calendar, Unadjusted);
std::vector<double> coupons(1, 0.07);
FixedRateBond bond(0, 10000., schedule, coupons, Actual360(),
ModifiedFollowing);
Handle<YieldTermStructure> tsCurve(boost::shared_ptr<FlatForward>(
new FlatForward(todaysDate, 0.05, Actual360(),
Compounded)));
boost::shared_ptr<DiscountingBondEngine> engine(new
DiscountingBondEngine(tsCurve));
bond.setPricingEngine(engine);
bond.cleanPriceFromZSpread(0.0200, Actual360(), Compounded,
Annual); // <- this throws
}
catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return 1;
}
|