19#include <ql/cashflows/capflooredinflationcoupon.hpp>
20#include <ql/cashflows/cashflowvectors.hpp>
21#include <ql/cashflows/inflationcoupon.hpp>
22#include <ql/cashflows/inflationcouponpricer.hpp>
28 const Date& endDate, Natural fixingDays,
29 const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
30 const DayCounter& dayCounter, Real gearing, Spread spread,
31 const Date& refPeriodStart,
const Date& refPeriodEnd,
bool addInflationNotional)
33 dayCounter, gearing, spread, refPeriodStart, refPeriodEnd),
34 addInflationNotional_(addInflationNotional) {}
37 Visitor<YoYInflationCoupon>* v1 =
dynamic_cast<Visitor<YoYInflationCoupon>*
>(&v);
41 QuantLib::YoYInflationCoupon::accept(v);
45 Real RateYoY = QuantLib::YoYInflationCoupon::rate();
47 RateYoY = gearing_ * ((RateYoY -
spread_) / gearing_ + 1) +
spread_;
53 const ext::shared_ptr<QuantLib::YoYInflationCoupon>& underlying, Rate cap, Rate floor,
bool addInflationNotional)
66 const Date& paymentDate, Real nominal,
const Date& startDate,
const Date& endDate, Natural fixingDays,
67 const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
const DayCounter& dayCounter,
68 Real gearing, Spread spread,
const Rate cap,
const Rate floor,
const Date& refPeriodStart,
const Date& refPeriodEnd,
69 bool addInflationNotional)
71 observationLag, dayCounter, gearing, spread, cap, floor, refPeriodStart,
73 addInflationNotional_(addInflationNotional) {
85 Visitor<CappedFlooredYoYInflationCoupon>* v1 =
dynamic_cast<Visitor<CappedFlooredYoYInflationCoupon>*
>(&v);
89 QuantLib::CappedFlooredYoYInflationCoupon::accept(v);
93 Real RateYoY = QuantLib::CappedFlooredYoYInflationCoupon::rate();
95 RateYoY = gearing_ * ((RateYoY -
spread_) / gearing_ + 1) +
spread_;
101 const Period& observationLag)
102 : schedule_(std::move(schedule)), index_(std::move(index)), observationLag_(observationLag),
103 paymentAdjustment_(ModifiedFollowing), paymentCalendar_(std::move(paymentCalendar)),
104 addInflationNotional_(false) {}
137 gearings_ = std::vector<Real>(1, gearing);
147 spreads_ = std::vector<Spread>(1, spread);
157 caps_ = std::vector<Rate>(1, cap);
167 floors_ = std::vector<Rate>(1, floor);
186yoyInflationLeg::operator Leg()
const {
188 Size n = schedule_.size() - 1;
189 QL_REQUIRE(!notionals_.empty(),
"no notional given");
190 QL_REQUIRE(notionals_.size() <= n,
"too many nominals (" << notionals_.size() <<
"), only " << n <<
" required");
191 QL_REQUIRE(gearings_.size() <= n,
"too many gearings (" << gearings_.size() <<
"), only " << n <<
" required");
192 QL_REQUIRE(spreads_.size() <= n,
"too many spreads (" << spreads_.size() <<
"), only " << n <<
" required");
193 QL_REQUIRE(caps_.size() <= n,
"too many caps (" << caps_.size() <<
"), only " << n <<
" required");
194 QL_REQUIRE(floors_.size() <= n,
"too many floors (" << floors_.size() <<
"), only " << n <<
" required");
199 Calendar calendar = paymentCalendar_;
201 Date refStart, start, refEnd, end;
203 for (Size i = 0; i < n; ++i) {
204 refStart = start = schedule_.date(i);
205 refEnd = end = schedule_.date(i + 1);
206 Date paymentDate = calendar.adjust(end, paymentAdjustment_);
207 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
208 BusinessDayConvention bdc = schedule_.businessDayConvention();
209 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
211 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
212 BusinessDayConvention bdc = schedule_.businessDayConvention();
213 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
215 if (detail::get(gearings_, i, 1.0) == 0.0) {
216 leg.push_back(ext::shared_ptr<CashFlow>(
new FixedRateCoupon(
217 paymentDate, detail::get(notionals_, i, 1.0), detail::effectiveFixedRate(spreads_, caps_, floors_, i),
218 paymentDayCounter_, start, end, refStart, refEnd)));
220 if (detail::noOption(caps_, floors_, i)) {
222 paymentDate, detail::get(notionals_, i, 1.0), start, end, detail::get(fixingDays_, i, 0), index_,
223 observationLag_, paymentDayCounter_, detail::get(gearings_, i, 1.0), detail::get(spreads_, i, 0.0),
224 refStart, refEnd, addInflationNotional_));
228 ext::shared_ptr<YoYInflationCouponPricer> pricer =
229 ext::make_shared<YoYInflationCouponPricer>(rateCurve_);
230 coup->setPricer(pricer);
231 leg.push_back(ext::dynamic_pointer_cast<CashFlow>(coup));
235 paymentDate, detail::get(notionals_, i, 1.0), start, end, detail::get(fixingDays_, i, 0), index_,
236 observationLag_, paymentDayCounter_, detail::get(gearings_, i, 1.0), detail::get(spreads_, i, 0.0),
237 detail::get(caps_, i, Null<Rate>()), detail::get(floors_, i, Null<Rate>()), refStart, refEnd,
238 addInflationNotional_)));
bool addInflationNotional_
Rate rate() const override
virtual void accept(AcyclicVisitor &) override
CappedFlooredYoYInflationCoupon(const ext::shared_ptr< YoYInflationCoupon > &underlying, Rate cap=Null< Rate >(), Rate floor=Null< Rate >(), bool addInflationNotional=false)
bool addInflationNotional_
Rate rate() const override
virtual void accept(AcyclicVisitor &) override
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(), bool addInflationNotional=false)
yoyInflationLeg & withRateCurve(const Handle< YieldTermStructure > &rateCurve)
BusinessDayConvention paymentAdjustment_
bool addInflationNotional_
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 &)
Handle< YieldTermStructure > rateCurve_
std::vector< Natural > fixingDays_
yoyInflationLeg & withCaps(Rate cap)
yoyInflationLeg & withInflationNotional(bool addInflationNotional_)
std::vector< Rate > floors_
yoyInflationLeg & withFixingDays(Natural fixingDays)
std::vector< Real > gearings_
DayCounter paymentDayCounter_