35#include <ql/cashflows/cashflows.hpp>
36#include <ql/cashflows/cashflowvectors.hpp>
37#include <ql/cashflows/inflationcouponpricer.hpp>
48 if (
cap != Null<Rate>()) {
52 if (
floor != Null<Rate>()) {
57 if (
cap != Null<Rate>()) {
61 if (
floor != Null<Rate>()) {
67 QL_REQUIRE(
cap >=
floor,
"cap level (" <<
cap <<
") less than floor level (" <<
floor <<
")");
72 const ext::shared_ptr<NonStandardYoYInflationCoupon>& underlying, Rate cap, Rate floor)
74 underlying->accrualEndDate(), underlying->fixingDays(), underlying->cpiIndex(),
75 underlying->observationLag(), underlying->dayCounter(), underlying->gearing(),
76 underlying->spread(), underlying->referencePeriodStart(),
77 underlying->referencePeriodEnd(), underlying->addInflationNotional(),
78 underlying->interpolationType()),
79 underlying_(underlying), isFloored_(false), isCapped_(false) {
81 registerWith(underlying);
85 const Date& paymentDate, Real nominal,
const Date& startDate,
const Date& endDate, Natural fixingDays,
86 const ext::shared_ptr<ZeroInflationIndex>& index,
const Period& observationLag,
const DayCounter& dayCounter,
87 Real gearing, Spread spread,
const Rate cap,
const Rate floor,
const Date& refPeriodStart,
const Date& refPeriodEnd,
88 bool addInflationNotional, QuantLib::CPI::InterpolationType interpolation)
90 dayCounter, gearing, spread, refPeriodStart, refPeriodEnd, addInflationNotional,
92 isFloored_(false), isCapped_(false) {
97 const ext::shared_ptr<NonStandardYoYInflationCouponPricer>& pricer) {
99 NonStandardYoYInflationCoupon::setPricer(pricer);
109 QL_REQUIRE(
underlying_->pricer(),
"pricer not set");
111 QL_REQUIRE(
pricer_,
"pricer not set");
115 Rate floorletRate = 0.;
120 Rate capletRate = 0.;
126 return swapletRate + floorletRate - capletRate;
156 Visitor<NonStandardCappedFlooredYoYInflationCoupon>* v1 =
157 dynamic_cast<Visitor<NonStandardCappedFlooredYoYInflationCoupon>*
>(&v);
166 const ext::shared_ptr<ZeroInflationIndex>& index,
167 const Period& observationLag)
168 : schedule_(schedule), index_(index), observationLag_(observationLag), paymentAdjustment_(ModifiedFollowing),
169 paymentCalendar_(paymentCalendar), addInflationNotional_(false), interpolation_(
QuantLib::CPI::Flat) {}
202 gearings_ = std::vector<Real>(1, gearing);
212 spreads_ = std::vector<Spread>(1, spread);
222 caps_ = std::vector<Rate>(1, cap);
232 floors_ = std::vector<Rate>(1, floor);
256NonStandardYoYInflationLeg::operator Leg()
const {
258 Size n = schedule_.size() - 1;
259 QL_REQUIRE(!notionals_.empty(),
"no notional given");
260 QL_REQUIRE(notionals_.size() <= n,
"too many nominals (" << notionals_.size() <<
"), only " << n <<
" required");
261 QL_REQUIRE(gearings_.size() <= n,
"too many gearings (" << gearings_.size() <<
"), only " << n <<
" required");
262 QL_REQUIRE(spreads_.size() <= n,
"too many spreads (" << spreads_.size() <<
"), only " << n <<
" required");
263 QL_REQUIRE(caps_.size() <= n,
"too many caps (" << caps_.size() <<
"), only " << n <<
" required");
264 QL_REQUIRE(floors_.size() <= n,
"too many floors (" << floors_.size() <<
"), only " << n <<
" required");
269 Calendar calendar = paymentCalendar_;
271 Date refStart, start, refEnd, end;
273 for (Size i = 0; i < n; ++i) {
274 refStart = start = schedule_.date(i);
275 refEnd = end = schedule_.date(i + 1);
276 Date paymentDate = calendar.adjust(end, paymentAdjustment_);
277 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
278 BusinessDayConvention bdc = schedule_.businessDayConvention();
279 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
281 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
282 BusinessDayConvention bdc = schedule_.businessDayConvention();
283 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
285 if (detail::get(gearings_, i, 1.0) == 0.0) {
286 leg.push_back(ext::shared_ptr<CashFlow>(
new FixedRateCoupon(
287 paymentDate, detail::get(notionals_, i, 1.0), detail::effectiveFixedRate(spreads_, caps_, floors_, i),
288 paymentDayCounter_, start, end, refStart, refEnd)));
290 if (detail::noOption(caps_, floors_, i)) {
292 paymentDate, detail::get(notionals_, i, 1.0), start, end, detail::get(fixingDays_, i, 0), index_,
293 observationLag_, paymentDayCounter_, detail::get(gearings_, i, 1.0), detail::get(spreads_, i, 0.0),
294 refStart, refEnd, addInflationNotional_, interpolation_));
298 ext::shared_ptr<NonStandardYoYInflationCouponPricer> pricer(
300 coup->setPricer(pricer);
301 leg.push_back(ext::dynamic_pointer_cast<CashFlow>(coup));
305 paymentDate, detail::get(notionals_, i, 1.0), start, end, detail::get(fixingDays_, i, 0), index_,
306 observationLag_, paymentDayCounter_, detail::get(gearings_, i, 1.0), detail::get(spreads_, i, 0.0),
307 detail::get(caps_, i, Null<Rate>()), detail::get(floors_, i, Null<Rate>()), refStart, refEnd,
308 addInflationNotional_, interpolation_)));
Capped or floored inflation coupon.
virtual void setCommon(Rate cap, Rate floor)
Rate rate() const override
swap(let) rate
Rate effectiveCap() const
effective cap of fixing
NonStandardCappedFlooredYoYInflationCoupon(const ext::shared_ptr< NonStandardYoYInflationCoupon > &underlying, Rate cap=Null< Rate >(), Rate floor=Null< Rate >())
Rate effectiveFloor() const
effective floor of fixing
void setPricer(const ext::shared_ptr< NonStandardYoYInflationCouponPricer > &)
virtual void accept(AcyclicVisitor &v) override
ext::shared_ptr< NonStandardYoYInflationCoupon > underlying_
Coupon paying a YoY-inflation type index
bool addInflationNotional_
virtual Rate rate() const override
virtual void accept(AcyclicVisitor &) override
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
Spread spread() const
spread paid over the fixing of the underlying index
base pricer for capped/floored YoY inflation coupons
BusinessDayConvention paymentAdjustment_
bool addInflationNotional_
std::vector< Rate > caps_
NonStandardYoYInflationLeg & withPaymentAdjustment(BusinessDayConvention)
NonStandardYoYInflationLeg & withFloors(Rate floor)
NonStandardYoYInflationLeg & withFixingDays(Natural fixingDays)
NonStandardYoYInflationLeg & withRateCurve(const Handle< YieldTermStructure > &rateCurve)
QuantLib::CPI::InterpolationType interpolation_
NonStandardYoYInflationLeg & withSpreads(Spread spread)
NonStandardYoYInflationLeg(const Schedule &schedule, const Calendar &cal, const ext::shared_ptr< ZeroInflationIndex > &index, const Period &observationLag)
NonStandardYoYInflationLeg & withPaymentDayCounter(const DayCounter &)
std::vector< Real > notionals_
std::vector< Spread > spreads_
NonStandardYoYInflationLeg & withGearings(Real gearing)
NonStandardYoYInflationLeg & withNotionals(Real notional)
Handle< YieldTermStructure > rateCurve_
std::vector< Natural > fixingDays_
NonStandardYoYInflationLeg & withObservationInterpolation(QuantLib::CPI::InterpolationType interpolation)
std::vector< Rate > floors_
NonStandardYoYInflationLeg & withCaps(Rate cap)
NonStandardYoYInflationLeg & withInflationNotional(bool addInflationNotional_)
std::vector< Real > gearings_
DayCounter paymentDayCounter_
const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > pricer_