35 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
37 applyIndexing(leg,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
39 if (
data.legType() ==
"Fixed" && !
data.isNotResetXCCY()) {
41 QL_REQUIRE(!
data.fxIndex().empty(),
"FixedLegBuilder: need fx index for fx resetting leg");
47 if (
data.notionals().size() == 0) {
48 DLOG(
"Building FX Resettable with unspecified domestic notional");
51 LOG(
"Building FX Resettable with first domestic notional specified explicitly");
55 for (; j < leg.size(); ++j) {
56 QuantLib::ext::shared_ptr<FixedRateCoupon> coupon = QuantLib::ext::dynamic_pointer_cast<FixedRateCoupon>(leg[j]);
57 Date
fixingDate = fxIndex->fixingCalendar().advance(coupon->accrualStartDate(),
58 -
static_cast<Integer
>(fxIndex->fixingDays()), Days);
59 QuantLib::ext::shared_ptr<FixedRateFXLinkedNotionalCoupon> fxLinkedCoupon =
60 QuantLib::ext::make_shared<FixedRateFXLinkedNotionalCoupon>(
fixingDate,
data.foreignAmount(), fxIndex, coupon);
61 leg[j] = fxLinkedCoupon;
72 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
74 applyIndexing(leg,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
81 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
82 auto floatData = QuantLib::ext::dynamic_pointer_cast<FloatingLegData>(
data.concreteLegData());
83 QL_REQUIRE(floatData,
"Wrong LegType, expected Floating");
84 string indexName = floatData->index();
85 auto index = *engineFactory->market()->iborIndex(indexName, configuration);
87 auto ois = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index);
90 QuantLib::ext::shared_ptr<OvernightIndex> idx = ois;
91 if (!floatData->historicalFixings().empty())
92 idx = QuantLib::ext::make_shared<OvernightIndexWithFixingOverride>(ois, floatData->historicalFixings());
93 result =
makeOISLeg(
data, idx, engineFactory,
true, openEndDateReplacement);
95 auto bma = QuantLib::ext::dynamic_pointer_cast<QuantExt::BMAIndexWrapper>(index);
97 result =
makeBMALeg(
data, bma, engineFactory, openEndDateReplacement);
99 QuantLib::ext::shared_ptr<IborIndex> idx = index;
100 if (!floatData->historicalFixings().empty())
101 idx = QuantLib::ext::make_shared<IborIndexWithFixingOverride>(index, floatData->historicalFixings());
102 result =
makeIborLeg(
data, idx, engineFactory,
true, openEndDateReplacement);
105 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
110 if (
data.legType() ==
"Floating" && !
data.isNotResetXCCY()) {
111 QL_REQUIRE(!
data.fxIndex().empty(),
"FloatingRateLegBuilder: need fx index for fx resetting leg");
113 configuration,
true);
122 if (
data.notionals().size() == 0) {
123 DLOG(
"Building FX Resettable with unspecified domestic notional");
127 LOG(
"Building FX Resettable with first domestic notional specified explicitly");
132 for (; j < result.size(); ++j) {
133 QuantLib::ext::shared_ptr<FloatingRateCoupon> coupon =
134 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(result[j]);
135 Date
fixingDate = fxIndex->fixingCalendar().advance(coupon->accrualStartDate(),
136 -
static_cast<Integer
>(fxIndex->fixingDays()), Days);
137 QuantLib::ext::shared_ptr<FloatingRateFXLinkedNotionalCoupon> fxLinkedCoupon =
138 QuantLib::ext::make_shared<FloatingRateFXLinkedNotionalCoupon>(
fixingDate,
data.foreignAmount(),
141 fxLinkedCoupon->setPricer(coupon->pricer());
142 result[j] = fxLinkedCoupon;
154 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
160 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
161 auto cpiData = QuantLib::ext::dynamic_pointer_cast<CPILegData>(
data.concreteLegData());
162 QL_REQUIRE(cpiData,
"Wrong LegType, expected CPI");
163 string inflationIndexName = cpiData->index();
164 auto index = *engineFactory->market()->zeroInflationIndex(inflationIndexName, configuration);
165 Leg result =
makeCPILeg(
data, index, engineFactory, openEndDateReplacement);
166 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
173 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
174 auto yyData = QuantLib::ext::dynamic_pointer_cast<YoYLegData>(
data.concreteLegData());
175 QL_REQUIRE(yyData,
"Wrong LegType, expected YY");
176 string inflationIndexName = yyData->index();
177 bool irregularYoY = yyData->irregularYoY();
180 auto index = *engineFactory->market()->yoyInflationIndex(inflationIndexName, configuration);
181 result =
makeYoYLeg(
data, index, engineFactory, openEndDateReplacement);
182 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
184 QuantLib::ext::make_shared<FixingDateGetter>(requiredFixings));
186 auto index = *engineFactory->market()->zeroInflationIndex(inflationIndexName, configuration);
187 result =
makeYoYLeg(
data, index, engineFactory, openEndDateReplacement);
188 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
196 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
197 auto cmsData = QuantLib::ext::dynamic_pointer_cast<CMSLegData>(
data.concreteLegData());
198 QL_REQUIRE(cmsData,
"Wrong LegType, expected CMS");
199 string swapIndexName = cmsData->swapIndex();
200 auto index = *engineFactory->market()->swapIndex(swapIndexName, configuration);
201 Leg result =
makeCMSLeg(
data, index, engineFactory,
true, openEndDateReplacement);
202 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
209 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
210 auto cmbData = QuantLib::ext::dynamic_pointer_cast<CMBLegData>(
data.concreteLegData());
211 QL_REQUIRE(cmbData,
"Wrong LegType, expected CMB");
212 string indexName = cmbData->genericBond();
214 Leg result =
makeCMBLeg(
data, engineFactory,
true, openEndDateReplacement);
215 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
222 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
223 auto digitalCmsData = QuantLib::ext::dynamic_pointer_cast<DigitalCMSLegData>(
data.concreteLegData());
224 QL_REQUIRE(digitalCmsData,
"Wrong LegType, expected DigitalCMS");
226 auto cmsData = QuantLib::ext::dynamic_pointer_cast<CMSLegData>(digitalCmsData->underlying());
227 QL_REQUIRE(cmsData,
"Incomplete DigitalCmsLeg, expected CMSLegData");
229 string swapIndexName = digitalCmsData->underlying()->swapIndex();
230 auto index = *engineFactory->market()->swapIndex(swapIndexName, configuration);
232 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
239 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
240 auto cmsSpreadData = QuantLib::ext::dynamic_pointer_cast<CMSSpreadLegData>(
data.concreteLegData());
241 QL_REQUIRE(cmsSpreadData,
"Wrong LegType, expected CMSSpread");
242 auto index1 = *engineFactory->market()->swapIndex(cmsSpreadData->swapIndex1(), configuration);
243 auto index2 = *engineFactory->market()->swapIndex(cmsSpreadData->swapIndex2(), configuration);
245 QuantLib::ext::make_shared<QuantLib::SwapSpreadIndex>(
246 "CMSSpread_" + index1->familyName() +
"_" + index2->familyName(), index1, index2),
247 engineFactory,
true, openEndDateReplacement);
248 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
255 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
256 auto digitalCmsSpreadData = QuantLib::ext::dynamic_pointer_cast<DigitalCMSSpreadLegData>(
data.concreteLegData());
257 QL_REQUIRE(digitalCmsSpreadData,
"Wrong LegType, expected DigitalCMSSpread");
259 auto cmsSpreadData = QuantLib::ext::dynamic_pointer_cast<CMSSpreadLegData>(digitalCmsSpreadData->underlying());
260 QL_REQUIRE(cmsSpreadData,
"Incomplete DigitalCmsSpread Leg, expected CMSSpread data");
262 auto index1 = *engineFactory->market()->swapIndex(cmsSpreadData->swapIndex1(), configuration);
263 auto index2 = *engineFactory->market()->swapIndex(cmsSpreadData->swapIndex2(), configuration);
267 QuantLib::ext::make_shared<QuantLib::SwapSpreadIndex>(
268 "CMSSpread_" + index1->familyName() +
"_" + index2->familyName(), index1, index2),
269 engineFactory, openEndDateReplacement);
270 applyIndexing(result,
data, engineFactory, requiredFixings, openEndDateReplacement, useXbsCurves);
277 const QuantLib::Date& openEndDateReplacement,
const bool useXbsCurves)
const {
278 auto eqData = QuantLib::ext::dynamic_pointer_cast<EquityLegData>(
data.concreteLegData());
279 QL_REQUIRE(eqData,
"Wrong LegType, expected Equity");
280 string eqName = eqData->eqName();
281 auto eqCurve = *engineFactory->market()->equityCurve(eqName, configuration);
284 if (eqData->returnType() == EquityReturnType::Dividend) {
285 Real spotVal = eqCurve->equitySpot()->value();
286 Handle<Quote> divSpot = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(spotVal));
287 eqCurve = eqCurve->clone(divSpot, eqCurve->equityForecastCurve(), eqCurve->equityDividendCurve());
293 if (!eqData->eqCurrency().empty())
296 if (eqCurve->currency().empty()) {
297 WLOG(
"No equity currency set in EquityIndex for equity " << eqCurve->name());
300 if (!eqCurrency.empty())
301 QL_REQUIRE(eqCurve->currency() == eqCurrency,
302 "Equity Currency provided does not match currency of Equity Curve");
304 eqCurrency = eqCurve->currency();
307 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex =
nullptr;
309 if (!eqCurrency.empty() && dataCurrency != eqCurrency) {
310 QL_REQUIRE(eqData->fxIndex() !=
"",
311 "No FxIndex - if equity currency differs from leg currency an FxIndex must be provided");
315 if (!eqCurve->currency().empty() && !eqCurrency.empty()) {
316 QL_REQUIRE(eqCurve->currency() == eqCurrency,
317 "Equity Currency provided does not match currency of Equity Curve");
320 fxIndex =
buildFxIndex(eqData->fxIndex(),
data.currency(), eqCurrency.code(), engineFactory->market(),
321 configuration, useXbsCurves);
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Serializable object holding leg data.
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Leg buildLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const string &configuration, const QuantLib::Date &openEndDateReplacement=Null< Date >(), const bool useXbsCurves=false) const override
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
QuantLib::ext::shared_ptr< ConstantMaturityBondIndex > parseConstantMaturityBondIndex(const string &name)
Convert std::string to QuantExt::ConstantMaturityBondIndex.
leg data model and serialization
#define LOG(text)
Logging Macro (Level = Notice)
#define DLOG(text)
Logging Macro (Level = Debug)
#define WLOG(text)
Logging Macro (Level = Warning)
market data related utilties
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Leg makeOISLeg(const LegData &data, const QuantLib::ext::shared_ptr< OvernightIndex > &index, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const bool attachPricer, const QuantLib::Date &openEndDateReplacement)
Leg makeDigitalCMSLeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantLib::SwapIndex > &swapIndex, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const bool attachPricer, const QuantLib::Date &openEndDateReplacement)
Leg makeSimpleLeg(const LegData &data)
void applyIndexing(Leg &leg, const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, RequiredFixings &requiredFixings, const QuantLib::Date &openEndDateReplacement, const bool useXbsCurves)
Leg makeBMALeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantExt::BMAIndexWrapper > &indexWrapper, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const QuantLib::Date &openEndDateReplacement)
void addToRequiredFixings(const QuantLib::Leg &leg, const QuantLib::ext::shared_ptr< FixingDateGetter > &fixingDateGetter)
Leg makeCMBLeg(const LegData &data, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const bool attachPricer, const QuantLib::Date &openEndDateReplacement)
Leg makeYoYLeg(const LegData &data, const QuantLib::ext::shared_ptr< InflationIndex > &index, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const QuantLib::Date &openEndDateReplacement)
Leg makeCMSSpreadLeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantLib::SwapSpreadIndex > &swapSpreadIndex, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const bool attachPricer, const QuantLib::Date &openEndDateReplacement)
Leg makeDigitalCMSSpreadLeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantLib::SwapSpreadIndex > &swapSpreadIndex, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const QuantLib::Date &openEndDateReplacement)
Leg makeCPILeg(const LegData &data, const QuantLib::ext::shared_ptr< ZeroInflationIndex > &index, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const QuantLib::Date &openEndDateReplacement)
Leg makeCMSLeg(const LegData &data, const QuantLib::ext::shared_ptr< QuantLib::SwapIndex > &swapIndex, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const bool attachPricer, const QuantLib::Date &openEndDateReplacement)
Leg makeEquityLeg(const LegData &data, const QuantLib::ext::shared_ptr< EquityIndex2 > &equityCurve, const QuantLib::ext::shared_ptr< QuantExt::FxIndex > &fxIndex, const QuantLib::Date &openEndDateReplacement)
Leg makeZCFixedLeg(const LegData &data, const QuantLib::Date &openEndDateReplacement)
Leg makeIborLeg(const LegData &data, const QuantLib::ext::shared_ptr< IborIndex > &index, const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const bool attachPricer, const QuantLib::Date &openEndDateReplacement)
Leg makeFixedLeg(const LegData &data, const QuantLib::Date &openEndDateReplacement)
QuantLib::ext::shared_ptr< QuantExt::FxIndex > buildFxIndex(const string &fxIndex, const string &domestic, const string &foreign, const QuantLib::ext::shared_ptr< Market > &market, const string &configuration, bool useXbsCurves)
Serializable Credit Default Swap.
Reference data model and serialization.