final Date settlement) {
if (frequency == Frequency.NoFrequency || frequency == Frequency.Once) {
frequency = Frequency.Annual;
}
final InterestRate y = new InterestRate(yield, dayCounter, compounding, frequency);
/* @Real */double price = 0.0;
/* @DiscountFactor */double discount = 1.0;
Date lastDate = new Date();
for (int i = 0; i < cashflows.size(); ++i) {
if (cashflows.get(i).hasOccurred(settlement)) {
continue;
}
final Date couponDate = cashflows.get(i).date();
/* @Real */final double amount = cashflows.get(i).amount();
if (lastDate.isNull()) {
// first not-expired coupon
if (i > 0) {
lastDate = cashflows.get(i - 1).date().clone();
} else {
final Object cpnObj = cashflows.get(i);
final Coupon coupon = Coupon.class.isAssignableFrom(cpnObj.getClass()) ? (Coupon)cpnObj : null;
if (coupon != null) {
lastDate = coupon.accrualStartDate().clone();
} else {
lastDate = couponDate.sub(new Period(1, TimeUnit.Years));
}
}
discount *= y.discountFactor(settlement, couponDate, lastDate, couponDate);
} else {
discount *= y.discountFactor(lastDate, couponDate);
}
lastDate = couponDate.clone();
price += amount * discount;
}