Hi,
there is a problem when quantlib is trying to get the yield from the price for zero coupon bond.
In the dirtyPriceFromYield() method, quantlib sets time t2 to ( CouponDate - LastCouponDate) but in Once frequency lastCouponDate is the issue Date so the t2 time is wrong in this case :
Real price = 0.0;
DiscountFactor discount = 1.0;
Date lastDate = Date();
for (Size i=0; i<cashflows.size(); ++i) {
// discard expired coupons
#if QL_TODAYS_PAYMENTS
if (cashflows[i]->date() < settlement)
#else
if (cashflows[i]->date() <= settlement)
#endif
continue;
Date nextDate = cashflows[i]->date();
Real amount = cashflows[i]->amount();
if (i == cashflows.size()-1)
amount += redemption;
Time t1, t2;
if (lastDate == Date()) {
// first not-expired coupon
if (i > 0) {
lastDate = cashflows[i-1]->date();
} else {
boost::shared_ptr<Coupon> coupon
=
boost::dynamic_pointer_cast<Coupon>(cashflows[i]);
if (coupon)
lastDate = coupon->accrualStartDate();
else
lastDate = nextDate -
1*Years;
}
t1 = dayCounter.yearFraction(settlement, nextDate,
lastDate, nextDate);
t2 = dayCounter.yearFraction(lastDate, nextDate);
} else
{
t1 = dayCounter.yearFraction(lastDate, nextDate);
t2 = t1;
}
discount /= QL_POW(1 + yield*t2, t1/t2);
price += amount * discount;
lastDate = nextDate;
}
return price;
}
regards.
Découvrez le nouveau Yahoo! Mail :
250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail