final Date paymentDate = cf.date();
boolean firstCouponFound = false;
/*@Real*/double nominal = Constants.NULL_REAL;
/*@Time*/double accrualPeriod = Constants.NULL_REAL;
DayCounter dc = null;
/*@Rate*/double result = 0.0;
// QL starts at the next cashflow and only continues to the one after to
// check that it isn't the same date. Also stop at the penultimate flow. The last flow
// is not a Coupon
final int startIndex = cashflows_.indexOf(cf);
for (final CashFlow flow : Iterables.unmodifiableIterable(cashflows_.listIterator(startIndex))) {
if (flow.date().ne(paymentDate)) {
break;
}
//TODO: code review: should the last element be excluded?
final Coupon cp = (Coupon)flow;
if (cp != null) {
if (firstCouponFound) {
assert(nominal == cp.nominal() &&
accrualPeriod == cp.accrualPeriod() &&
//FIXME: implement equals for dayCounters!
dc.getClass() == cp.dayCounter().getClass()):
"cannot aggregate accrued amount of two " +
"different coupons on "+ paymentDate.toString();
} else {
firstCouponFound = true;
nominal = cp.nominal();