@Override
public /* @Real */ double swapletRate() {
List<Date> fixingDates = coupon.fixingDates();
InterestRateIndex index = coupon.index();
@Natural int cutoffDays = 0; // to be verified
Date startDate = coupon.accrualStartDate().sub(cutoffDays);
Date endDate = coupon.accrualEndDate().sub(cutoffDays);
Date d1 = new Date(startDate.serialNumber());
Date d2 = new Date(startDate.serialNumber());
QL.require(fixingDates.size() > 0, "fixing date list empty");
QL.require(index.valueDate(fixingDates.get(0)).le(startDate), "first fixing date valid after period start");
QL.require(index.valueDate(fixingDates.get((fixingDates.size()-1))).ge(startDate), "last fixing date valid before period end");
@Rate double avgBMA = 0.0;
int days = 0;
for (int i=0;i<(fixingDates.size()-1);i++) {
Date valueDate = index.valueDate(fixingDates.get(i));
Date nextValueDate = index.valueDate(fixingDates.get(i+1));
if (fixingDates.get(i).ge(endDate) || valueDate.ge(valueDate)) {
break;
}
if (fixingDates.get(i+1).lt(startDate) || nextValueDate.le(startDate)) {
continue;
}
d2 = Date.min(nextValueDate, endDate);
avgBMA += (index.fixing(fixingDates.get(i))) * (d2.sub(d1));
days += d2.sub(d1);
d1 = d2;
}