Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Private Member Functions | List of all members
CashFlows Class Reference

cashflow-analysis functions in addition to those in QuantLib More...

#include <qle/cashflows/cashflows.hpp>

+ Collaboration diagram for CashFlows:

Static Public Member Functions

YieldTermStructure 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. 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)
 

Private Member Functions

 CashFlows ()
 
 CashFlows (const CashFlows &)
 

Detailed Description

cashflow-analysis functions in addition to those in QuantLib

Definition at line 33 of file cashflows.hpp.

Constructor & Destructor Documentation

◆ CashFlows() [1/2]

CashFlows ( )
private

◆ CashFlows() [2/2]

CashFlows ( const CashFlows )
private

Member Function Documentation

◆ 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
39 Real spreadNpv = 0.0;
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.
Definition: cashflows.cpp:27
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 // Empty leg return 0
57 if (leg.empty())
58 return 0.0;
59
60 // If leg is not empty
61 Real sumCashflows = 0.0;
62 for (Size i = 0; i < leg.size(); ++i) {
63 Date cashflowDate = leg[i]->date();
64 if (startDate < cashflowDate && cashflowDate <= endDate)
65 sumCashflows += leg[i]->amount();
66 }
67 return sumCashflows;
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.
Definition: cashflows.cpp:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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
72 vector<Rate> couponRates;
73 // Non-empty leg
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)
77 couponRates.push_back(coupon->rate());
78 }
79 return couponRates;
80}
static std::vector< Rate > couponRates(const Leg &leg)
Definition: cashflows.cpp:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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
84 vector<Rate> couponDcfRates;
85 // Non-empty leg
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 }
91 return couponDcfRates;
92}
static std::vector< Rate > couponDcfRates(const Leg &leg)
Definition: cashflows.cpp:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function: