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

#include <ored/portfolio/genericbarrieroption.hpp>

+ Inheritance diagram for GenericBarrierOption:
+ Collaboration diagram for GenericBarrierOption:

Public Member Functions

 GenericBarrierOption (const std::string &tradeType="GenericBarrierOption")
 
 GenericBarrierOption (std::vector< QuantLib::ext::shared_ptr< Underlying > > underlyings, const OptionData &optionData, const std::vector< BarrierData > &barriers, const ScheduleData &barrierMonitoringDates, const std::vector< BarrierData > &transatlanticBarrier, const std::string &payCurrency, const std::string &settlementDate, const std::string &quantity, const std::string &strike, const std::string &amount, const std::string &kikoType)
 
 GenericBarrierOption (QuantLib::ext::shared_ptr< Underlying > &underlying, const OptionData &optionData, const std::vector< BarrierData > &barriers, const ScheduleData &barrierMonitoringDates, const BarrierData &transatlanticBarrier, const std::string &payCurrency, const std::string &settlementDate, const std::string &quantity, const std::string &strike, const std::string &amount, const std::string &kikoType)
 
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::vector< QuantLib::ext::shared_ptr< ore::data::Underlying > > underlyings_
 
OptionData optionData_
 
std::vector< BarrierDatabarriers_
 
ScheduleData barrierMonitoringDates_
 
std::vector< BarrierDatatransatlanticBarrier_
 
std::string barrierMonitoringStartDate_
 
std::string barrierMonitoringEndDate_
 
std::string payCurrency_
 
std::string settlementDate_
 
std::string quantity_
 
std::string strike_
 
std::string amount_
 
std::string kikoType_
 
std::string settlementLag_
 
std::string settlementCalendar_
 
std::string settlementConvention_
 
std::set< std::string > names () const
 
void initIndices ()
 
QuantLib::Calendar getUnderlyingCalendar (const QuantLib::ext::shared_ptr< EngineFactory > &factory) const
 

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 36 of file genericbarrieroption.hpp.

Constructor & Destructor Documentation

◆ GenericBarrierOption() [1/3]

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

Definition at line 38 of file genericbarrieroption.hpp.

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

◆ GenericBarrierOption() [2/3]

GenericBarrierOption ( std::vector< QuantLib::ext::shared_ptr< Underlying > >  underlyings,
const OptionData optionData,
const std::vector< BarrierData > &  barriers,
const ScheduleData barrierMonitoringDates,
const std::vector< BarrierData > &  transatlanticBarrier,
const std::string &  payCurrency,
const std::string &  settlementDate,
const std::string &  quantity,
const std::string &  strike,
const std::string &  amount,
const std::string &  kikoType 
)

Definition at line 39 of file genericbarrieroption.hpp.

44 : underlyings_(underlyings), optionData_(optionData), barriers_(barriers),
45 barrierMonitoringDates_(barrierMonitoringDates), transatlanticBarrier_(transatlanticBarrier),
46 payCurrency_(payCurrency), settlementDate_(settlementDate), quantity_(quantity), strike_(strike),
47 amount_(amount), kikoType_(kikoType) {
49 }
std::vector< BarrierData > transatlanticBarrier_
std::vector< QuantLib::ext::shared_ptr< ore::data::Underlying > > underlyings_
std::vector< BarrierData > barriers_
+ Here is the call graph for this function:

◆ GenericBarrierOption() [3/3]

GenericBarrierOption ( QuantLib::ext::shared_ptr< Underlying > &  underlying,
const OptionData optionData,
const std::vector< BarrierData > &  barriers,
const ScheduleData barrierMonitoringDates,
const BarrierData transatlanticBarrier,
const std::string &  payCurrency,
const std::string &  settlementDate,
const std::string &  quantity,
const std::string &  strike,
const std::string &  amount,
const std::string &  kikoType 
)

Definition at line 51 of file genericbarrieroption.hpp.

56 : optionData_(optionData), barriers_(barriers),
57 barrierMonitoringDates_(barrierMonitoringDates),
58 payCurrency_(payCurrency), settlementDate_(settlementDate), quantity_(quantity), strike_(strike),
59 amount_(amount), kikoType_(kikoType) {
60 underlyings_.push_back(underlying);
61 transatlanticBarrier_.push_back(transatlanticBarrier);
63 }
+ 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.

