cashflow-analysis functions in addition to those in QuantLib
More...
#include <qle/cashflows/cashflows.hpp>
|
|
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. More...
|
|
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 . More...
|
|
static std::vector< Rate > | couponRates (const Leg &leg) |
|
static std::vector< Rate > | couponDcfRates (const Leg &leg) |
|
cashflow-analysis functions in addition to those in QuantLib
Definition at line 33 of file cashflows.hpp.
◆ CashFlows() [1/2]
◆ CashFlows() [2/2]
◆ spreadNpv()
Real spreadNpv |
( |
const Leg & |
leg, |
|
|
const YieldTermStructure & |
discountCurve, |
|
|
bool |
includeSettlementDateFlows, |
|
|
Date |
settlementDate = Date() , |
|
|
Date |
npvDate = Date() |
|
) |
| |
|
static |
NPV due to any spreads on a leg.
The spread NPV is the sum of the spread-related cash flows on the leg, each discounted according to the given term structure.
- If there are no spreads on the leg, then zero is returned.
- Only applicable to FloatingRateCoupon. Should be expanded if needed for other coupon types e.g. YoYInflationCoupon.
Definition at line 27 of file cashflows.cpp.
28 {
29
30 if (leg.empty())
31 return 0.0;
32
33 if (settlementDate == Date())
34 settlementDate = Settings::instance().evaluationDate();
35
36 if (npvDate == Date())
37 npvDate = settlementDate;
38
40 for (Size i = 0; i < leg.size(); ++i) {
41
42 QuantLib::ext::shared_ptr<FloatingRateCoupon> floatCoupon = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(leg[i]);
43
44 if (floatCoupon && !floatCoupon->hasOccurred(settlementDate, includeSettlementDateFlows)) {
45
46 spreadNpv += floatCoupon->nominal() * floatCoupon->accrualPeriod() * floatCoupon->spread() *
47 discountCurve.discount(floatCoupon->date());
48 }
49 }
50
51 return spreadNpv / discountCurve.discount(npvDate);
52}
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.
◆ sumCashflows()
Real sumCashflows |
( |
const Leg & |
leg, |
|
|
const Date & |
startDate, |
|
|
const Date & |
endDate |
|
) |
| |
|
static |
Return the sum of the cashflows on leg
after startDate
and before or on endDate
.
Definition at line 54 of file cashflows.cpp.
54 {
55
56
57 if (leg.empty())
58 return 0.0;
59
60
62 for (Size i = 0; i < leg.size(); ++i) {
63 Date cashflowDate = leg[i]->date();
64 if (startDate < cashflowDate && cashflowDate <= endDate)
66 }
68}
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.
◆ couponRates()
vector< Rate > couponRates |
( |
const Leg & |
leg | ) |
|
|
static |
Return only the coupon rates from a leg
i.e. only Cashflow that casts to Coupon Maintains the order of the coupon rates
Definition at line 70 of file cashflows.cpp.
70 {
71
73
74 for (Size i = 0; i < leg.size(); ++i) {
75 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(leg[i]);
76 if (coupon)
78 }
80}
static std::vector< Rate > couponRates(const Leg &leg)
◆ couponDcfRates()
vector< Rate > couponDcfRates |
( |
const Leg & |
leg | ) |
|
|
static |
Return the coupon rates multiplied by day count fraction from a leg
i.e. only Cashflow that casts to Coupon. Maintains the order of the coupon rates
Definition at line 82 of file cashflows.cpp.
82 {
83
85
86 for (Size i = 0; i < leg.size(); ++i) {
87 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(leg[i]);
88 if (coupon)
89 couponDcfRates.push_back(coupon->rate() * coupon->accrualPeriod());
90 }
92}
static std::vector< Rate > couponDcfRates(const Leg &leg)