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

#include <ored/portfolio/tarf.hpp>

+ Inheritance diagram for TaRF:
+ Collaboration diagram for TaRF:

Public Member Functions

 TaRF (const std::string &tradeType="TaRF")
 
 TaRF (const std::string &currency, const std::string &fixingAmount, const std::string &targetAmount, const std::string &targetPoints, const std::vector< std::string > &strikes, const std::vector< std::string > &strikeDates, const QuantLib::ext::shared_ptr< Underlying > &underlying, const ScheduleData &fixingDates, const std::string &settlementLag, const std::string &settlementCalendar, const std::string &settlementConvention, OptionData &optionData, const std::vector< std::vector< RangeBound > > &rangeBoundSet, const std::vector< std::string > &rangeBoundSetDates, const std::vector< BarrierData > &barriers)
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
- Public Member Functions inherited from ScriptedTrade
 ScriptedTrade (const std::string &tradeType="ScriptedTrade", const Envelope &env=Envelope())
 
 ScriptedTrade (const Envelope &env, const std::vector< ScriptedTradeEventData > &events, const std::vector< ScriptedTradeValueTypeData > &numbers, const std::vector< ScriptedTradeValueTypeData > &indices, const std::vector< ScriptedTradeValueTypeData > &currencies, const std::vector< ScriptedTradeValueTypeData > &daycounters, const std::map< std::string, ScriptedTradeScriptData > &script, const std::string &productTag, const std::string &tradeType="ScriptedTrade")
 
 ScriptedTrade (const Envelope &env, const std::vector< ScriptedTradeEventData > &events, const std::vector< ScriptedTradeValueTypeData > &numbers, const std::vector< ScriptedTradeValueTypeData > &indices, const std::vector< ScriptedTradeValueTypeData > &currencies, const std::vector< ScriptedTradeValueTypeData > &daycounters, const std::string &scriptName, const std::string &tradeType="ScriptedTrade")
 
void clear ()
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
std::string notionalCurrency () const override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const PremiumData &premiumData, const Real premiumMultiplier)
 
std::map< ore::data::AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 
virtual void setIsdaTaxonomyFields ()
 
const std::vector< ScriptedTradeEventData > & events () const
 
const std::vector< ScriptedTradeValueTypeData > & numbers () const
 
const std::vector< ScriptedTradeValueTypeData > & indices () const
 
const std::vector< ScriptedTradeValueTypeData > & currencies () const
 
const std::vector< ScriptedTradeValueTypeData > & daycounters () const
 
const std::map< std::string, ScriptedTradeScriptData > & script () const
 
const std::string & productTag () const
 
const std::string & scriptName () const
 
const std::string & simmProductClass () const
 
const std::string & scheduleProductClass () const
 
const ScriptedTradeScriptDatascript (const std::string &purpose, const bool fallBackOnEmptyPurpose=true) const
 
- Public Member Functions inherited from Trade
 Trade ()
 Default constructor. More...
 
 Trade (const string &tradeType, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Base class constructor. More...
 
virtual ~Trade ()
 Default destructor. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &)=0
 
virtual std::map< std::string, RequiredFixings::FixingDatesfixings (const QuantLib::Date &settlementDate=QuantLib::Date()) const
 
const RequiredFixingsrequiredFixings () const
 
virtual std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const
 
void reset ()
 Reset trade, clear all base class data. This does not reset accumulated timings for this trade. More...
 
void resetPricingStats (const std::size_t numberOfPricings=0, const boost::timer::nanosecond_type cumulativePricingTime=0)
 Reset accumulated timings to given values. More...
 
string & id ()
 Set the trade id. More...
 
void setEnvelope (const Envelope &envelope)
 Set the envelope with counterparty and portfolio info. More...
 
void setAdditionalData (const std::map< std::string, boost::any > &additionalData)
 
TradeActionstradeActions ()
 Set the trade actions. More...
 
const string & id () const
 
const string & tradeType () const
 
const Envelopeenvelope () const
 
const set< string > & portfolioIds () const
 
const TradeActionstradeActions () const
 
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument () const
 
const std::vector< QuantLib::Leg > & legs () const
 
const std::vector< string > & legCurrencies () const
 
