|
From: Nathan A. <nka...@gm...> - 2009-01-06 18:32:16
|
There is a bug in couponpricer.cpp. I found the bug when I tried to evaluate
a cap floor with a coupon that has a payment date on Jan 05, 2009. The
evaluation date was set to Jan 02, 2009. The reference date of the curve was
set to Jan 06, 2009. The method that has the error is shown below starting
at line 38.
void BlackIborCouponPricer::initialize(const FloatingRateCoupon& coupon) {
coupon_ = dynamic_cast<const IborCoupon*>(&coupon);
gearing_ = coupon_->gearing();
spread_ = coupon_->spread();
Date paymentDate = coupon_->date();
const boost::shared_ptr<InterestRateIndex>& index =
coupon_->index();
Handle<YieldTermStructure> rateCurve = index->termStructure();
Date today = Settings::instance().evaluationDate();
if (paymentDate > today) // Error!!! should ask for the reference
date !!!!
discount_ = rateCurve->discount(paymentDate);
else
discount_ = 1.0;
spreadLegValue_ = spread_ * coupon_->accrualPeriod()* discount_;
}
The error occurred in because the payment date of the coupon was between the
evaluation date and the reference date of the curve. The method checks to
see if the payment date is greater than the evaluation date. If it is, then
it tries to get the discount factor of the date from the curve. If the you
ask a curve for the discount factor of a date before its reference date, the
curve will throw you an error. This is what happen to me because Jan 05 our
payment date was greater than Jan 02 our evaluation date and Jan 05 was less
than our reference date of Jan 06.
To fix it, I suggest the following changes to the code that is shown below.
Now the method checks to see if payment date is greater or equal to the
reference date of the curve.
void BlackIborCouponPricer::initialize(const FloatingRateCoupon& coupon) {
coupon_ = dynamic_cast<const IborCoupon*>(&coupon);
gearing_ = coupon_->gearing();
spread_ = coupon_->spread();
Date paymentDate = coupon_->date();
const boost::shared_ptr<InterestRateIndex>& index =
coupon_->index();
Handle<YieldTermStructure> rateCurve = index->termStructure();
Date referenceDate = rateCurve->referenceDate();
if (paymentDate >= referenceDate)
discount_ = rateCurve->discount(paymentDate);
else
discount_ = 1.0;
spreadLegValue_ = spread_ * coupon_->accrualPeriod()* discount_;
}
|