40 {
41
42 auto cmsData = QuantLib::ext::dynamic_pointer_cast<DurationAdjustedCmsLegData>(
data.concreteLegData());
43 QL_REQUIRE(cmsData, "Wrong LegType, expected CMS");
44
45 string indexName = cmsData->swapIndex();
46 auto index = *engineFactory->market()->swapIndex(indexName, configuration);
50
51 vector<double> spreads =
53 vector<double> gearings =
56 Size fixingDays = cmsData->fixingDays() == Null<Size>() ? index->fixingDays() : cmsData->fixingDays();
57
59
67 .
withPaymentLag(boost::apply_visitor(PaymentLagInteger(), paymentLag))
70
71 if (!
data.paymentCalendar().empty())
73
74 if (cmsData->caps().size() > 0)
76
77 if (cmsData->floors().size() > 0)
79
80
81 auto builder = QuantLib::ext::dynamic_pointer_cast<DurationAdjustedCmsCouponPricerBuilder>(
82 engineFactory->builder("DurationAdjustedCMS"));
83 QL_REQUIRE(builder != nullptr, "No builder found for DurationAdjustedCmsLeg");
84 auto couponPricer = builder->engine(IndexNameTranslator::instance().oreName(index->iborIndex()->name()));
85
86
87 Leg result = leg;
88 for (auto& c : result) {
89 auto f = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c);
90 QL_REQUIRE(f != nullptr,
91 "DurationAdjustedCmsLegBuilder::buildLeg(): internal error, expected FloatingRateCoupon");
92 f->setPricer(couponPricer);
93 }
94
95
96 if (cmsData->nakedOption()) {
97 result = StrippedCappedFlooredCouponLeg(result);
98 }
99
100 applyIndexing(result, data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
102 return result;
103}
DurationAdjustedCmsLeg & withPaymentCalendar(const Calendar &)
DurationAdjustedCmsLeg & withPaymentAdjustment(BusinessDayConvention)
DurationAdjustedCmsLeg & withSpreads(Spread spread)
DurationAdjustedCmsLeg & withFixingDays(Natural fixingDays)
DurationAdjustedCmsLeg & withPaymentLag(Natural lag)
DurationAdjustedCmsLeg & withFloors(Rate floor)
DurationAdjustedCmsLeg & withNotionals(Real notional)
DurationAdjustedCmsLeg & withGearings(Real gearing)
DurationAdjustedCmsLeg & withPaymentDayCounter(const DayCounter &)
DurationAdjustedCmsLeg & inArrears(bool flag=true)
DurationAdjustedCmsLeg & withCaps(Rate cap)
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
PaymentLag parsePaymentLag(const string &s)
Convert text to PaymentLag.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
vector< T > buildScheduledVectorNormalised(const vector< T > &values, const vector< string > &dates, const Schedule &schedule, const T &defaultValue, const bool checkAllValuesAppearInResult=false)
void applyAmortization(std::vector< Real > ¬ionals, const LegData &data, const Schedule &schedule, const bool annuityAllowed, const std::vector< Real > &rates)
void applyIndexing(Leg &leg, const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const QuantLib::Date &openEndDateReplacement, const bool useXbsCurves)
void addToRequiredFixings(const QuantLib::Leg &leg, const QuantLib::ext::shared_ptr< FixingDateGetter > &fixingDateGetter)
vector< T > buildScheduledVector(const vector< T > &values, const vector< string > &dates, const Schedule &schedule, const bool checkAllValuesAppearInResult=false)
boost::variant< QuantLib::Period, QuantLib::Natural > PaymentLag
Schedule makeSchedule(const ScheduleDates &data)