Date dtStart = Date(); Time t = 0.0; NPV_ = 0.0; QL_REQUIRE(!discountCurve_.empty(), "no term structure set"); Date settlement = settlementDate(); double dAmount, dDiscount = 0.0; NPV_ = 0.0; // add the discounted cash flows including redemption for (Size i=0; idate(); #if QL_TODAYS_PAYMENTS if (d >= settlement) { #else if (d > settlement) { #endif if (dtStart == Date()) { boost::shared_ptr coupon = boost::dynamic_pointer_cast(cashFlows_[i]); dtStart = coupon->accrualStartDate(); t = dayCount_.yearFraction(settlement, d, dtStart, d); dDiscount = discountCurve_->discount(t); dAmount = cashFlows_[i]->amount(); NPV_ += dAmount * dDiscount; } else { boost::shared_ptr coupon = boost::dynamic_pointer_cast(cashFlows_[i]); dtStart = coupon->accrualStartDate(); t += dayCount_.yearFraction(dtStart, d); dDiscount = discountCurve_->discount(t); dAmount = cashFlows_[i]->amount(); NPV_ += dAmount * dDiscount; } } } Date redemptionDate = redemption_->date(); if (dtStart == Date()) { dtStart = redemptionDate - (12/frequency_)*Months; t = dayCount_.yearFraction(settlement, redemptionDate, dtStart, redemptionDate); dDiscount = discountCurve_->discount(t); } else { // Take previous Discount at (t) dDiscount = discountCurve_->discount(t); } dAmount = redemption_->amount(); NPV_ += dAmount * dDiscount;