const std::vector< bool > & legPayers () const
 
const string & npvCurrency () const
 
const Date & maturity () const
 
virtual bool isExpired (const Date &d)
 
const string & issuer () const
 
template<typename T >
additionalDatum (const std::string &tag) const
 returns any additional datum. More...
 
virtual const std::map< std::string, boost::any > & additionalData () const
 returns all additional data returned by the trade once built More...
 
const std::string & sensitivityTemplate () const
 
void validate () const
 Utility to validate that everything that needs to be set in this base class is actually set. More...
 
virtual bool hasCashflows () const
 
boost::timer::nanosecond_type getCumulativePricingTime () const
 Get cumulative timing spent on pricing. More...
 
std::size_t getNumberOfPricings () const
 Get number of pricings. More...
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Inspectors

std::string currency_
 
std::string fixingAmount_
 
std::string targetAmount_
 
std::string targetPoints_
 
std::vector< std::string > strikes_
 
std::vector< std::string > strikeDates_
 
QuantLib::ext::shared_ptr< Underlyingunderlying_
 
ScheduleData fixingDates_
 
std::string settlementLag_
 
std::string settlementCalendar_
 
std::string settlementConvention_
 
OptionData optionData_
 
std::vector< std::vector< RangeBound > > rangeBoundSet_
 
std::vector< std::string > rangeBoundSetDates_
 
std::vector< BarrierDatabarriers_
 
const std::string & name () const
 
void initIndices ()
 

Additional Inherited Members

- Protected Member Functions inherited from Trade
Date addPremiums (std::vector< QuantLib::ext::shared_ptr< Instrument > > &instruments, std::vector< Real > &multipliers, const Real tradeMultiplier, const PremiumData &premiumData, const Real premiumMultiplier, const Currency &tradeCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &factory, const string &configuration)
 
void setLegBasedAdditionalData (const Size legNo, Size resultLegId=Null< Size >()) const
 
void setSensitivityTemplate (const EngineBuilder &builder)
 
void setSensitivityTemplate (const std::string &id)
 
- Protected Attributes inherited from ScriptedTrade
std::vector< ScriptedTradeEventDataevents_
 
std::vector< ScriptedTradeValueTypeDatanumbers_
 
std::vector< ScriptedTradeValueTypeDataindices_
 
std::vector< ScriptedTradeValueTypeDatacurrencies_
 
std::vector< ScriptedTradeValueTypeDatadaycounters_
 
std::map< std::string, ScriptedTradeScriptDatascript_
 
std::string productTag_
 
std::string scriptName_
 
std::string simmProductClass_
 
std::string scheduleProductClass_
 
- Protected Attributes inherited from Trade
string tradeType_
 
QuantLib::ext::shared_ptr< InstrumentWrapperinstrument_
 
std::vector< QuantLib::Leg > legs_
 
std::vector< string > legCurrencies_
 
std::vector< boollegPayers_
 
string npvCurrency_
 
QuantLib::Real notional_
 
string notionalCurrency_
 
Date maturity_
 
string issuer_
 
string sensitivityTemplate_
 
bool sensitivityTemplateSet_ = false
 
std::size_t savedNumberOfPricings_ = 0
 
boost::timer::nanosecond_type savedCumulativePricingTime_ = 0
 
RequiredFixings requiredFixings_
 
std::map< std::string, boost::any > additionalData_
 

Detailed Description

Definition at line 37 of file tarf.hpp.

Constructor & Destructor Documentation

◆ TaRF() [1/2]

TaRF ( const std::string &  tradeType = "TaRF")
explicit

Definition at line 39 of file tarf.hpp.

ScriptedTrade(const std::string &tradeType="ScriptedTrade", const Envelope &env=Envelope())
const string & tradeType() const
Definition: trade.hpp:133

◆ TaRF() [2/2]

TaRF ( const std::string &  currency,
const std::string &  fixingAmount,
const std::string &  targetAmount,
const std::string &  targetPoints,
const std::vector< std::string > &  strikes,
const std::vector< std::string > &  strikeDates,
const QuantLib::ext::shared_ptr< Underlying > &  underlying,
const ScheduleData fixingDates,
const std::string &  settlementLag,
const std::string &  settlementCalendar,
const std::string &  settlementConvention,
OptionData optionData,
const std::vector< std::vector< RangeBound > > &  rangeBoundSet,
const std::vector< std::string > &  rangeBoundSetDates,
const std::vector< BarrierData > &  barriers 
)

