Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
DurationAdjustedCmsLegBuilder Class Reference

#include <ored/portfolio/durationadjustedcmslegbuilder.hpp>

+ Inheritance diagram for DurationAdjustedCmsLegBuilder:
+ Collaboration diagram for DurationAdjustedCmsLegBuilder:

Public Member Functions

 DurationAdjustedCmsLegBuilder ()
 
QuantLib::Leg buildLeg (const ore::data::LegData &data, const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &engineFactory, ore::data::RequiredFixings &requiredFixings, const std::string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
 
- Public Member Functions inherited from LegBuilder
 LegBuilder (const string &legType)
 
virtual ~LegBuilder ()
 
virtual Leg buildLeg (const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const =0
 
const string & legType () const
 

Detailed Description

Definition at line 33 of file durationadjustedcmslegbuilder.hpp.

Constructor & Destructor Documentation

◆ DurationAdjustedCmsLegBuilder()

Definition at line 35 of file durationadjustedcmslegbuilder.hpp.

35: LegBuilder("DurationAdjustedCMS") {}
LegBuilder(const string &legType)

Member Function Documentation

◆ buildLeg()

Leg buildLeg ( const ore::data::LegData data,
const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  engineFactory,
ore::data::RequiredFixings requiredFixings,
const std::string &  configuration,
const QuantLib::Date &  openEndDateReplacement = Null<Date>(),
const bool  useXbsCurves = false 
) const
override

Definition at line 37 of file durationadjustedcmslegbuilder.cpp.

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);
47 Schedule schedule = makeSchedule(data.schedule(), openEndDateReplacement);
48 DayCounter dc = parseDayCounter(data.dayCounter());
49 BusinessDayConvention bdc = parseBusinessDayConvention(data.paymentConvention());
50
51 vector<double> spreads =
52 ore::data::buildScheduledVectorNormalised(cmsData->spreads(), cmsData->spreadDates(), schedule, 0.0);
53 vector<double> gearings =
54 ore::data::buildScheduledVectorNormalised(cmsData->gearings(), cmsData->gearingDates(), schedule, 1.0);
55 vector<double> notionals = buildScheduledVector(data.notionals(), data.notionalDates(), schedule);
56 Size fixingDays = cmsData->fixingDays() == Null<Size>() ? index->fixingDays() : cmsData->fixingDays();
57
58 applyAmortization(notionals, data, schedule, false);
59
60 PaymentLag paymentLag = parsePaymentLag(data.paymentLag());
61 DurationAdjustedCmsLeg leg = DurationAdjustedCmsLeg(schedule, index, cmsData->duration())
62 .withNotionals(notionals)
63 .withSpreads(spreads)
64 .withGearings(gearings)
67 .withPaymentLag(boost::apply_visitor(PaymentLagInteger(), paymentLag))
68 .withFixingDays(fixingDays)
69 .inArrears(cmsData->isInArrears());
70
71 if (!data.paymentCalendar().empty())
72 leg.withPaymentCalendar(parseCalendar(data.paymentCalendar()));
73
74 if (cmsData->caps().size() > 0)
75 leg.withCaps(buildScheduledVector(cmsData->caps(), cmsData->capDates(), schedule));
76
77 if (cmsData->floors().size() > 0)
78 leg.withFloors(buildScheduledVector(cmsData->floors(), cmsData->floorDates(), schedule));
79
80 // Get a coupon pricer for the leg
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 // Loop over the coupons in the leg and set pricer
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 // build naked option leg if required
96 if (cmsData->nakedOption()) {
97 result = StrippedCappedFlooredCouponLeg(result);
98 }
99
100 applyIndexing(result, data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
101 addToRequiredFixings(result, QuantLib::ext::make_shared<FixingDateGetter>(requiredFixings));
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.
Definition: parsers.cpp:157
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Definition: parsers.cpp:173
PaymentLag parsePaymentLag(const string &s)
Convert text to PaymentLag.
Definition: parsers.cpp:628
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Definition: parsers.cpp:209
@ data
Definition: log.hpp:77
vector< T > buildScheduledVectorNormalised(const vector< T > &values, const vector< string > &dates, const Schedule &schedule, const T &defaultValue, const bool checkAllValuesAppearInResult=false)
Definition: legdata.hpp:1139
void applyAmortization(std::vector< Real > &notionals, const LegData &data, const Schedule &schedule, const bool annuityAllowed, const std::vector< Real > &rates)
Definition: legdata.cpp:2593
void applyIndexing(Leg &leg, const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const QuantLib::Date &openEndDateReplacement, const bool useXbsCurves)
Definition: legdata.cpp:2633
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)
Definition: legdata.hpp:1061
boost::variant< QuantLib::Period, QuantLib::Natural > PaymentLag
Definition: types.hpp:32
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
+ Here is the call graph for this function: