Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.
50 {
51 DLOG(
"BondTRS::build() called for trade " <<
id());
52
53
58
59 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
60 QuantLib::ext::shared_ptr<EngineBuilder> builder_trs = engineFactory->builder("BondTRS");
63
66
67 auto configuration = builder_trs->configuration(MarketContext::pricing);
69
70
71
74 << "), no fx index must be given");
77 << "), a fx index must be given");
78
81
82
83 DLOG(
"build valuation and payment dates vectors");
84
89
91 Period plPeriod = boost::apply_visitor(PaymentLagPeriod(), paymentLag);
95
97
98 for (auto const& d : schedule.dates()) {
99 valuationDates.push_back(observationCalendar.advance(d, -observationLag, observationConvention));
100 if (d != schedule.dates().front())
101 paymentDates.push_back(paymentCalendar.advance(d, plPeriod, paymentConvention));
102 }
103
107 "paymentDates size (" <<
paymentDates_.size() <<
") does no match valuatioDates size ("
111 }
112
113 DLOG(
"valuation schedule:");
116
117 DLOG(
"payment schedule:");
120
121
122
123 QuantLib::ext::shared_ptr<FxIndex>
fxIndex;
127 engineFactory->configuration(MarketContext::pricing));
128
129 }
130
131
132 BondIndexBuilder bondIndexBuilder(bondData_, useDirtyPrices_, false, NullCalendar(), false, engineFactory);
133 auto bondIndex = bondIndexBuilder.bondIndex();
134
135
136 Real effectiveInitialPrice = bondIndexBuilder.priceAdjustment(
initialPrice_);
137 if (effectiveInitialPrice != Null<Real>())
138 effectiveInitialPrice = effectiveInitialPrice / 100.0;
139
140
141
143 DLOG(
"adding indexing information from trs leg to funding leg");
144
145 std::vector<string> stringValuationDates;
148 ScheduleData valuationSchedule(ScheduleDates("", "", "", stringValuationDates, ""));
149
150
153 Null<Real>(), valuationSchedule, 0, "", "U", false);
155
156
158 Indexing fxIndexing(
fxIndex_,
"",
false,
false,
false, 1.0, Null<Real>(), Null<Real>(), valuationSchedule,
159 0, "", "U", false);
161 }
162
163
166
167
169 }
170
171
172
173 Leg
fundingLeg = legBuilder->buildLeg(fundingLegData_, engineFactory, requiredFixings_, configuration);
174 Leg fundingNotionalLeg;
177 Natural fundingLegPayLag = 0;
178 fundingNotionalLeg =
183 }
184
186 "funding leg and total return lag are both rec or both pay");
187 DLOG(
"Before bondTRS");
188 auto bondTRS = QuantLib::ext::make_shared<QuantExt::BondTRS>(
193 DLOG(
"After bondTRS");
194 QuantLib::ext::shared_ptr<BondTRSEngineBuilder> trsBondBuilder =
195 QuantLib::ext::dynamic_pointer_cast<BondTRSEngineBuilder>(builder_trs);
196 QL_REQUIRE(trsBondBuilder, "No Builder found for BondTRS: " << id());
200
203
204
205
209
210
211 addToRequiredFixings(bondTRS->returnLeg(), QuantLib::ext::make_shared<FixingDateGetter>(requiredFixings_));
212 bondIndexBuilder.addRequiredFixings(requiredFixings_, bondTRS->returnLeg());
213
214
215
217 for (
auto const& c :
bondIndex->bond()->cashflows()) {
219 }
220 }
221
223 auto inflationIndices = extractAllInflationUnderlyingFromBond(
bondIndex->bond());
224 for (const auto& cf : bondTRS->returnLeg()) {
225 auto tcf = QuantLib::ext::dynamic_pointer_cast<TRSCashFlow>(cf);
226 if (tcf != nullptr) {
227 for (const auto& [key, index] : inflationIndices) {
228 auto [
name, interpolation, couponFrequency, observationLag] = key;
229 std::string oreName = IndexNameTranslator::instance().oreName(
name);
231 tcf->fixingStartDate() - observationLag, oreName, false, index->frequency(),
232 index->availabilityLag(), interpolation, couponFrequency, Date::maxDate(), false, false);
233 }
234 }
235 }
236 }
237}
bool payBondCashFlowsImmediately_
boost::shared_ptr< QuantExt::FxIndex > fxIndex_
const std::vector< Date > & valuationDates() const
const std::vector< Leg > & fundingLeg() const
const std::vector< Date > & paymentDates() const
std::vector< Date > paymentDates_
const boost::shared_ptr< QuantExt::FxIndex > & fxIndex() const
const boost::shared_ptr< QuantExt::BondIndex > & bondIndex() const
const string & currency() const
void populateFromBondReferenceData(const QuantLib::ext::shared_ptr< BondReferenceDatum > &referenceDatum, const std::string &startDate="", const std::string &endDate="")
populate data from reference datum and check data for completeness
const string & calendar() const
bool isInflationLinked() const
Real bondNotional() const
std::string observationConvention_
const std::string & observationConvention() const
const bool useDirtyPrices() const
const std::string & observationCalendar() const
const std::string & paymentCalendar() const
const std::string & observationLag() const
std::string observationLag_
const std::string & paymentLag() const
const std::string & paymentConvention() const
std::string paymentConvention_
const string & paymentConvention() const
const string & currency() const
bool notionalFinalExchange() const
bool notionalAmortizingExchange() const
const std::vector< Indexing > & indexing() const
const string & legType() const
const std::string & paymentCalendar() const
const bool indexingFromAssetLeg() const
const vector< string > & notionalDates() const
bool notionalInitialExchange() const
const vector< double > & notionals() const
void addZeroInflationFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const bool indexInterpolated, const Frequency indexFrequency, const Period &indexAvailabilityLag, const CPI::InterpolationType coupopnInterpolation, const Frequency couponFrequency, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
std::vector< bool > legPayers_
std::vector< string > legCurrencies_
std::vector< QuantLib::Leg > legs_
void setSensitivityTemplate(const EngineBuilder &builder)
RequiredFixings requiredFixings_
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
PaymentLag parsePaymentLag(const string &s)
Convert text to PaymentLag.
#define DLOG(text)
Logging Macro (Level = Debug)
void addToRequiredFixings(const QuantLib::Leg &leg, const QuantLib::ext::shared_ptr< FixingDateGetter > &fixingDateGetter)
std::string to_string(const LocationInfo &l)
boost::variant< QuantLib::Period, QuantLib::Natural > PaymentLag
Leg makeNotionalLeg(const Leg &refLeg, const bool initNomFlow, const bool finalNomFlow, const bool amortNomFlow, const Natural notionalPaymentLag, const BusinessDayConvention paymentConvention, const Calendar paymentCalendar, const bool excludeIndexing)
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)
Schedule makeSchedule(const ScheduleDates &data)