19#include <ql/cashflows/floatingratecoupon.hpp>
27Real
CashFlows::spreadNpv(
const Leg& leg,
const YieldTermStructure& discountCurve,
bool includeSettlementDateFlows,
28 Date settlementDate, Date npvDate) {
33 if (settlementDate == Date())
34 settlementDate = Settings::instance().evaluationDate();
36 if (npvDate == Date())
37 npvDate = settlementDate;
40 for (Size i = 0; i < leg.size(); ++i) {
42 QuantLib::ext::shared_ptr<FloatingRateCoupon> floatCoupon = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(leg[i]);
44 if (floatCoupon && !floatCoupon->hasOccurred(settlementDate, includeSettlementDateFlows)) {
46 spreadNpv += floatCoupon->nominal() * floatCoupon->accrualPeriod() * floatCoupon->spread() *
47 discountCurve.discount(floatCoupon->date());
51 return spreadNpv / discountCurve.discount(npvDate);
62 for (Size i = 0; i < leg.size(); ++i) {
63 Date cashflowDate = leg[i]->date();
64 if (startDate < cashflowDate && cashflowDate <= endDate)
74 for (Size i = 0; i < leg.size(); ++i) {
75 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(leg[i]);
86 for (Size i = 0; i < leg.size(); ++i) {
87 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(leg[i]);
89 couponDcfRates.push_back(coupon->rate() * coupon->accrualPeriod());
additional cash-flow analysis functions
static Real spreadNpv(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
NPV due to any spreads on a leg.
static Real sumCashflows(const Leg &leg, const Date &startDate, const Date &endDate)
Return the sum of the cashflows on leg after startDate and before or on endDate.
static std::vector< Rate > couponDcfRates(const Leg &leg)
static std::vector< Rate > couponRates(const Leg &leg)