Implements Trade.

Definition at line 272 of file genericbarrieroption.cpp.

272 {
273
274 // set script parameters
275
276 clear();
277 initIndices();
278
279 if (underlyings_.size() > 1)
280 QL_REQUIRE(optionData_.payoffType() == "CashOrNothing",
281 "Only CashOrNothing payoff allowed for mulitple underlyings");
282
283 std::string payoffType;
284 if (optionData_.payoffType() == "Vanilla" || optionData_.payoffType() == "AssetOrNothing")
285 payoffType = "0";
286 else if (optionData_.payoffType() == "CashOrNothing")
287 payoffType = "1";
288 else {
289 QL_FAIL("PayoffTpye (" << optionData_.payoffType() << ") must be Vanilla or CashOrNothing");
290 }
291 numbers_.emplace_back("Number", "PayoffType", payoffType);
292
293 QL_REQUIRE(optionData_.payoffType() != "Vanilla" || (!quantity_.empty() && !strike_.empty() && amount_.empty()),
294 "Need Quantity, Strike, no Amount for PayoffType = Vanilla");
295 QL_REQUIRE(optionData_.payoffType() != "AssetOrNothing" ||
296 (!quantity_.empty() && strike_.empty() && amount_.empty()),
297 "Need Quantity, no Strike, no Amount for PayoffType = AssetOrNothing");
298 QL_REQUIRE(optionData_.payoffType() != "CashOrNothing" ||
299 (quantity_.empty() && strike_.empty() && !amount_.empty()),
300 "Need no Quantity, no Strike, Amount for PayoffType = CashOrNothing");
301
302 std::vector<std::string> transatlanticBarrierType(underlyings_.size(), "0");
303 std::vector<std::string> transatlanticBarrierLevel(underlyings_.size(), "0");
304 std::string transatlanticBarrierRebate = "0.0";
305 std::string transatlanticBarrierRebateCurrency = payCurrency_;
306 if (!transatlanticBarrier_[0].type().empty()) {
307 transatlanticBarrierType.clear();
308 for (auto const& n : transatlanticBarrier_) {
309 if (n.type() == "DownAndIn")
310 transatlanticBarrierType.push_back("1");
311 else if (n.type() == "UpAndIn")
312 transatlanticBarrierType.push_back("2");
313 else if (n.type() == "DownAndOut")
314 transatlanticBarrierType.push_back("3");
315 else if (n.type() == "UpAndOut")
316 transatlanticBarrierType.push_back("4");
317 else {
318 QL_FAIL("Transatlantic BarrierType (" << n.type()
319 << ") must be DownAndIn, UpAndIn, DownAndOut, UpAndOut");
320 }
321 }
322 QL_REQUIRE(transatlanticBarrierType.size() == 1 || transatlanticBarrierType.size() == underlyings_.size(),
323 "Transatlantic Barrier must have only 1 Barrier block or 1 block for each underlyings, got "
324 << transatlanticBarrierType.size());
325 if (transatlanticBarrierType.size() == 1 && underlyings_.size() > 1) {
326 transatlanticBarrierType.assign(underlyings_.size(), transatlanticBarrierType[0]);
327 }
328 transatlanticBarrierLevel.clear();
329 if (transatlanticBarrier_.size() == 1) {
330 QL_REQUIRE(transatlanticBarrier_[0].levels().size() == underlyings_.size(),
331 "Transatlantic Barrier must have exactly 1 level for each underlying, got "
332 << transatlanticBarrier_[0].levels().size());
333 for (const auto& l : transatlanticBarrier_[0].levels())
334 transatlanticBarrierLevel.push_back(boost::lexical_cast<std::string>(l.value()));
335 } else {
336 QL_REQUIRE(transatlanticBarrierType.size() == underlyings_.size(),
337 "Transatlantic Barrier must have exactly 1 level for each underlying, got "
338 << transatlanticBarrier_.size());
339 for (auto const& n : transatlanticBarrier_) {
340 QL_REQUIRE(n.levels().size() == 1, "Number of level in each barrier block in transatlantic barriers "
341 "must be exactly 1 if more than 1 barrier blocks are provided, got "
342 << transatlanticBarrier_.size());
343 transatlanticBarrierLevel.push_back(boost::lexical_cast<std::string>(n.levels()[0].value()));
344 }
345 }
346 if (transatlanticBarrier_.size() > 1) {
347 for (Size i = 1; i < transatlanticBarrier_.size(); i++) {
348 QL_REQUIRE(transatlanticBarrier_[i].rebateCurrency().empty() ||
349 transatlanticBarrier_[i].rebateCurrency() == transatlanticBarrier_[0].rebateCurrency(),
350 "Rebate currency for transatlantic barriers must be identical or only given in the first "
351 "transatlantic barrier.");
352 }
353 }
354 transatlanticBarrierRebate = boost::lexical_cast<std::string>(transatlanticBarrier_[0].rebate());
355 if (!transatlanticBarrier_[0].rebateCurrency().empty())
356 transatlanticBarrierRebateCurrency = transatlanticBarrier_[0].rebateCurrency();
357 }
358 numbers_.emplace_back("Number", "TransatlanticBarrierType", transatlanticBarrierType);
359 numbers_.emplace_back("Number", "TransatlanticBarrierLevel", transatlanticBarrierLevel);
360 numbers_.emplace_back("Number", "TransatlanticBarrierRebate", transatlanticBarrierRebate);
361 currencies_.emplace_back("Currency", "TransatlanticBarrierRebateCurrency", transatlanticBarrierRebateCurrency);
362
363 auto positionType = parsePositionType(optionData_.longShort());
364 numbers_.emplace_back("Number", "LongShort", positionType == Position::Long ? "1" : "-1");
365
366 if (optionData_.callPut().empty()) {
367 QL_REQUIRE(optionData_.payoffType() == "CashOrNothing" || optionData_.payoffType() == "AssetOrNothing",
368 "Payoff type must be vanilla if option type is not givien.");
369 numbers_.emplace_back("Number", "PutCall", "1.0");
370 } else {
371 numbers_.emplace_back("Number", "PutCall",
372 parseOptionType(optionData_.callPut()) == Option::Call ? "1.0" : "-1.0");
373 }
374 numbers_.emplace_back("Number", "Quantity", quantity_.empty() ? "0.0" : quantity_);
375 if (!strike_.empty())
376 numbers_.emplace_back("Number", "Strike", strike_);
377 numbers_.emplace_back("Number", "Amount", amount_.empty() ? "0.0" : amount_);
378 currencies_.emplace_back("Currency", "PayCurrency", payCurrency_);
379
380 QL_REQUIRE(optionData_.exerciseDates().size() == 1,
381 "OptionData must contain exactly one ExerciseDate, got " << optionData_.exerciseDates().size());
382 events_.emplace_back("ExpiryDate", optionData_.exerciseDates().front());
383
384 if (!settlementDate_.empty()) {
385 QL_REQUIRE(
386 settlementLag_.empty() && settlementCalendar_.empty() && settlementConvention_.empty(),
387 "If SettlementDate is given, no SettlementLag, SettlementCalendar or SettlementConvention must be given.");
388 events_.emplace_back("SettlementDate", settlementDate_);
389 } else {
390 Date ref = parseDate(optionData_.exerciseDates().front());
391 Period p = settlementLag_.empty() ? 0 * Days : parsePeriod(settlementLag_);
392 Calendar cal =
394 BusinessDayConvention conv =
396 events_.emplace_back("SettlementDate", ore::data::to_string(cal.advance(ref, p, conv)));
397 }
398
400 QL_REQUIRE(barrierMonitoringStartDate_.empty() && barrierMonitoringEndDate_.empty(),
401 "If ScheduleData is given, no StartDate or EndDate must be given");
402 events_.emplace_back("BarrierMonitoringDates", barrierMonitoringDates_);
403 } else {
404 /* build a daily schedule from the given start / end dates and deriving the calendar from
405 the underlying */
406 QL_REQUIRE(!barrierMonitoringStartDate_.empty() && !barrierMonitoringEndDate_.empty(),
407 "If no ScheduleData is given, StartDate and EndDate must be given");
408 events_.emplace_back("BarrierMonitoringDates",
409 ScheduleData(ScheduleRules(barrierMonitoringStartDate_, barrierMonitoringEndDate_, "1D",
410 getUnderlyingCalendar(factory).name(), "F", "F", "Forward")));
411 }
412
413 std::vector<std::string> barrierTypes, barrierLevels, barrierRebates, barrierRebateCurrencies,
414 barrierRebatePayTimes;
415 bool hasKi = false, hasKo = false;
416 for (auto const& b : barriers_) {
417 std::string barrierType;
418 if (b.type() == "DownAndIn") {
419 barrierType = "1";
420 hasKi = true;
421 } else if (b.type() == "UpAndIn") {
422 barrierType = "2";
423 hasKi = true;
424 } else if (b.type() == "DownAndOut") {
425 barrierType = "3";
426 hasKo = true;
427 } else if (b.type() == "UpAndOut") {
428 barrierType = "4";
429 hasKo = true;
430 } else {
431 QL_FAIL("BarrierType (" << b.type() << ") must be DownAndIn, UpAndIn, DownAndOut, UpAndOut");
432 }
433 barrierTypes.push_back(barrierType);
434 QL_REQUIRE(b.levels().size() == underlyings_.size(), "Barrier must have exactly number of levels as underlyings, got " << b.levels().size());
435 for (const auto& l : b.levels())
436 barrierLevels.push_back(boost::lexical_cast<std::string>(l.value()));
437 barrierRebates.push_back(boost::lexical_cast<std::string>(b.rebate()));
438 barrierRebateCurrencies.push_back(b.rebateCurrency().empty() ? payCurrency_ : b.rebateCurrency());
439 std::string rebatePayTime;
440 if (b.rebatePayTime() == "atHit")
441 rebatePayTime = "0";
442 else if (b.rebatePayTime() == "atExpiry" || b.rebatePayTime().empty())
443 rebatePayTime = "1";
444 else {
445 QL_FAIL("RebatePayTime (" << b.rebatePayTime() << ") must be atHit, atExpiry");
446 }
447 barrierRebatePayTimes.push_back(rebatePayTime);
448 }
449
450 // if there is at least one ki barrier, all rebates must be identical + atExpiry
451 // and are set via BarrierRebate, BarrierRebateCurrency
452
453 std::string barrierRebate = "0.0", barrierRebateCurrency = payCurrency_;
454 if (hasKi) {
455 for (Size i = 1; i < barrierTypes.size(); ++i) {
456 QL_REQUIRE(close_enough(parseReal(barrierRebates[i]), parseReal(barrierRebates[0])) &&
457 barrierRebateCurrencies[i] == barrierRebateCurrencies[0],
458 "If Knock-In barrier is present, all rebates must be identical, found "
459 << barrierRebates[0] << " " << barrierRebateCurrencies[0] << " and " << barrierRebates[i]
460 << " " << barrierRebateCurrencies[i]);
461 }
462 for (Size i = 0; i < barrierTypes.size(); ++i) {
463 QL_REQUIRE(barrierRebatePayTimes[i] == "1",
464 "If Knock-In barrier is present, all rebate pay times must be atExpiry");
465 }
466 barrierRebate = barrierRebates[0];
467 barrierRebateCurrency = barrierRebateCurrencies[0];
468 for (Size i = 0; i < barrierTypes.size(); ++i) {
469 barrierRebates[i] = "0.0";
470 barrierRebateCurrencies[i] = payCurrency_;
471 }
472 }
473
474 numbers_.emplace_back("Number", "BarrierTypes", barrierTypes);
475 numbers_.emplace_back("Number", "BarrierLevels", barrierLevels);
476 numbers_.emplace_back("Number", "BarrierRebates", barrierRebates);
477 currencies_.emplace_back("Currency", "BarrierRebateCurrencies", barrierRebateCurrencies);
478 numbers_.emplace_back("Number", "BarrierRebatePayTimes", barrierRebatePayTimes);
479 numbers_.emplace_back("Number", "BarrierRebate", barrierRebate);
480 currencies_.emplace_back("Currency", "BarrierRebateCurrency", barrierRebateCurrency);
481
482 std::string kikoType;
483 if (kikoType_ == "KoAlways" || kikoType_.empty())
484 kikoType = "1";
485 else if (kikoType_ == "KoBeforeKi")
486 kikoType = "2";
487 else if (kikoType_ == "KoAfterKi")
488 kikoType = "3";
489 else {
490 QL_FAIL("KikoType (" << kikoType_ << ") must be KoAlways, KoBeforeKi, KoAfterKi");
491 }
492 numbers_.emplace_back("Number", "KikoType", kikoType);
493
494 QL_REQUIRE((hasKi && hasKo) || kikoType == "1",
495 "KikoType (" << kikoType_ << ") must be KoAlways if there are only Ko or only Ki barriers");
496 QL_REQUIRE(!(hasKi && hasKo) || !kikoType_.empty(),
497 "KikoType must be given (KoAlways, KoBeforeKi, KoAfterKi) if both Ko and Ki barriers are present");
498
499 // set product tag
500
501 productTag_ = (underlyings_.size() < 2) ? "SingleAssetOptionBwd({AssetClass})"
502 : "MultiAssetOption({AssetClass})";
503
504 // set script
505
506 script_[""] = ScriptedTradeScriptData(
507 mcscript, "value",
508 {{"currentNotional", "currentNotional"},
509 {"notionalCurrency", "PayCurrency"},
510 {"Active", "Active"},
511 {"TransatlanticActive", "TransatlanticActive"}},
512 {}, {}, {ScriptedTradeScriptData::CalibrationData("Underlyings", {"Strike", "BarrierLevels"})});
513 script_["FD"] = ScriptedTradeScriptData(
514 fdscript, "value", {{"currentNotional", "currentNotional"}, {"notionalCurrency", "PayCurrency"}}, {}, {},
515 {ScriptedTradeScriptData::CalibrationData("Underlyings", {"Strike", "BarrierLevels"})});
516
517 // build trade
518
519 ScriptedTrade::build(factory, optionData_.premiumData(), positionType == QuantLib::Position::Long ? -1.0 : 1.0);
520}
QuantLib::Calendar getUnderlyingCalendar(const QuantLib::ext::shared_ptr< EngineFactory > &factory) const
const string & callPut() const
Definition: optiondata.hpp:71
const string & payoffType() const
Definition: optiondata.hpp:72
const string & longShort() const
Definition: optiondata.hpp:70
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
bool hasData() const
Check if has any dates/rules/derived schedules.
Definition: schedule.hpp:223
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
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Definition: parsers.cpp:173
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Definition: parsers.cpp:481
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
Size size(const ValueType &v)
Definition: value.cpp:145
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
string name
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 555 of file genericbarrieroption.cpp.

