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());
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) {
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();
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);
405 void visit(Coupon& c)
override {
406 Real bps = c.nominal() *
411 void visit(CashFlow& cf)
override {
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,
485 if (settlementDate ==
Date())
488 if (npvDate ==
Date())
489 npvDate = settlementDate;
491 for (
const auto& i : leg) {
494 includeSettlementDateFlows) &&
496 ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(i);
500 bps += cp->nominal() * cp->accrualPeriod() * df;
512 bool includeSettlementDateFlows,
519 if (settlementDate ==
Date())
522 if (npvDate ==
Date())
523 npvDate = settlementDate;
526 BPSCalculator calc(discountCurve);
527 for (
const auto& i : leg) {
530 includeSettlementDateFlows) &&
539 targetNpv =
npv - calc.nonSensNPV();
541 targetNpv *= discountCurve.
discount(npvDate);
542 targetNpv -= calc.nonSensNPV();
551 return targetNpv/
bps;
569 Time getStepwiseDiscountTime(
const ext::shared_ptr<QuantLib::CashFlow>& cashFlow,
570 const DayCounter& dc,
573 Date cashFlowDate = cashFlow->date();
574 Date refStartDate, refEndDate;
575 ext::shared_ptr<Coupon> coupon =
576 ext::dynamic_pointer_cast<Coupon>(cashFlow);
577 if (coupon !=
nullptr) {
578 refStartDate = coupon->referencePeriodStart();
579 refEndDate = coupon->referencePeriodEnd();
581 if (lastDate == npvDate) {
584 refStartDate = cashFlowDate - 1*
Years;
586 refStartDate = lastDate;
588 refEndDate = cashFlowDate;
591 if ((coupon !=
nullptr) && lastDate != coupon->accrualStartDate()) {
592 Time couponPeriod = dc.yearFraction(coupon->accrualStartDate(),
593 cashFlowDate, refStartDate, refEndDate);
594 Time accruedPeriod = dc.yearFraction(coupon->accrualStartDate(),
595 lastDate, refStartDate, refEndDate);
596 return couponPeriod - accruedPeriod;
598 return dc.yearFraction(lastDate, cashFlowDate,
599 refStartDate, refEndDate);
603 Real simpleDuration(
const Leg& leg,
604 const InterestRate&
y,
605 bool includeSettlementDateFlows,
611 if (settlementDate == Date())
614 if (npvDate == Date())
615 npvDate = settlementDate;
620 Date lastDate = npvDate;
621 const DayCounter& dc =
y.dayCounter();
622 for (
const auto& i : leg) {
623 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
626 Real c = i->amount();
627 if (i->tradingExCoupon(settlementDate)) {
631 t += getStepwiseDiscountTime(i, dc, npvDate, lastDate);
636 lastDate = i->date();
643 Real modifiedDuration(
const Leg& leg,
644 const InterestRate&
y,
645 bool includeSettlementDateFlows,
651 if (settlementDate == Date())
654 if (npvDate == Date())
655 npvDate = settlementDate;
662 Date lastDate = npvDate;
663 const DayCounter& dc =
y.dayCounter();
664 for (
const auto& i : leg) {
665 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
668 Real c = i->amount();
669 if (i->tradingExCoupon(settlementDate)) {
673 t += getStepwiseDiscountTime(i, dc, npvDate, lastDate);
676 switch (
y.compounding()) {
681 dPdy -= c *
t * B/(1+
r/N);
690 dPdy -= c *
t * B/(1+
r/N);
696 dPdy -= c *
t * B/(1+
r/N);
699 QL_FAIL(
"unknown compounding convention (" <<
702 lastDate = i->date();
710 Real macaulayDuration(
const Leg& leg,
711 const InterestRate&
y,
712 bool includeSettlementDateFlows,
717 "compounded rate required");
719 return (1.0+
y.rate()/
Integer(
y.frequency())) *
720 modifiedDuration(leg,
y,
721 includeSettlementDateFlows,
722 settlementDate, npvDate);
725 struct CashFlowLater {
726 bool operator()(
const ext::shared_ptr<CashFlow> &c,
727 const ext::shared_ptr<CashFlow> &
d) {
728 return c->date() >
d->date();
739 bool includeSettlementDateFlows,
742 :
leg_(leg),
npv_(npv), dayCounter_(
std::move(dayCounter)), compounding_(comp),
777 for (
const auto& i :
leg_) {
780 Integer thisSign = sign(i->amount());
781 if (lastSign * thisSign < 0)
789 "the given cash flows cannot result in the given market "
790 "price due to their sign");
814 bool includeSettlementDateFlows,
821 if (settlementDate ==
Date())
824 if (npvDate ==
Date())
825 npvDate = settlementDate;
827#if defined(QL_EXTRA_SAFETY_CHECKS)
828 QL_REQUIRE(std::adjacent_find(leg.begin(), leg.end(),
829 CashFlowLater()) == leg.end(),
830 "cashflows must be sorted in ascending order w.r.t. their payment dates");
835 Date lastDate = npvDate;
837 for (
const auto& i : leg) {
838 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
841 Real amount = i->amount();
842 if (i->tradingExCoupon(settlementDate)) {
846 DiscountFactor b =
y.discountFactor(getStepwiseDiscountTime(i, dc, npvDate, lastDate));
848 lastDate = i->date();
850 npv += amount * discount;
861 bool includeSettlementDateFlows,
865 includeSettlementDateFlows,
866 settlementDate, npvDate);
871 bool includeSettlementDateFlows,
878 if (settlementDate ==
Date())
881 if (npvDate ==
Date())
882 npvDate = settlementDate;
886 return bps(leg, flatRate,
887 includeSettlementDateFlows,
888 settlementDate, npvDate);
896 bool includeSettlementDateFlows,
900 includeSettlementDateFlows,
901 settlementDate, npvDate);
909 bool includeSettlementDateFlows,
917 return CashFlows::yield<NewtonSafe>(solver, leg,
npv, dayCounter,
918 compounding, frequency,
919 includeSettlementDateFlows,
920 settlementDate, npvDate,
928 bool includeSettlementDateFlows,
935 if (settlementDate ==
Date())
938 if (npvDate ==
Date())
939 npvDate = settlementDate;
943 return simpleDuration(leg, rate,
944 includeSettlementDateFlows,
945 settlementDate, npvDate);
947 return modifiedDuration(leg, rate,
948 includeSettlementDateFlows,
949 settlementDate, npvDate);
951 return macaulayDuration(leg, rate,
952 includeSettlementDateFlows,
953 settlementDate, npvDate);
955 QL_FAIL(
"unknown duration type");
965 bool includeSettlementDateFlows,
970 includeSettlementDateFlows,
971 settlementDate, npvDate);
976 bool includeSettlementDateFlows,
982 if (settlementDate ==
Date())
985 if (npvDate ==
Date())
986 npvDate = settlementDate;
995 Date lastDate = npvDate;
996 for (
const auto& i : leg) {
997 if (i->hasOccurred(settlementDate, includeSettlementDateFlows))
1000 Real c = i->amount();
1001 if (i->tradingExCoupon(settlementDate)) {
1005 t += getStepwiseDiscountTime(i, dc, npvDate, lastDate);
1008 switch (
y.compounding()) {
1010 d2Pdy2 += c * 2.0*B*B*B*
t*
t;
1013 d2Pdy2 += c * B*
t*(N*
t+1)/(N*(1+
r/N)*(1+
r/N));
1016 d2Pdy2 += c * B*
t*
t;
1020 d2Pdy2 += c * 2.0*B*B*B*
t*
t;
1022 d2Pdy2 += c * B*
t*(N*
t+1)/(N*(1+
r/N)*(1+
r/N));
1026 d2Pdy2 += c * 2.0*B*B*B*
t*
t;
1028 d2Pdy2 += c * B*
t*(N*
t+1)/(N*(1+
r/N)*(1+
r/N));
1031 QL_FAIL(
"unknown compounding convention (" <<
1034 lastDate = i->date();
1050 bool includeSettlementDateFlows,
1051 Date settlementDate,
1054 includeSettlementDateFlows,
1055 settlementDate, npvDate);
1060 bool includeSettlementDateFlows,
1061 Date settlementDate,
1066 if (settlementDate ==
Date())
1069 if (npvDate ==
Date())
1070 npvDate = settlementDate;
1073 includeSettlementDateFlows,
1074 settlementDate, npvDate);
1077 includeSettlementDateFlows,
1078 settlementDate, npvDate);
1080 includeSettlementDateFlows,
1081 settlementDate, npvDate);
1082 Real delta = -modifiedDuration*
npv;
1085 Real shift = 0.0001;
1087 gamma *= shift*shift;
1089 return delta + 0.5*gamma;
1097 bool includeSettlementDateFlows,
1098 Date settlementDate,
1101 includeSettlementDateFlows,
1102 settlementDate, npvDate);
1107 bool includeSettlementDateFlows,
1108 Date settlementDate,
1113 if (settlementDate ==
Date())
1116 if (npvDate ==
Date())
1117 npvDate = settlementDate;
1120 includeSettlementDateFlows,
1121 settlementDate, npvDate);
1124 includeSettlementDateFlows,
1125 settlementDate, npvDate);
1128 return (1.0/(-
npv*modifiedDuration))*shift;
1136 bool includeSettlementDateFlows,
1137 Date settlementDate,
1140 includeSettlementDateFlows,
1141 settlementDate, npvDate);
1147 class ZSpreadFinder {
1149 ZSpreadFinder(
const Leg& leg,
1150 const ext::shared_ptr<YieldTermStructure>& discountCurve,
1155 bool includeSettlementDateFlows,
1156 Date settlementDate,
1173 curve_.enableExtrapolation(
1174 discountCurve->allowsExtrapolation());
1176 Real operator()(Rate zSpread)
const {
1195 const ext::shared_ptr<YieldTermStructure>& discountCurve,
1200 bool includeSettlementDateFlows,
1201 Date settlementDate,
1207 if (settlementDate ==
Date())
1210 if (npvDate ==
Date())
1211 npvDate = settlementDate;
1223 return npv(leg, spreadedCurve,
1224 includeSettlementDateFlows,
1225 settlementDate, npvDate);
1230 const ext::shared_ptr<YieldTermStructure>& discount,
1234 bool includeSettlementDateFlows,
1235 Date settlementDate,
1241 if (settlementDate ==
Date())
1244 if (npvDate ==
Date())
1245 npvDate = settlementDate;
1249 ZSpreadFinder objFunction(leg,
1252 dayCounter, compounding, frequency, includeSettlementDateFlows,
1253 settlementDate, npvDate);
1255 return solver.
solve(objFunction, accuracy, guess, step);
ext::shared_ptr< SimpleQuote > zSpread_
bool includeSettlementDateFlows_
const YieldTermStructure & discountCurve_
ZeroSpreadedTermStructure curve_
Cash-flow analysis functions.
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.
Coupon accruing over a fixed period.
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
ext::function< Real(Real)> b
flat forward rate term structure
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.
Safe (bracketed) Newton 1-D solver.
ext::shared_ptr< YieldTermStructure > r
degenerate base class for the Acyclic Visitor pattern
Zero spreaded term structure.