Definition at line 246 of file tarf.cpp.

253 : currency_(currency), fixingAmount_(fixingAmount), targetAmount_(targetAmount), targetPoints_(targetPoints),
254 strikes_(strikes), underlying_(underlying), fixingDates_(fixingDates), settlementLag_(settlementLag),
255 settlementCalendar_(settlementCalendar), settlementConvention_(settlementConvention), optionData_(optionData),
256 rangeBoundSet_(rangeBoundSet), barriers_(barriers) {
257 QL_REQUIRE(strikes_.size() == strikeDates_.size(), "TaRF: strike size (" << strikes_.size()
258 << ") does not match strikeDates size ("
259 << strikeDates_.size() << ")");
260 QL_REQUIRE(rangeBoundSet_.size() == rangeBoundSetDates_.size(),
261 "TaRF: rangeBoundSet size (" << rangeBoundSet_.size() << ") does not match rangeBoundSetDates size ("
262 << rangeBoundSetDates_.size());
263 QL_REQUIRE(targetAmount_.empty() || targetPoints_.empty(),
264 "TaRF: both ttargetAmount, targetPoints is populated, only one is allowed");
265 initIndices();
266}
std::string settlementConvention_
Definition: tarf.hpp:62
void initIndices()
Definition: tarf.cpp:433
OptionData optionData_
Definition: tarf.hpp:63
std::vector< std::string > strikeDates_
Definition: tarf.hpp:59
std::string currency_
Definition: tarf.hpp:58
std::vector< std::string > strikes_
Definition: tarf.hpp:59
ScheduleData fixingDates_
Definition: tarf.hpp:61
QuantLib::ext::shared_ptr< Underlying > underlying_
Definition: tarf.hpp:60
std::string settlementLag_
Definition: tarf.hpp:62
std::string targetAmount_
Definition: tarf.hpp:58
std::string targetPoints_
Definition: tarf.hpp:58
std::vector< BarrierData > barriers_
Definition: tarf.hpp:66
std::vector< std::string > rangeBoundSetDates_
Definition: tarf.hpp:65
std::vector< std::vector< RangeBound > > rangeBoundSet_
Definition: tarf.hpp:64
std::string fixingAmount_
Definition: tarf.hpp:58
std::string settlementCalendar_
Definition: tarf.hpp:62
+ Here is the call graph for this function:

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< EngineFactory > &  )
overridevirtual

Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.

Reimplemented from ScriptedTrade.

Definition at line 268 of file tarf.cpp.