555 {
556 Trade::fromXML(node);
557 XMLNode* dataNode = XMLUtils::getChildNode(node, tradeType() + "Data");
558 QL_REQUIRE(dataNode, tradeType() + "Data node not found");
559
560 if (XMLNode* underlyingsNode = XMLUtils::getChildNode(dataNode, "Underlyings")) {
561 QL_REQUIRE(underlyingsNode, "No Underlyings node");
562 auto underlyings = XMLUtils::getChildrenNodes(underlyingsNode, "Underlying");
563 for (auto const& n : underlyings) {
564 UnderlyingBuilder underlyingBuilder;
565 underlyingBuilder.fromXML(n);
566 underlyings_.push_back(underlyingBuilder.underlying());
567 }
568 } else {
569 XMLNode* tmp = XMLUtils::getChildNode(dataNode, "Underlying");
570 if (!tmp)
571 tmp = XMLUtils::getChildNode(dataNode, "Name");
572 UnderlyingBuilder underlyingBuilder;
573 underlyingBuilder.fromXML(tmp);
574 underlyings_.push_back(underlyingBuilder.underlying());
575 }
576
577 optionData_.fromXML(XMLUtils::getChildNode(dataNode, "OptionData"));
578
579 auto barriersNode = XMLUtils::getChildNode(dataNode, "Barriers");
580 QL_REQUIRE(barriersNode, "No Barriers node found");
581 if (auto sd = XMLUtils::getChildNode(barriersNode, "ScheduleData")) {
583 }
584 barrierMonitoringStartDate_ = XMLUtils::getChildValue(barriersNode, "StartDate", false);
585 barrierMonitoringEndDate_ = XMLUtils::getChildValue(barriersNode, "EndDate", false);
586 kikoType_ = XMLUtils::getChildValue(barriersNode, "KikoType", false, "KoAlways");
587 auto barriers = XMLUtils::getChildrenNodes(barriersNode, "BarrierData");
588 for (auto const& n : barriers) {
589 barriers_.push_back(BarrierData());
590 barriers_.back().fromXML(n);
591 }
592
593 auto transatlanticBarrierNode = XMLUtils::getChildNode(dataNode, "TransatlanticBarrier");
594 if (transatlanticBarrierNode) {
595 auto b = XMLUtils::getChildrenNodes(transatlanticBarrierNode, "BarrierData");
596 for (auto const& n : b) {
597 transatlanticBarrier_.push_back(BarrierData());
598 transatlanticBarrier_.back().fromXML(n);
599 }
600 }
601
602 payCurrency_ = XMLUtils::getChildValue(dataNode, "PayCurrency", true);
603 settlementDate_ = XMLUtils::getChildValue(dataNode, "SettlementDate", false);
604 settlementLag_ = XMLUtils::getChildValue(dataNode, "SettlementLag", false);
605 settlementCalendar_ = XMLUtils::getChildValue(dataNode, "SettlementCalendar", false);
606 settlementConvention_ = XMLUtils::getChildValue(dataNode, "SettlementConvention", false);
607 quantity_ = XMLUtils::getChildValue(dataNode, "Quantity", false);
608 strike_ = XMLUtils::getChildValue(dataNode, "Strike", false);
609 amount_ = XMLUtils::getChildValue(dataNode, "Amount", false);
610
611 initIndices();
612}
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
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 Trade.

