19#include <ql/indexes/interestrateindex.hpp>
20#include <ql/time/schedule.hpp>
21#include <ql/utilities/vectors.hpp>
32 const QuantLib::ext::shared_ptr<InterestRateIndex>& index,
Type type,
33 BusinessDayConvention convention, Spread spread,
const DayCounter& dayCounter,
34 bool includeSpread, Real gearing)
35 :
FloatingRateCoupon(paymentDate, nominal, startDate, endDate, index->fixingDays(), index, gearing, spread, Date(),
36 Date(), dayCounter, false),
37 type_(type), includeSpread_(includeSpread) {
40 Schedule sch = MakeSchedule()
43 .withTenor(index->tenor())
44 .withCalendar(index->fixingCalendar())
45 .withConvention(convention)
46 .withTerminationDateConvention(convention)
49 QL_ENSURE(
valueDates_.size() >= 2,
"Degenerate schedule.");
53 if (index->fixingDays() == 0) {
80 Visitor<SubPeriodsCoupon1>* v1 =
dynamic_cast<Visitor<SubPeriodsCoupon1>*
>(&v);
84 FloatingRateCoupon::accept(v);
89 : schedule_(schedule), index_(index), notionals_(std::vector<Real>(1, 1.0)), paymentAdjustment_(Following),
113 gearings_ = std::vector<Real>(1, gearing);
123 spreads_ = std::vector<Spread>(1, spread);
147SubPeriodsLeg1::operator Leg()
const {
155 if (!paymentCalendar_.empty()) {
156 calendar = paymentCalendar_;
158 calendar = schedule_.calendar();
161 Size numPeriods = schedule_.size() - 1;
165 startDate = schedule_.date(0);
166 for (Size i = 0; i < numPeriods; ++i) {
167 endDate = schedule_.date(i + 1);
168 paymentDate = calendar.adjust(endDate, paymentAdjustment_);
176 QuantLib::ext::shared_ptr<SubPeriodsCoupon1> cashflow(
177 new SubPeriodsCoupon1(paymentDate, detail::get(notionals_, i, notionals_.back()), startDate, endDate,
178 index_, type_, paymentAdjustment_, detail::get(spreads_, i, 0.0),
179 paymentDayCounter_, includeSpread_, detail::get(gearings_, i, 1.0)));
181 cashflows.push_back(cashflow);
183 }
catch (
const QuantLib::Error&) {
std::vector< Date > fixingDates_
std::vector< Time > accrualFractions_
void accept(AcyclicVisitor &) override
std::vector< Rate > fixings_
std::vector< Date > valueDates_
const std::vector< Rate > & indexFixings() const
fixings for the sub-periods
SubPeriodsCoupon1(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, const QuantLib::ext::shared_ptr< InterestRateIndex > &index, Type type, BusinessDayConvention convention, Spread spread=0.0, const DayCounter &dayCounter=DayCounter(), bool includeSpread=false, Real gearing=1.0)
Pricer for sub-period coupons.
helper class building a sequence of sub-period coupons
BusinessDayConvention paymentAdjustment_
SubPeriodsLeg1 & withPaymentDayCounter(const DayCounter &dayCounter)
Calendar paymentCalendar_
SubPeriodsLeg1 & withGearing(Real gearing)
SubPeriodsLeg1 & withType(SubPeriodsCoupon1::Type type)
SubPeriodsLeg1 & withSpreads(const std::vector< Spread > &spreads)
std::vector< Real > notionals_
std::vector< Spread > spreads_
SubPeriodsLeg1(const Schedule &schedule, const QuantLib::ext::shared_ptr< InterestRateIndex > &index)
SubPeriodsLeg1 & withSpread(Spread spread)
SubPeriodsCoupon1::Type type_
SubPeriodsLeg1 & includeSpread(bool includeSpread)
SubPeriodsLeg1 & withGearings(const std::vector< Real > &gearings)
SubPeriodsLeg1 & withPaymentCalendar(const Calendar &calendar)
SubPeriodsLeg1 & withNotional(Real notional)
SubPeriodsLeg1 & withNotionals(const std::vector< Real > ¬ionals)
SubPeriodsLeg1 & withPaymentAdjustment(BusinessDayConvention convention)
std::vector< Real > gearings_
DayCounter paymentDayCounter_
Utility functions for setting coupon pricers on legs.
void setCouponPricer(const Leg &leg, const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Set Coupon Pricer.
Coupon with a number of sub-periods.
Pricer for sub-period coupons.