268 {
269
270 // 1 inits
271
272 clear();
273 initIndices();
274
275 // 2 build rangeBounds and strikes vectors according to fixing date schedule
276
277 std::vector<QuantLib::Date> fixingSchedulePlusInf = makeSchedule(fixingDates_).dates();
278 fixingSchedulePlusInf.push_back(Date::maxDate());
279 std::vector<std::vector<RangeBound>> rangeBoundSet = buildScheduledVectorNormalised<std::vector<RangeBound>>(
280 rangeBoundSet_, rangeBoundSetDates_, fixingSchedulePlusInf, std::vector<RangeBound>());
281 std::vector<std::string> strikes =
282 buildScheduledVectorNormalised<std::string>(strikes_, strikeDates_, fixingSchedulePlusInf, "");
283 Size numberOfRangeBounds = Null<Size>();
284
285 QL_REQUIRE(rangeBoundSet.size() == fixingSchedulePlusInf.size() - 1,
286 "RangeBoundSet has " << rangeBoundSet.size() << " elements for " << (fixingSchedulePlusInf.size() - 1)
287 << " fixing dates.");
288 QL_REQUIRE(strikes.size() == fixingSchedulePlusInf.size() - 1, "Strikes has " << strikes.size() << " elements for "
289 << (fixingSchedulePlusInf.size() - 1)
290 << " fixing dates.");
291
292 // 3 populate range-bound data (per fixing date)
293
294 std::vector<std::string> rangeStrikes, rangeUpperBounds, rangeLowerBounds, rangeLeverages;
295 for (Size i = 0; i < rangeBoundSet.size(); ++i) {
296
297 for (auto const& r : rangeBoundSet[i]) {
298 if (r.strike() != Null<Real>())
299 rangeStrikes.push_back(boost::lexical_cast<std::string>(r.strike()));
300 else if (r.strikeAdjustment() != Null<Real>() && !strikes[i].empty())
301 rangeStrikes.push_back(boost::lexical_cast<std::string>(r.strikeAdjustment() + parseReal(strikes[i])));
302 else if (!strikes[i].empty())
303 rangeStrikes.push_back(boost::lexical_cast<std::string>(parseReal(strikes[i])));
304 else {
305 QL_FAIL("insufficient strike information");
306 }
307 rangeLowerBounds.push_back(
308 boost::lexical_cast<std::string>(r.from() == Null<Real>() ? -QL_MAX_REAL : r.from()));
309 rangeUpperBounds.push_back(boost::lexical_cast<std::string>(r.to() == Null<Real>() ? QL_MAX_REAL : r.to()));
310 rangeLeverages.push_back(
311 boost::lexical_cast<std::string>(r.leverage() == Null<Real>() ? 1.0 : r.leverage()));
312 }
313
314 if (i == 0)
315 numberOfRangeBounds = rangeLowerBounds.size();
316 else {
317 QL_REQUIRE(
318 numberOfRangeBounds * (i + 1) == rangeLowerBounds.size(),
319 "Each RangeBounds subnode (under RangeBoundSets) must contain the same number of RangeBound nodes");
320 }
321 }
322
323 QL_REQUIRE(numberOfRangeBounds != Null<Size>(), "internal error: numberOfRangeBounds not set.");
324
325 // 4 set parameters
326
327 numbers_.emplace_back("Number", "NumberOfRangeBounds", std::to_string(numberOfRangeBounds));
328 numbers_.emplace_back("Number", "RangeStrikes", rangeStrikes);
329 numbers_.emplace_back("Number", "RangeLowerBounds", rangeLowerBounds);
330 numbers_.emplace_back("Number", "RangeUpperBounds", rangeUpperBounds);
331 numbers_.emplace_back("Number", "RangeLeverages", rangeLeverages);
332
333 numbers_.emplace_back("Number", "FixingAmount", fixingAmount_);
334 numbers_.emplace_back("Number", "LongShort",
335 parsePositionType(optionData_.longShort()) == Position::Long ? "1" : "-1");
336
337 currencies_.emplace_back("Currency", "PayCcy", currency_);
338
339 events_.emplace_back("FixingDates", fixingDates_);
340 events_.emplace_back("SettlementDates", "FixingDates", settlementLag_.empty() ? "0D" : settlementLag_,
341 settlementCalendar_.empty() ? "NullCalendar" : settlementCalendar_,
343
344 std::string knockOutProfitAmount = "0", knockOutProfitAmountPoints = "0", knockOutProfitEvents = "0";
345 for (auto const& b : barriers_) {
346 QL_REQUIRE(b.style().empty() || b.style() == "European", "only european barrier style supported");
347 if (b.type() == "CumulatedProfitCap" && !b.levels().empty())
348 knockOutProfitAmount = boost::lexical_cast<std::string>(b.levels().front().value());
349 else if (b.type() == "CumulatedProfitCapPoints" && !b.levels().empty())
350 knockOutProfitAmountPoints = boost::lexical_cast<std::string>(b.levels().front().value());
351 else if (b.type() == "FixingCap" && !b.levels().empty())
352 knockOutProfitEvents = boost::lexical_cast<std::string>(b.levels().front().value());
353 else {
354 QL_FAIL("invalid barrier definition, expected CumulatedProfitCap or FixingCap with exactly one level");
355 }
356 }
357
358 // 4a compute both target amount and points from given trade data, it depends on the variant which we use below
359
360 Real targetAmount = 0.0, targetPoints = 0.0;
361 if (!targetAmount_.empty()) {
362 targetAmount = parseReal(targetAmount_);
363 targetPoints = targetAmount / parseReal(fixingAmount_);
364 } else if (!targetPoints_.empty()) {
365 targetPoints = parseReal(targetPoints_);
366 targetAmount = targetPoints * parseReal(fixingAmount_);
367 }
368
369 // 4b choose the variant and check barrier types, set target amount or points dependent on variant
370
371 std::string scriptToUse, amcScriptToUse;
372 if (knockOutProfitAmountPoints != "0") {
373 scriptToUse = tarf_script_points;
374 amcScriptToUse = tarf_script_points_amc;
375 QL_REQUIRE(
376 knockOutProfitAmount == "0",
377 "CumulatedProfitCapPoints can not be combined with other barrier types CumulatedPorfitCap, FixingCap");
378 numbers_.emplace_back("Number", "TargetPoints", boost::lexical_cast<std::string>(targetPoints));
379 numbers_.emplace_back("Number", "KnockOutProfitAmountPoints", knockOutProfitAmountPoints);
380 } else {
381 scriptToUse = tarf_script_regular;
382 amcScriptToUse = tarf_script_regular_amc;
383 numbers_.emplace_back("Number", "TargetAmount", boost::lexical_cast<std::string>(targetAmount));
384 numbers_.emplace_back("Number", "KnockOutProfitAmount", knockOutProfitAmount);
385 numbers_.emplace_back("Number", "KnockOutProfitEvents", knockOutProfitEvents);
386 }
387
388 // 4c set target type
389
390 std::string targetType;
391 if (optionData_.payoffType() == "TargetTruncated")
392 targetType = "-1";
393 else if (optionData_.payoffType() == "TargetExact")
394 targetType = "0";
395 else if (optionData_.payoffType() == "TargetFull")
396 targetType = "1";
397 else {
398 QL_FAIL("invalid payoffType, expected TargetTruncated, TargetExact, TargetFull");
399 }
400 numbers_.emplace_back("Number", "TargetType", targetType);
401
402 // 5 set product tag
403
404 productTag_ = "SingleAssetOptionCG({AssetClass})";
405
406 // 6 set script
407
408 script_.clear();
409
410 script_[""] = ScriptedTradeScriptData(scriptToUse, "value",
411 {{"currentNotional", "currentNotional"},
412 {"notionalCurrency", "PayCcy"},
413 {"FixingAmount", "FixingAmount"},
414 {"Fixing", "Fixing"},
415 {"Triggered", "Triggered"}},
416 {});
417
418 script_["AMC"] = ScriptedTradeScriptData(
419 amcScriptToUse, "value",
420 {{"currentNotional", "currentNotional"},
421 {"notionalCurrency", "PayCcy"},
422 {"FixingAmount", "FixingAmount"},
423 {"Fixing", "Fixing"},
424 {"Triggered", "Triggered"}},
425 {}, {ScriptedTradeScriptData::NewScheduleData("FixingAndSimDates", "Join", {"_AMC_SimDates", "FixingDates"})},
426 {}, {}, {"Asset"});
427
428 // 7 build trade
429
430 ScriptedTrade::build(factory);
431}
const string & payoffType() const
Definition: optiondata.hpp:72
const string & longShort() const
Definition: optiondata.hpp:70
std::vector< ScriptedTradeEventData > events_
std::vector< ScriptedTradeValueTypeData > currencies_
std::vector< ScriptedTradeValueTypeData > numbers_
std::map< std::string, ScriptedTradeScriptData > script_
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
vector< Real > strikes
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from ScriptedTrade.

Definition at line 435 of file tarf.cpp.

435 {
436 Trade::fromXML(node);
437 XMLNode* dataNode = XMLUtils::getChildNode(node, tradeType() + "Data");
438 QL_REQUIRE(dataNode, tradeType() + "Data node not found");
439 currency_ = XMLUtils::getChildValue(dataNode, "Currency", true);
440 fixingAmount_ = XMLUtils::getChildValue(dataNode, "FixingAmount", true);
441 targetAmount_ = XMLUtils::getChildValue(dataNode, "TargetAmount", false);
442 targetPoints_ = XMLUtils::getChildValue(dataNode, "TargetPoints", false);
443 QL_REQUIRE(targetAmount_.empty() || targetPoints_.empty(),
444 "both TargetAmount and TargetPoints are given, only one of these is allowed at the same time");
445 strikes_ = {XMLUtils::getChildValue(dataNode, "Strike", false)};
446 if (XMLUtils::getChildNode(dataNode, "Strikes")) {
447 QL_REQUIRE(strikes_.front().empty(),
448 "both Strike and Strikes nodes are given, only one of these is allowed at the same time.");
449 strikes_ = XMLUtils::getChildrenValuesWithAttributes(dataNode, "Strikes", "Strike", "startDate", strikeDates_);
450 QL_REQUIRE(!strikes_.empty(), "noch Strike nodes under Strikes given.");
451 }
452 strikeDates_.resize(strikes_.size());
453 XMLNode* tmp = XMLUtils::getChildNode(dataNode, "Underlying");
454 if (!tmp)
455 tmp = XMLUtils::getChildNode(dataNode, "Name");
456 UnderlyingBuilder underlyingBuilder;
457 underlyingBuilder.fromXML(tmp);
458 underlying_ = underlyingBuilder.underlying();
459
460 fixingDates_.fromXML(XMLUtils::getChildNode(dataNode, "ScheduleData"));
461 settlementLag_ = XMLUtils::getChildValue(dataNode, "SettlementLag", false);
462 settlementCalendar_ = XMLUtils::getChildValue(dataNode, "SettlementCalendar", false);
463 settlementConvention_ = XMLUtils::getChildValue(dataNode, "SettlementConvention", false);
464 optionData_.fromXML(XMLUtils::getChildNode(dataNode, "OptionData"));
465 std::vector<XMLNode*> rangeBounds = {XMLUtils::getChildNode(dataNode, "RangeBounds")};
466 if (XMLUtils::getChildNode(dataNode, "RangeBoundSet")) {
467 QL_REQUIRE(rangeBounds.front() == nullptr,
468 "both RangeBounds and RangeBoundSet nodes are given, only one allowed at the same time");
469 rangeBounds = XMLUtils::getChildrenNodesWithAttributes(dataNode, "RangeBoundSet", "RangeBounds", "startDate",
471 QL_REQUIRE(!rangeBounds.empty(), "no RangeBounds subnode under RangeBoundSets given");
472 }
473 QL_REQUIRE(rangeBounds.front() != nullptr, "either RangeBounds or RangeBoundSet nodes required");
474 rangeBoundSetDates_.resize(rangeBounds.size());
475 for (auto const& r : rangeBounds) {
476 rangeBoundSet_.push_back(std::vector<RangeBound>());
477 auto rb = XMLUtils::getChildrenNodes(r, "RangeBound");
478 for (auto const& n : rb) {
479 rangeBoundSet_.back().push_back(RangeBound());
480 rangeBoundSet_.back().back().fromXML(n);
481 }
482 }
483 auto barriersNode = XMLUtils::getChildNode(dataNode, "Barriers");
484 QL_REQUIRE(barriersNode, "No Barriers node");
485 auto barriers = XMLUtils::getChildrenNodes(barriersNode, "BarrierData");
486 for (auto const& n : barriers) {
487 barriers_.push_back(BarrierData());
488 barriers_.back().fromXML(n);
489 }
490 initIndices();
491}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static vector< string > getChildrenValuesWithAttributes(XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
Definition: xmlutils.cpp:563
static vector< XMLNode * > getChildrenNodesWithAttributes(XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
Definition: xmlutils.cpp:437
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from ScriptedTrade.

Definition at line 493 of file tarf.cpp.

493 {
494 XMLNode* node = Trade::toXML(doc);
495 XMLNode* dataNode = doc.allocNode(tradeType() + "Data");
496 XMLUtils::appendNode(node, dataNode);
497 XMLUtils::addChild(doc, dataNode, "Currency", currency_);
498 XMLUtils::addChild(doc, dataNode, "FixingAmount", fixingAmount_);
499 if (!targetAmount_.empty())
500 XMLUtils::addChild(doc, dataNode, "TargetAmount", targetAmount_);
501 if (!targetPoints_.empty())
502 XMLUtils::addChild(doc, dataNode, "TargetPoints", targetPoints_);
503 if (!strikes_.front().empty())
504 XMLUtils::addChildrenWithAttributes(doc, dataNode, "Strikes", "Strike", strikes_, "startDate", strikeDates_);
505 XMLUtils::appendNode(dataNode, underlying_->toXML(doc));
507 if (!settlementLag_.empty())
508 XMLUtils::addChild(doc, dataNode, "SettlementLag", settlementLag_);
509 if (!settlementCalendar_.empty())
510 XMLUtils::addChild(doc, dataNode, "SettlementCalendar", settlementCalendar_);
511 if (!settlementConvention_.empty())
512 XMLUtils::addChild(doc, dataNode, "SettlementConvention", settlementConvention_);
513 XMLUtils::appendNode(dataNode, optionData_.toXML(doc));
514 XMLNode* rangeBoundSet = doc.allocNode("RangeBoundSet");
515 for (Size i = 0; i < rangeBoundSet_.size(); ++i) {
516 XMLNode* rangeBoundsNode = doc.allocNode("RangeBounds");
517 for (auto& n : rangeBoundSet_[i]) {
518 XMLUtils::appendNode(rangeBoundsNode, n.toXML(doc));
519 }
520 if (!rangeBoundSetDates_[i].empty())
521 XMLUtils::addAttribute(doc, rangeBoundsNode, "startDate", rangeBoundSetDates_[i]);
522 XMLUtils::appendNode(rangeBoundSet, rangeBoundsNode);
523 }
524 XMLUtils::appendNode(dataNode, rangeBoundSet);
525 XMLNode* barriers = doc.allocNode("Barriers");
526 for (auto& n : barriers_) {
527 XMLUtils::appendNode(barriers, n.toXML(doc));
528 }
529 XMLUtils::appendNode(dataNode, barriers);
530 return node;
531}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static void addChildrenWithAttributes(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
Definition: xmlutils.cpp:510
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:

◆ name()

const std::string & name ( ) const

Definition at line 53 of file tarf.hpp.

53{ return underlying_->name(); }

◆ initIndices()

void initIndices ( )
private

Definition at line 433 of file tarf.cpp.

433{ indices_.emplace_back("Index", "Underlying", scriptedIndexName(underlying_)); }
std::vector< ScriptedTradeValueTypeData > indices_
QL_DEPRECATED_ENABLE_WARNING std::string scriptedIndexName(const QuantLib::ext::shared_ptr< Underlying > &underlying)
Definition: utilities.cpp:614
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ currency_

std::string currency_
private

Definition at line 58 of file tarf.hpp.

◆ fixingAmount_

std::string fixingAmount_
private

Definition at line 58 of file tarf.hpp.

◆ targetAmount_

std::string targetAmount_
private

Definition at line 58 of file tarf.hpp.

◆ targetPoints_

std::string targetPoints_
private

Definition at line 58 of file tarf.hpp.

◆ strikes_

std::vector<std::string> strikes_
private

Definition at line 59 of file tarf.hpp.

◆ strikeDates_

std::vector<std::string> strikeDates_
private

Definition at line 59 of file tarf.hpp.

◆ underlying_

QuantLib::ext::shared_ptr<Underlying> underlying_
private

Definition at line 60 of file tarf.hpp.

◆ fixingDates_

ScheduleData fixingDates_
private

Definition at line 61 of file tarf.hpp.

◆ settlementLag_

std::string settlementLag_
private

Definition at line 62 of file tarf.hpp.

◆ settlementCalendar_

std::string settlementCalendar_
private

Definition at line 62 of file tarf.hpp.

◆ settlementConvention_

std::string settlementConvention_
private

Definition at line 62 of file tarf.hpp.

◆ optionData_

OptionData optionData_
private

Definition at line 63 of file tarf.hpp.

◆ rangeBoundSet_

std::vector<std::vector<RangeBound> > rangeBoundSet_
private

Definition at line 64 of file tarf.hpp.

◆ rangeBoundSetDates_

std::vector<std::string> rangeBoundSetDates_
private

Definition at line 65 of file tarf.hpp.

◆ barriers_

std::vector<BarrierData> barriers_
private

Definition at line 66 of file tarf.hpp.