Definition at line 614 of file genericbarrieroption.cpp.

614 {
615 XMLNode* node = Trade::toXML(doc);
616 XMLNode* dataNode = doc.allocNode(tradeType() + "Data");
617 XMLUtils::appendNode(node, dataNode);
618
619
620 XMLNode* underlyingsNode = doc.allocNode("Underlyings");
621 for (auto& n : underlyings_) {
622 XMLUtils::appendNode(underlyingsNode, n->toXML(doc));
623 }
624 XMLUtils::appendNode(dataNode, underlyingsNode);
625 XMLUtils::appendNode(dataNode, optionData_.toXML(doc));
626
627 XMLNode* barriers = doc.allocNode("Barriers");
630 if (!barrierMonitoringStartDate_.empty())
631 XMLUtils::addChild(doc, barriers, "StartDate", barrierMonitoringStartDate_);
632 if (!barrierMonitoringEndDate_.empty())
633 XMLUtils::addChild(doc, barriers, "EndDate", barrierMonitoringEndDate_);
634 for (auto& n : barriers_) {
635 XMLUtils::appendNode(barriers, n.toXML(doc));
636 }
637 if (!kikoType_.empty())
638 XMLUtils::addChild(doc, barriers, "KikoType", kikoType_);
639 XMLUtils::appendNode(dataNode, barriers);
640
641 if (!transatlanticBarrier_[0].type().empty()) {
642 XMLNode* transatlanticBarrierNode = doc.allocNode("TransatlanticBarrier");
643 for (auto& n : transatlanticBarrier_) {
644 XMLUtils::appendNode(transatlanticBarrierNode, n.toXML(doc));
645 }
646 XMLUtils::appendNode(dataNode, transatlanticBarrierNode);
647 }
648
649 XMLUtils::addChild(doc, dataNode, "PayCurrency", payCurrency_);
650 if (!settlementDate_.empty())
651 XMLUtils::addChild(doc, dataNode, "SettlementDate", settlementDate_);
652 if (!settlementLag_.empty())
653 XMLUtils::addChild(doc, dataNode, "SettlementLag", settlementLag_);
654 if (!settlementCalendar_.empty())
655 XMLUtils::addChild(doc, dataNode, "SettlementCalendar", settlementCalendar_);
656 if (!settlementConvention_.empty())
657 XMLUtils::addChild(doc, dataNode, "SettlementConvention", settlementConvention_);
658
659 if (!quantity_.empty())
660 XMLUtils::addChild(doc, dataNode, "Quantity", quantity_);
661 if (!strike_.empty())
662 XMLUtils::addChild(doc, dataNode, "Strike", strike_);
663 if (!amount_.empty())
664 XMLUtils::addChild(doc, dataNode, "Amount", amount_);
665
666 return node;
667}
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 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:

