notionals_.clear();
Date lastPaymentDate = new Date();
notionalSchedule_.add(new Date());
for (int i=0; i<cashflows_.size(); ++i) {
final Object cfObj = cashflows_.get(i);
final Coupon coupon = Coupon.class.isAssignableFrom(cfObj.getClass()) ? (Coupon)cfObj : null;
if (coupon==null){
continue;
}
final double notional = coupon.nominal();
// we add the notional only if it is the first one...
if (notionals_.isEmpty()) {
notionals_.add(coupon.nominal());
lastPaymentDate = coupon.date().clone();
} else if (!Closeness.isClose(notional, notionals_.get(notionals_.size() -1 ))) {
// ...or if it has changed.
QL.require(notional < notionals_.get(notionals_.size()-1), "increasing coupon notionals");
notionals_.add(coupon.nominal());
// in this case, we also add the last valid date for
// the previous one...
notionalSchedule_.add(lastPaymentDate);
// ...and store the candidate for this one.
lastPaymentDate = coupon.date().clone();
} else {
// otherwise, we just extend the valid range of dates
// for the current notional.
lastPaymentDate = coupon.date().clone();
}
}
QL.require(!notionals_.isEmpty(), "no coupons provided");
notionals_.add(0.0);
notionalSchedule_.add(lastPaymentDate);