3232#include < ql/cashflows/cashflows.hpp>
3333#include < ql/cashflows/fixedratecoupon.hpp>
3434
35+ #include < boost/optional/optional_io.hpp>
3536#include < boost/assign/list_of.hpp>
3637#include < boost/bimap.hpp>
3738#include < boost/optional.hpp>
4041namespace ore {
4142namespace data {
4243
43- void addTRSRequiredFixings (RequiredFixings& fixings, const std::vector<Leg>& returnLegs,
44- const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& ind = nullptr ) {
44+ void addTRSRequiredFixings (RequiredFixings& fixings, const std::vector<Leg>& returnLegs,
45+ const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& ind = nullptr ) {
4546 QL_REQUIRE (returnLegs.size () > 0 , " TrsUnderlyingBuilder: No returnLeg built" );
4647 auto fdg = QuantLib::ext::make_shared<FixingDateGetter>(fixings);
4748 fdg->setAdditionalFxIndex (ind);
@@ -62,7 +63,9 @@ void TRS::ReturnData::fromXML(XMLNode* node) {
6263 paymentCalendar_ = XMLUtils::getChildValue (node, " PaymentCalendar" , false );
6364 paymentDates_ = XMLUtils::getChildrenValues (node, " PaymentDates" , " PaymentDate" , false );
6465 initialPrice_ = Null<Real>();
65- fxConversionAtPeriodEnd_ = XMLUtils::getChildValue (node, " FXConversion" , false , " Start" ) == " End" ;
66+ if (XMLNode* fxcNode = XMLUtils::getChildNode (node, " FXConversion" )) {
67+ fxConversion_ = parseFXConversion (XMLUtils::getNodeValue (fxcNode));
68+ }
6669 if (auto n = XMLUtils::getChildNode (node, " InitialPrice" )) {
6770 initialPrice_ = parseReal (XMLUtils::getNodeValue (n));
6871 }
@@ -101,9 +104,19 @@ XMLNode* TRS::ReturnData::toXML(XMLDocument& doc) const {
101104 XMLUtils::addChild (doc, n, " PayUnderlyingCashFlowsImmediately" , *payUnderlyingCashFlowsImmediately_);
102105 if (!fxTerms_.empty ())
103106 XMLUtils::addChildren (doc, n, " FXTerms" , " FXIndex" , fxTerms_);
107+ if (fxConversion_) {
108+ XMLUtils::addChild (doc, n, " FXConversion" , ore::data::to_string (fxConversion_));
109+ }
104110 return n;
105111}
106112
113+ TRS::FXConversion TRS::ReturnData::parseFXConversion (string fxConv_) {
114+ return fxConv_ == " End" ? FXConversion::End : FXConversion::Start;
115+ }
116+
117+
118+
119+
107120void TRS::FundingData::fromXML (XMLNode* node) {
108121 XMLUtils::checkNode (node, " FundingData" );
109122 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes (node, " LegData" );
@@ -314,6 +327,10 @@ TRS::getFxIndex(const QuantLib::ext::shared_ptr<Market> market, const std::strin
314327 return fx;
315328}
316329
330+ /* TRS::FXConversion TRS::ReturnData::parseFXConversion(string fxConv_) { return (fxConv_ == "Start" ? FXConversion::Start
331+ : FXConversion::End);
332+ }*/
333+
317334void TRS::build (const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) {
318335
319336 DLOG (" TRS::build() called for id = " << id ());
@@ -861,6 +878,17 @@ std::ostream& operator<<(std::ostream& os, const TRS::FundingData::NotionalType
861878 return os;
862879}
863880
881+ std::ostream& operator <<(std::ostream& out, const TRS::FXConversion type) {
882+ switch (type) {
883+ case TRS::FXConversion::Start:
884+ return out << " Start" ;
885+ case TRS::FXConversion::End:
886+ return out << " End" ;
887+ default :
888+ QL_FAIL (" Unrecognized FXConversion type" );
889+ }
890+ }
891+
864892void TRS::populateFromReferenceData (const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceData) const {
865893
866894 if (!portfolioId_.empty () && referenceData != nullptr &&
0 commit comments