◆ names()

std::set< std::string > names ( ) const

Definition at line 70 of file genericbarrieroption.hpp.

70 {
71 std::set<std::string> names;
72 for (const auto& u : underlyings_)
73 names.insert(u->name());
74 return names;
75 }
std::set< std::string > names() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initIndices()

void initIndices ( )
private

Definition at line 522 of file genericbarrieroption.cpp.

522 {
523 std::vector<std::string> underlyings;
524 for (auto const& u : underlyings_)
525 underlyings.push_back(scriptedIndexName(u));
526
527 indices_.emplace_back("Index", "Underlyings", underlyings);
528}
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:

◆ getUnderlyingCalendar()

QuantLib::Calendar getUnderlyingCalendar ( const QuantLib::ext::shared_ptr< EngineFactory > &  factory) const
private

Definition at line 530 of file genericbarrieroption.cpp.

530 {
531 Calendar calendar = NullCalendar();
532 QL_REQUIRE(underlyings_.size() > 0, "No underlyings provided.");
533 IndexInfo ind(scriptedIndexName(underlyings_.front()));
534 if (ind.isFx()) {
535 /* just take the default calendars for the two currencies, this can be improved once we have
536 full fx indices available in the t0 market (TODO) */
537 calendar = parseCalendar(ind.fx()->sourceCurrency().code() + "," + ind.fx()->targetCurrency().code());
538 } else if (ind.isEq()) {
539 /* get the equity calendar from the market */
540 calendar = factory->market()
541 ->equityCurve(ind.eq()->name(), factory->configuration(MarketContext::pricing))
542 ->fixingCalendar();
543 } else if (ind.isComm()) {
544 /* again, just take the default calendar for the comm currency until we have the actual calendar
545 available via the market interface */
546 calendar =
547 parseCalendar(factory->market()
548 ->commodityPriceCurve(ind.commName(), factory->configuration(MarketContext::pricing))
549 ->currency()
550 .code());
551 }
552 return calendar;
553}
Calendar calendar
Definition: utilities.cpp:441
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ underlyings_

