32 const Date& startDate,
35 const ext::shared_ptr<YoYInflationIndex>& yoyIndex,
36 const Period& observationLag,
40 const Date& refPeriodStart,
41 const Date& refPeriodEnd)
43 fixingDays, yoyIndex, observationLag,
44 dayCounter, refPeriodStart, refPeriodEnd),
45 yoyIndex_(yoyIndex), gearing_(gearing), spread_(spread) {}
58 const ext::shared_ptr<InflationCouponPricer>&pricer)
const {
59 return static_cast<bool>(
60 ext::dynamic_pointer_cast<YoYInflationCouponPricer>(
pricer));
66 ext::shared_ptr<YoYInflationIndex> index,
67 const Period& observationLag)
68 : schedule_(
std::move(schedule)), index_(
std::move(index)), observationLag_(observationLag),
69 paymentCalendar_(
std::move(paymentCalendar)) {}
103 gearings_ = std::vector<Real>(1,gearing);
113 spreads_ = std::vector<Spread>(1,spread);
123 caps_ = std::vector<Rate>(1,cap);
133 floors_ = std::vector<Rate>(1,floor);
143 yoyInflationLeg::operator
Leg()
const {
145 Size n = schedule_.size()-1;
146 QL_REQUIRE(!paymentDayCounter_.empty(),
"no payment daycounter given");
147 QL_REQUIRE(!notionals_.empty(),
"no notional given");
149 "too many nominals (" << notionals_.size() <<
150 "), only " <<
n <<
" required");
152 "too many gearings (" << gearings_.size() <<
153 "), only " <<
n <<
" required");
155 "too many spreads (" << spreads_.size() <<
156 "), only " <<
n <<
" required");
158 "too many caps (" << caps_.size() <<
159 "), only " <<
n <<
" required");
161 "too many floors (" << floors_.size() <<
162 "), only " <<
n <<
" required");
164 Leg leg; leg.reserve(
n);
166 Calendar calendar = paymentCalendar_;
168 Date refStart, start, refEnd, end;
170 for (
Size i=0; i<
n; ++i) {
171 refStart = start = schedule_.date(i);
172 refEnd = end = schedule_.date(i+1);
173 Date paymentDate = calendar.
adjust(end, paymentAdjustment_);
174 if (i==0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
176 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
178 if (i==
n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
180 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
183 leg.push_back(ext::make_shared<FixedRateCoupon>(
189 start, end, refStart, refEnd));
192 leg.push_back(ext::make_shared<YoYInflationCoupon>(
204 leg.push_back(ext::make_shared<CappedFlooredYoYInflationCoupon>(
223 if (caps_.empty() && floors_.empty())
caplet and floorlet pricing for YoY inflation coupons
Cash flow vector builders.
degenerate base class for the Acyclic Visitor pattern
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Base inflation-coupon class.
ext::shared_ptr< InflationCouponPricer > pricer() const
void accept(AcyclicVisitor &) override
template class providing a null value for a given type.
Visitor for a specific class
virtual void visit(T &)=0
bool checkPricerImpl(const ext::shared_ptr< InflationCouponPricer > &) const override
makes sure you were given the correct type of pricer
YoYInflationCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, const ext::shared_ptr< YoYInflationIndex > &index, const Period &observationLag, const DayCounter &dayCounter, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date())
void accept(AcyclicVisitor &) override
BusinessDayConvention paymentAdjustment_
std::vector< Rate > caps_
yoyInflationLeg & withSpreads(Spread spread)
yoyInflationLeg & withFloors(Rate floor)
yoyInflationLeg & withPaymentAdjustment(BusinessDayConvention)
yoyInflationLeg(Schedule schedule, Calendar cal, ext::shared_ptr< YoYInflationIndex > index, const Period &observationLag)
yoyInflationLeg & withNotionals(Real notional)
yoyInflationLeg & withGearings(Real gearing)
std::vector< Real > notionals_
std::vector< Spread > spreads_
yoyInflationLeg & withPaymentDayCounter(const DayCounter &)
std::vector< Natural > fixingDays_
yoyInflationLeg & withCaps(Rate cap)
std::vector< Rate > floors_
yoyInflationLeg & withFixingDays(Natural fixingDays)
std::vector< Real > gearings_
DayCounter paymentDayCounter_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
Real Spread
spreads on interest rates
std::size_t Size
size of a container
Coupon paying a variable index-based rate.
T get(const std::vector< T > &v, Size i, U defaultValue)
Rate effectiveFixedRate(const std::vector< Spread > &spreads, const std::vector< Rate > &caps, const std::vector< Rate > &floors, Size i)
bool noOption(const std::vector< Rate > &caps, const std::vector< Rate > &floors, Size i)
void setCouponPricer(const Leg &leg, const ext::shared_ptr< FloatingRateCouponPricer > &pricer)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
ext::shared_ptr< BlackVolTermStructure > v