23#include <ql/cashflows/cashflows.hpp>
24#include <ql/cashflows/coupon.hpp>
25#include <ql/cashflows/couponpricer.hpp>
26#include <ql/math/solvers1d/brent.hpp>
27#include <ql/math/solvers1d/newtonsafe.hpp>
28#include <ql/patterns/visitor.hpp>
29#include <ql/quotes/simplequote.hpp>
30#include <ql/termstructures/yield/flatforward.hpp>
31#include <ql/termstructures/yield/zerospreadedtermstructure.hpp>
39 QL_REQUIRE(!leg.empty(),
"empty leg");
42 for (
const auto& i : leg) {
43 ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(i);
45 d = std::min(d, c->accrualStartDate());
47 d = std::min(d, i->date());
53 QL_REQUIRE(!leg.empty(),
"empty leg");
56 for (
const auto& i : leg) {
57 ext::shared_ptr<Coupon> c = ext::dynamic_pointer_cast<Coupon>(i);
59 d = std::max(d, c->accrualEndDate());
61 d = std::max(d, i->date());
67 bool includeSettlementDateFlows,
73 if (settlementDate ==
Date())
76 for (
Size i=leg.size(); i>0; --i)
77 if (!leg[i-1]->hasOccurred(settlementDate,
78 includeSettlementDateFlows))
83 Leg::const_reverse_iterator
85 bool includeSettlementDateFlows,
86 Date settlementDate) {
90 if (settlementDate ==
Date())
93 Leg::const_reverse_iterator i;
94 for (i = leg.rbegin(); i<leg.rend(); ++i) {
95 if ( (*i)->hasOccurred(settlementDate, includeSettlementDateFlows) )
103 bool includeSettlementDateFlows,
104 Date settlementDate) {
108 if (settlementDate ==
Date())
111 Leg::const_iterator i;
112 for (i = leg.begin(); i<leg.end(); ++i) {
113 if ( ! (*i)->hasOccurred(settlementDate, includeSettlementDateFlows) )
120 bool includeSettlementDateFlows,
121 Date settlementDate) {
122 Leg::const_reverse_iterator cf;
128 return (*cf)->date();
132 bool includeSettlementDateFlows,
133 Date settlementDate) {
134 Leg::const_iterator cf;
135 cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
140 return (*cf)->date();
144 bool includeSettlementDateFlows,
145 Date settlementDate) {
146 Leg::const_reverse_iterator cf;
152 Date paymentDate = (*cf)->date();
154 for (; cf<leg.rend() && (*cf)->date()==paymentDate; ++cf)
155 result += (*cf)->amount();
160 bool includeSettlementDateFlows,
161 Date settlementDate) {
162 Leg::const_iterator cf;
163 cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
168 Date paymentDate = (*cf)->date();
170 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf)
171 result += (*cf)->amount();
178 template<
typename Iter>
179 Rate aggregateRate(
const Leg& leg,
182 if (first==last)
return 0.0;
184 Date paymentDate = (*first)->date();
185 bool firstCouponFound =
false;
187 Time accrualPeriod = 0.0;
190 for (; first<last && (*first)->date()==paymentDate; ++first) {
191 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*first);
193 if (firstCouponFound) {
194 QL_REQUIRE(nominal == cp->nominal() &&
195 accrualPeriod == cp->accrualPeriod() &&
196 dc == cp->dayCounter(),
197 "cannot aggregate two different coupons on "
200 firstCouponFound =
true;
201 nominal = cp->nominal();
202 accrualPeriod = cp->accrualPeriod();
203 dc = cp->dayCounter();
205 result += cp->rate();
208 QL_ENSURE(firstCouponFound,
209 "no coupon paid at cashflow date " << paymentDate);
216 bool includeSettlementDateFlows,
217 Date settlementDate) {
218 Leg::const_reverse_iterator cf;
221 return aggregateRate<Leg::const_reverse_iterator>(leg, cf, leg.rend());
225 bool includeSettlementDateFlows,
226 Date settlementDate) {
227 Leg::const_iterator cf;
228 cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
229 return aggregateRate<Leg::const_iterator>(leg, cf, leg.end());
233 bool includeSettlementDateFlows,
234 Date settlementDate) {
235 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
236 if (cf==leg.end())
return 0.0;
238 Date paymentDate = (*cf)->date();
239 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
240 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
242 return cp->nominal();
248 bool includeSettlementDateFlows,
249 Date settlementDate) {
250 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
254 Date paymentDate = (*cf)->date();
255 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
256 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
258 return cp->accrualStartDate();
264 bool includeSettlementDateFlows,
265 Date settlementDate) {
266 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
270 Date paymentDate = (*cf)->date();
271 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
272 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
274 return cp->accrualEndDate();
280 bool includeSettlementDateFlows,
281 Date settlementDate) {
282 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
286 Date paymentDate = (*cf)->date();
287 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
288 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
290 return cp->referencePeriodStart();
296 bool includeSettlementDateFlows,
297 Date settlementDate) {
298 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
302 Date paymentDate = (*cf)->date();
303 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
304 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
306 return cp->referencePeriodEnd();
312 bool includeSettlementDateFlows,
313 Date settlementDate) {
314 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
315 if (cf==leg.end())
return 0;
317 Date paymentDate = (*cf)->date();
318 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
319 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
321 return cp->accrualPeriod();
327 bool includeSettlementDateFlows,
328 Date settlementDate) {
329 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
330 if (cf==leg.end())
return 0;
332 Date paymentDate = (*cf)->date();
333 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
334 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
336 return cp->accrualDays();
342 bool includeSettlementDateFlows,
343 Date settlementDate) {
344 if (settlementDate ==
Date())
347 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
348 if (cf==leg.end())
return 0;
350 Date paymentDate = (*cf)->date();
351 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
352 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
354 return cp->accruedPeriod(settlementDate);
360 bool includeSettlementDateFlows,
361 Date settlementDate) {
362 if (settlementDate ==
Date())
365 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
366 if (cf==leg.end())
return 0;
368 Date paymentDate = (*cf)->date();
369 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
370 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
372 return cp->accruedDays(settlementDate);
378 bool includeSettlementDateFlows,
379 Date settlementDate) {
380 if (settlementDate ==
Date())
383 auto cf =
nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
384 if (cf==leg.end())
return 0.0;
386 Date paymentDate = (*cf)->date();
388 for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
389 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
391 result += cp->accruedAmount(settlementDate);
404 : discountCurve_(discountCurve) {}
405 void visit(Coupon& c)
override {
406 Real bps = c.nominal() *
408 discountCurve_.discount(c.date());
411 void visit(CashFlow& cf)
override {
412 nonSensNPV_ += cf.amount() *
413 discountCurve_.discount(cf.date());
415 Real bps()
const {
return bps_; }
416 Real nonSensNPV()
const {
return nonSensNPV_; }
418 const YieldTermStructure& discountCurve_;
419 Real bps_ = 0.0, nonSensNPV_ = 0.0;
422 const Spread basisPoint_ = 1.0e-4;
427 bool includeSettlementDateFlows,
434 if (settlementDate ==
Date())
437 if (npvDate ==
Date())
438 npvDate = settlementDate;
441 for (
const auto& i : leg) {
442 if (!i->hasOccurred(settlementDate, includeSettlementDateFlows) &&
443 !i->tradingExCoupon(settlementDate))
444 totalNPV += i->amount() * discountCurve.
discount(i->date());
447 return totalNPV/discountCurve.
discount(npvDate);
452 bool includeSettlementDateFlows,
458 if (settlementDate ==
Date())
461 if (npvDate ==
Date())
462 npvDate = settlementDate;
464 BPSCalculator calc(discountCurve);
465 for (
const auto& i : leg) {
466 if (!i->hasOccurred(settlementDate, includeSettlementDateFlows) &&
467 !i->tradingExCoupon(settlementDate))
470 return basisPoint_*calc.bps()/discountCurve.
discount(npvDate);
475 bool includeSettlementDateFlows,
481 npvbps(leg, discountCurve, includeSettlementDateFlows, settlementDate, npvDate);
486 bool includeSettlementDateFlows,
496 if (settlementDate ==
Date())
499 if (npvDate ==
Date())
500 npvDate = settlementDate;
502 for (
const auto& i : leg) {
505 includeSettlementDateFlows) &&
507 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(i);
511 bps += cp->nominal() * cp->accrualPeriod() * df;
516 bps = basisPoint_ *
bps / d;
523 bool includeSettlementDateFlows,
530 if (settlementDate ==
Date())
533 if (npvDate ==
Date())
534 npvDate = settlementDate;
537 BPSCalculator calc(discountCurve);
538 for (
const auto& i : leg) {
541 includeSettlementDateFlows) &&
550 targetNpv =
npv - calc.nonSensNPV();
552 targetNpv *= discountCurve.
discount(npvDate);
553 targetNpv -= calc.nonSensNPV();
560 QL_REQUIRE(
bps!=0.0,
"null bps: impossible atm rate");
562 return targetNpv/
bps;
580 Time getStepwiseDiscountTime(
const ext::shared_ptr<QuantLib::CashFlow>& cashFlow,
581 const DayCounter& dc,
584 Date cashFlowDate = cashFlow->date();
585 Date refStartDate, refEndDate;
586 ext::shared_ptr<Coupon> coupon =
587 ext::dynamic_pointer_cast<Coupon>(cashFlow);
588 if (coupon !=
nullptr) {
589 refStartDate = coupon->referencePeriodStart();
590 refEndDate = coupon->referencePeriodEnd();
592 if (lastDate == npvDate) {
595 refStartDate = cashFlowDate - 1*
Years;
597 refStartDate = lastDate;
599 refEndDate = cashFlowDate;
602 if ((coupon !=
nullptr) && lastDate != coupon->accrualStartDate()) {
603 Time couponPeriod = dc.yearFraction(coupon->accrualStartDate(),
604 cashFlowDate, refStartDate, refEndDate);
605 Time accruedPeriod = dc.yearFraction(coupon->accrualStartDate(),
606 lastDate, refStartDate, refEndDate);
607 return couponPeriod - accruedPeriod;
609 return dc.yearFraction(lastDate, cashFlowDate,
610 refStartDate, refEndDate);
614 Real simpleDuration(
const Leg& leg,
615 const InterestRate& y,
616 bool includeSettlementDateFlows,
622 if (settlementDate == Date())
625 if (npvDate == Date())
626 npvDate = settlementDate;
631 Date lastDate = npvDate;
632 const DayCounter& dc = y.dayCounter();
633 for (
const auto& i : leg) {
634 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
637 Real c = i->amount();
638 if (i->tradingExCoupon(settlementDate)) {
642 t += getStepwiseDiscountTime(i, dc, npvDate, lastDate);
647 lastDate = i->date();
654 Real modifiedDuration(
const Leg& leg,
655 const InterestRate& y,
656 bool includeSettlementDateFlows,
662 if (settlementDate == Date())
665 if (npvDate == Date())
666 npvDate = settlementDate;
673 Date lastDate = npvDate;
674 const DayCounter& dc = y.dayCounter();
675 for (
const auto& i : leg) {
676 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
679 Real c = i->amount();
680 if (i->tradingExCoupon(settlementDate)) {
684 t += getStepwiseDiscountTime(i, dc, npvDate, lastDate);
687 switch (y.compounding()) {
692 dPdy -= c * t * B/(1+r/N);
701 dPdy -= c * t * B/(1+r/N);
707 dPdy -= c * t * B/(1+r/N);
710 QL_FAIL(
"unknown compounding convention (" <<
711 Integer(y.compounding()) <<
")");
713 lastDate = i->date();
721 Real macaulayDuration(
const Leg& leg,
722 const InterestRate& y,
723 bool includeSettlementDateFlows,
728 "compounded rate required");
730 return (1.0+y.rate()/
Integer(y.frequency())) *
731 modifiedDuration(leg, y,
732 includeSettlementDateFlows,
733 settlementDate, npvDate);
736 struct CashFlowLater {
737 bool operator()(
const ext::shared_ptr<CashFlow> &c,
738 const ext::shared_ptr<CashFlow> &d) {
739 return c->date() > d->date();
750 bool includeSettlementDateFlows,
753 : leg_(leg), npv_(npv), dayCounter_(
std::move(dayCounter)), compounding_(comp),
754 frequency_(freq), includeSettlementDateFlows_(includeSettlementDateFlows),
755 settlementDate_(settlementDate), npvDate_(npvDate) {
769 includeSettlementDateFlows_,
770 settlementDate_, npvDate_);
776 return modifiedDuration(leg_,
yield,
777 includeSettlementDateFlows_,
778 settlementDate_, npvDate_);
788 for (
const auto& i : leg_) {
789 if (!i->hasOccurred(settlementDate_, includeSettlementDateFlows_) &&
790 !i->tradingExCoupon(settlementDate_)) {
791 Integer thisSign = sign(i->amount());
792 if (lastSign * thisSign < 0)
799 QL_REQUIRE(signChanges > 0,
800 "the given cash flows cannot result in the given market "
801 "price due to their sign");
825 bool includeSettlementDateFlows,
832 if (settlementDate ==
Date())
835 if (npvDate ==
Date())
836 npvDate = settlementDate;
838#if defined(QL_EXTRA_SAFETY_CHECKS)
839 QL_REQUIRE(std::adjacent_find(leg.begin(), leg.end(),
840 CashFlowLater()) == leg.end(),
841 "cashflows must be sorted in ascending order w.r.t. their payment dates");
846 Date lastDate = npvDate;
848 for (
const auto& i : leg) {
849 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
852 Real amount = i->amount();
853 if (i->tradingExCoupon(settlementDate)) {
857 DiscountFactor b = y.discountFactor(getStepwiseDiscountTime(i, dc, npvDate, lastDate));
859 lastDate = i->date();
861 npv += amount * discount;
872 bool includeSettlementDateFlows,
876 includeSettlementDateFlows,
877 settlementDate, npvDate);
882 bool includeSettlementDateFlows,
889 if (settlementDate ==
Date())
892 if (npvDate ==
Date())
893 npvDate = settlementDate;
897 return bps(leg, flatRate,
898 includeSettlementDateFlows,
899 settlementDate, npvDate);
907 bool includeSettlementDateFlows,
911 includeSettlementDateFlows,
912 settlementDate, npvDate);
920 bool includeSettlementDateFlows,
928 return CashFlows::yield<NewtonSafe>(solver, leg,
npv, dayCounter,
929 compounding, frequency,
930 includeSettlementDateFlows,
931 settlementDate, npvDate,
939 bool includeSettlementDateFlows,
946 if (settlementDate ==
Date())
949 if (npvDate ==
Date())
950 npvDate = settlementDate;
954 return simpleDuration(leg, rate,
955 includeSettlementDateFlows,
956 settlementDate, npvDate);
958 return modifiedDuration(leg, rate,
959 includeSettlementDateFlows,
960 settlementDate, npvDate);
962 return macaulayDuration(leg, rate,
963 includeSettlementDateFlows,
964 settlementDate, npvDate);
966 QL_FAIL(
"unknown duration type");
976 bool includeSettlementDateFlows,
981 includeSettlementDateFlows,
982 settlementDate, npvDate);
987 bool includeSettlementDateFlows,
993 if (settlementDate ==
Date())
996 if (npvDate ==
Date())
997 npvDate = settlementDate;
1006 Date lastDate = npvDate;
1007 for (
const auto& i : leg) {
1008 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
1011 Real c = i->amount();
1012 if (i->tradingExCoupon(settlementDate)) {
1016 t += getStepwiseDiscountTime(i, dc, npvDate, lastDate);
1019 switch (y.compounding()) {
1021 d2Pdy2 += c * 2.0*B*B*B*t*t;
1024 d2Pdy2 += c * B*t*(N*t+1)/(N*(1+r/N)*(1+r/N));
1027 d2Pdy2 += c * B*t*t;
1031 d2Pdy2 += c * 2.0*B*B*B*t*t;
1033 d2Pdy2 += c * B*t*(N*t+1)/(N*(1+r/N)*(1+r/N));
1037 d2Pdy2 += c * 2.0*B*B*B*t*t;
1039 d2Pdy2 += c * B*t*(N*t+1)/(N*(1+r/N)*(1+r/N));
1042 QL_FAIL(
"unknown compounding convention (" <<
1043 Integer(y.compounding()) <<
")");
1045 lastDate = i->date();
1061 bool includeSettlementDateFlows,
1062 Date settlementDate,
1065 includeSettlementDateFlows,
1066 settlementDate, npvDate);
1071 bool includeSettlementDateFlows,
1072 Date settlementDate,
1077 if (settlementDate ==
Date())
1080 if (npvDate ==
Date())
1081 npvDate = settlementDate;
1084 includeSettlementDateFlows,
1085 settlementDate, npvDate);
1088 includeSettlementDateFlows,
1089 settlementDate, npvDate);
1091 includeSettlementDateFlows,
1092 settlementDate, npvDate);
1093 Real delta = -modifiedDuration*
npv;
1096 Real shift = 0.0001;
1098 gamma *= shift*shift;
1100 return delta + 0.5*gamma;
1108 bool includeSettlementDateFlows,
1109 Date settlementDate,
1112 includeSettlementDateFlows,
1113 settlementDate, npvDate);
1118 bool includeSettlementDateFlows,
1119 Date settlementDate,
1124 if (settlementDate ==
Date())
1127 if (npvDate ==
Date())
1128 npvDate = settlementDate;
1131 includeSettlementDateFlows,
1132 settlementDate, npvDate);
1135 includeSettlementDateFlows,
1136 settlementDate, npvDate);
1139 return (1.0/(-
npv*modifiedDuration))*shift;
1147 bool includeSettlementDateFlows,
1148 Date settlementDate,
1151 includeSettlementDateFlows,
1152 settlementDate, npvDate);
1158 class ZSpreadFinder {
1160 ZSpreadFinder(
const Leg& leg,
1161 const ext::shared_ptr<YieldTermStructure>& discountCurve,
1166 bool includeSettlementDateFlows,
1167 Date settlementDate,
1169 : leg_(leg), npv_(npv), zSpread_(new
SimpleQuote(0.0)),
1172 includeSettlementDateFlows_(includeSettlementDateFlows),
1173 settlementDate_(settlementDate),
1176 if (settlementDate_ ==
Date())
1177 settlementDate_ = Settings::instance().evaluationDate();
1179 if (npvDate_ ==
Date())
1180 npvDate_ = settlementDate_;
1184 curve_.enableExtrapolation(
1185 discountCurve->allowsExtrapolation());
1187 Real operator()(Rate zSpread)
const {
1188 zSpread_->setValue(zSpread);
1189 Real NPV = CashFlows::npv(leg_, curve_,
1190 includeSettlementDateFlows_,
1191 settlementDate_, npvDate_);
1197 ext::shared_ptr<SimpleQuote> zSpread_;
1198 ZeroSpreadedTermStructure curve_;
1199 bool includeSettlementDateFlows_;
1200 Date settlementDate_, npvDate_;
1206 const ext::shared_ptr<YieldTermStructure>& discountCurve,
1211 bool includeSettlementDateFlows,
1212 Date settlementDate,
1218 if (settlementDate ==
Date())
1221 if (npvDate ==
Date())
1222 npvDate = settlementDate;
1234 return npv(leg, spreadedCurve,
1235 includeSettlementDateFlows,
1236 settlementDate, npvDate);
1241 const ext::shared_ptr<YieldTermStructure>& discount,
1245 bool includeSettlementDateFlows,
1246 Date settlementDate,
1252 if (settlementDate ==
Date())
1255 if (npvDate ==
Date())
1256 npvDate = settlementDate;
1260 ZSpreadFinder objFunction(leg,
1263 dayCounter, compounding, frequency, includeSettlementDateFlows,
1264 settlementDate, npvDate);
1266 return solver.
solve(objFunction, accuracy, guess, step);
degenerate base class for the Acyclic Visitor pattern
Base class for cash flows.
bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const override
returns true if an event has already occurred before a date
bool tradingExCoupon(const Date &refDate=Date()) const
returns true if the cashflow is trading ex-coupon on the refDate
void accept(AcyclicVisitor &) override
Date date() const override=0
virtual Real amount() const =0
returns the amount of the cash flow
IrrFinder(const Leg &leg, Real npv, DayCounter dayCounter, Compounding comp, Frequency freq, bool includeSettlementDateFlows, Date settlementDate, Date npvDate)
Real derivative(Rate y) const
Real operator()(Rate y) const
static Date::serial_type accruedDays(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Real previousCashFlowAmount(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Rate previousCouponRate(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Rate nextCouponRate(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Date referencePeriodStart(const Leg &leg, bool includeSettlementDateFlows, Date settlDate=Date())
static Real nextCashFlowAmount(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Real yieldValueBasisPoint(const Leg &leg, const InterestRate &yield, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
Yield value of a basis point.
static Real accruedAmount(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Real basisPointValue(const Leg &leg, const InterestRate &yield, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
Basis-point value.
static Leg::const_iterator nextCashFlow(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
the first cashflow paying after the given date
static Spread zSpread(const Leg &leg, Real npv, const ext::shared_ptr< YieldTermStructure > &, const DayCounter &dayCounter, Compounding compounding, Frequency frequency, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date(), Real accuracy=1.0e-10, Size maxIterations=100, Rate guess=0.0)
implied Z-spread.
static Real npv(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
NPV of the cash flows.
static Date accrualEndDate(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Date accrualStartDate(const Leg &leg, bool includeSettlementDateFlows, Date settlDate=Date())
static Leg::const_reverse_iterator previousCashFlow(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
the last cashflow paying before or at the given date
static Date nextCashFlowDate(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Rate yield(const Leg &leg, Real npv, const DayCounter &dayCounter, Compounding compounding, Frequency frequency, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date(), Real accuracy=1.0e-10, Size maxIterations=100, Rate guess=0.05)
Implied internal rate of return.
static Time accrualPeriod(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Date::serial_type accrualDays(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Date maturityDate(const Leg &leg)
static Time duration(const Leg &leg, const InterestRate &yield, Duration::Type type, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
Cash-flow duration.
static Date startDate(const Leg &leg)
static Real nominal(const Leg &leg, bool includeSettlementDateFlows, Date settlDate=Date())
static Date previousCashFlowDate(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Rate atmRate(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date(), Real npv=Null< Real >())
At-the-money rate of the cash flows.
static bool isExpired(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Real bps(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
Basis-point sensitivity of the cash flows.
static std::pair< Real, Real > npvbps(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
NPV and BPS of the cash flows.
static Date referencePeriodEnd(const Leg &leg, bool includeSettlementDateFlows, Date settlDate=Date())
static Time accruedPeriod(const Leg &leg, bool includeSettlementDateFlows, Date settlementDate=Date())
static Real convexity(const Leg &leg, const InterestRate &yield, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
Cash-flow convexity.
static Date minDate()
earliest allowed date
std::int_fast32_t serial_type
serial number type
static Date maxDate()
latest allowed date
Flat interest-rate curve.
Shared handle to an observable.
Concrete interest rate class.
template class providing a null value for a given type.
purely virtual base class for market observables
DateProxy & evaluationDate()
the date at which pricing is to be performed.
market element returning a stored value
static Settings & instance()
access to the unique instance
void setMaxEvaluations(Size evaluations)
Real solve(const F &f, Real accuracy, Real guess, Real step) const
Visitor for a specific class
Interest-rate term structure.
DiscountFactor discount(const Date &d, bool extrapolate=false) const
Term structure with an added spread on the zero yield rate.
Frequency
Frequency of events.
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
Compounding
Interest rate coumpounding rule.
@ CompoundedThenSimple
Compounded up to the first period then Simple.
@ SimpleThenCompounded
Simple up to the first period then Compounded.
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.