std::vector<QuantLib::ext::shared_ptr<ore::data::Underlying> > underlyings_
private

Definition at line 81 of file genericbarrieroption.hpp.

◆ optionData_

OptionData optionData_
private

Definition at line 82 of file genericbarrieroption.hpp.

◆ barriers_

std::vector<BarrierData> barriers_
private

Definition at line 83 of file genericbarrieroption.hpp.

◆ barrierMonitoringDates_

ScheduleData barrierMonitoringDates_
private

Definition at line 84 of file genericbarrieroption.hpp.

◆ transatlanticBarrier_

std::vector<BarrierData> transatlanticBarrier_
private

Definition at line 85 of file genericbarrieroption.hpp.

◆ barrierMonitoringStartDate_

std::string barrierMonitoringStartDate_
private

Definition at line 86 of file genericbarrieroption.hpp.

◆ barrierMonitoringEndDate_

std::string barrierMonitoringEndDate_
private

Definition at line 86 of file genericbarrieroption.hpp.

◆ payCurrency_

std::string payCurrency_
private

Definition at line 87 of file genericbarrieroption.hpp.

◆ settlementDate_

std::string settlementDate_
private

Definition at line 87 of file genericbarrieroption.hpp.

◆ quantity_

std::string quantity_
private

Definition at line 87 of file genericbarrieroption.hpp.

◆ strike_

std::string strike_
private

Definition at line 87 of file genericbarrieroption.hpp.

◆ amount_

std::string amount_
private

Definition at line 87 of file genericbarrieroption.hpp.

◆ kikoType_

std::string kikoType_
private

Definition at line 87 of file genericbarrieroption.hpp.

◆ settlementLag_

std::string settlementLag_
private

Definition at line 88 of file genericbarrieroption.hpp.

◆ settlementCalendar_

std::string settlementCalendar_
private

Definition at line 88 of file genericbarrieroption.hpp.

◆ settlementConvention_

std::string settlementConvention_
private

Definition at line 88 of file genericbarrieroption.hpp.