21#include <ql/cashflows/cashflowvectors.hpp>
28 const Date& startDate,
const Date& endDate, Natural fixingDays,
29 const QuantLib::ext::shared_ptr<FormulaBasedIndex>& index,
const Date& refPeriodStart,
30 const Date& refPeriodEnd,
const DayCounter& dayCounter,
bool isInArrears)
31 :
FloatingRateCoupon(paymentDate, nominal, startDate, endDate, fixingDays, index, 1.0, 0.0, refPeriodStart,
32 refPeriodEnd, dayCounter, isInArrears),
33 paymentCurrency_(paymentCurrency), index_(index) {}
36 Visitor<FormulaBasedCoupon>* v1 =
dynamic_cast<Visitor<FormulaBasedCoupon>*
>(&v);
40 FloatingRateCoupon::accept(v);
44 const QuantLib::ext::shared_ptr<FormulaBasedIndex>& index)
45 : paymentCurrency_(paymentCurrency), schedule_(schedule), index_(index), paymentAdjustment_(Following),
46 paymentLag_(0), inArrears_(false), zeroPayments_(false) {}
98FormulaBasedLeg::operator Leg()
const {
103 Size n = schedule_.size() - 1;
104 QL_REQUIRE(!notionals_.empty(),
"no notional given");
105 QL_REQUIRE(notionals_.size() <= n,
"too many nominals (" << notionals_.size() <<
"), only " << n <<
" required");
106 QL_REQUIRE(!zeroPayments_ || !inArrears_,
"in-arrears and zero features are not compatible");
111 Calendar calendar = schedule_.calendar().empty() ? NullCalendar() : schedule_.calendar();
112 Calendar paymentCalendar = paymentCalendar_.empty() ? calendar : paymentCalendar_;
114 Date refStart, start, refEnd, end;
115 Date lastPaymentDate = paymentCalendar.advance(schedule_.date(n), paymentLag_, Days, paymentAdjustment_);
117 for (Size i = 0; i < n; ++i) {
118 refStart = start = schedule_.date(i);
119 refEnd = end = schedule_.date(i + 1);
121 zeroPayments_ ? lastPaymentDate : paymentCalendar.advance(end, paymentLag_, Days, paymentAdjustment_);
122 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
123 BusinessDayConvention bdc = schedule_.businessDayConvention();
124 refStart = calendar.adjust(end - schedule_.tenor(), bdc);
126 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
127 BusinessDayConvention bdc = schedule_.businessDayConvention();
128 refEnd = calendar.adjust(start + schedule_.tenor(), bdc);
130 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(
131 new FormulaBasedCoupon(paymentCurrency_, paymentDate, detail::get(notionals_, i, 1.0), start, end,
132 detail::get(fixingDays_, i, index_->fixingDays()), index_, refStart, refEnd,
133 paymentDayCounter_, inArrears_)));