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

Serializable FX Digital Option. More...

#include <ored/portfolio/fxdigitaloption.hpp>

+ Inheritance diagram for FxDigitalOption:
+ Collaboration diagram for FxDigitalOption:

Public Member Functions

 FxDigitalOption ()
 Default constructor. More...
 
 FxDigitalOption (Envelope &env, OptionData option, double strike, const string &payoffCurrency, double payoffAmount, const string &foreignCurrency, const string &domesticCurrency)
 Constructor. More...
 
 FxDigitalOption (Envelope &env, OptionData option, double strike, double payoffAmount, const string &foreignCurrency, const string &domesticCurrency)
 Legacy Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
Inspectors
const OptionDataoption () const
 
double strike () const
 
const string & payoffCurrency () const
 
double payoffAmount () const
 
- Public Member Functions inherited from FxSingleAssetDerivative
const std::string & boughtCurrency () const
 
const std::string & soldCurrency () const
 
const std::string & foreignCurrency () const
 
const std::string & domesticCurrency () 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
 
virtual QuantLib::Real notional () const
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
virtual string notionalCurrency () 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...
 

Serialisation

OptionData option_
 
Real strike_
 
string payoffCurrency_
 
Real payoffAmount_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 

Additional Inherited Members

- Protected Member Functions inherited from FxSingleAssetDerivative
 FxSingleAssetDerivative (const std::string &tradeType)
 
 FxSingleAssetDerivative (const std::string &tradeType, ore::data::Envelope &env, const std::string &boughtCurrency, const std::string &soldCurrency)
 
- Protected Member Functions inherited from FxDerivative
 FxDerivative (const std::string &tradeType)
 
 FxDerivative (const std::string &tradeType, ore::data::Envelope &env)
 
- 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 FxSingleAssetDerivative
std::string boughtCurrency_
 
std::string soldCurrency_
 
std::string & foreignCurrency_ = boughtCurrency_
 
std::string & domesticCurrency_ = soldCurrency_
 
- 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

Serializable FX Digital Option.

Definition at line 35 of file fxdigitaloption.hpp.

Constructor & Destructor Documentation

◆ FxDigitalOption() [1/3]

Default constructor.

Definition at line 38 of file fxdigitaloption.hpp.

38: ore::data::Trade("FxDigitalOption"), FxSingleAssetDerivative("") {}
FxSingleAssetDerivative(const std::string &tradeType)
Trade base class.
Definition: trade.hpp:55

◆ FxDigitalOption() [2/3]

FxDigitalOption ( Envelope env,
OptionData  option,
double  strike,
const string &  payoffCurrency,
double  payoffAmount,
const string &  foreignCurrency,
const string &  domesticCurrency 
)

◆ FxDigitalOption() [3/3]

FxDigitalOption ( Envelope env,
OptionData  option,
double  strike,
double  payoffAmount,
const string &  foreignCurrency,
const string &  domesticCurrency 
)

Legacy Constructor.

Definition at line 48 of file fxdigitaloption.hpp.

Member Function Documentation

◆ build()

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

Build QuantLib/QuantExt instrument, link pricing engine.

Implements Trade.

Definition at line 34 of file fxdigitaloption.cpp.

34 {
35
36 // ISDA taxonomy
37 additionalData_["isdaAssetClass"] = string("Foreign Exchange");
38 additionalData_["isdaBaseProduct"] = string("Simple Exotic");
39 additionalData_["isdaSubProduct"] = string("Digital");
40 additionalData_["isdaTransaction"] = string("");
41
42 additionalData_["payoffAmount"] = payoffAmount_;
43 additionalData_["payoffCurrency"] = payoffCurrency_;
44
45 // Only European Vanilla supported for now
46 QL_REQUIRE(option_.style() == "European", "Option Style unknown: " << option_.style());
47 QL_REQUIRE(option_.exerciseDates().size() == 1, "Invalid number of exercise dates");
48 QL_REQUIRE(option_.payoffAtExpiry() == true, "PayoffAtExpiry must be True for FxDigitalOption");
49 QL_REQUIRE(tradeActions().empty(), "TradeActions not supported for FxDigitalOption");
50 QL_REQUIRE(strike_ > 0.0 && strike_ != Null<Real>(), "Invalid strike " << strike_);
51
52 Currency domCcy = parseCurrency(domesticCurrency_);
53 Currency forCcy = parseCurrency(foreignCurrency_);
54
55 // Payoff Type
56 Option::Type type = parseOptionType(option_.callPut());
57
58 // Handle PayoffCurrency, we might have to flip the trade here
59 Real strike = strike_;
60 bool flipResults = false;
61 if (payoffCurrency_ == "") {
62 DLOG("PayoffCurrency defaulting to " << domesticCurrency_ << " for FxDigitalOption " << id());
63 } else if (payoffCurrency_ == foreignCurrency_) {
64 // Invert the trade, switch dom and for and flip Put/Call
65 strike = 1.0 / strike;
66 std::swap(domCcy, forCcy);
67 type = type == Option::Call ? Option::Put : Option::Call;
68 flipResults = true;
69 } else if (payoffCurrency_ != domesticCurrency_) {
70 QL_FAIL("Invalid Payoff currency (" << payoffCurrency_ << ") for FxDigitalOption " << forCcy << domCcy);
71 }
72 DLOG("Setting up FxDigitalOption with strike " << strike << " foreign " << forCcy << " domestic " << domCcy);
73
74 // Set up the CashOrNothing
75 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new CashOrNothingPayoff(type, strike, payoffAmount_));
76
77 npvCurrency_ = domCcy.code(); // don't use domesticCurrency_ as it might be flipped
80
81 // Exercise
82 Date expiryDate = parseDate(option_.exerciseDates().front());
83 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
84 maturity_ = std::max(option_.premiumData().latestPremiumDate(), expiryDate);
85
86 // QL does not have an FXDigitalOption, so we add a vanilla one here and wrap
87 // it in a composite.
88 QuantLib::ext::shared_ptr<Instrument> vanilla = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
89
90 // set pricing engines
91 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeType_);
92 QL_REQUIRE(builder, "No builder found for " << tradeType_);
93 QuantLib::ext::shared_ptr<FxDigitalOptionEngineBuilder> fxOptBuilder =
94 QuantLib::ext::dynamic_pointer_cast<FxDigitalOptionEngineBuilder>(builder);
95 vanilla->setPricingEngine(fxOptBuilder->engine(forCcy, domCcy, flipResults));
96 setSensitivityTemplate(*fxOptBuilder);
97
98 Position::Type positionType = parsePositionType(option_.longShort());
99 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
100 Real mult = bsInd;
101
102 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
103 std::vector<Real> additionalMultipliers;
104 addPremiums(additionalInstruments, additionalMultipliers, mult, option_.premiumData(), -bsInd, domCcy,
105 engineFactory, fxOptBuilder->configuration(MarketContext::pricing));
106
107 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
108 new VanillaInstrument(vanilla, mult, additionalInstruments, additionalMultipliers));
109}
const string & callPut() const
Definition: optiondata.hpp:71
const string & longShort() const
Definition: optiondata.hpp:70
const string & style() const
Definition: optiondata.hpp:74
const bool & payoffAtExpiry() const
Definition: optiondata.hpp:75
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
QuantLib::Date latestPremiumDate() const
Definition: premiumdata.cpp:28
TradeActions & tradeActions()
Set the trade actions.
Definition: trade.hpp:126
string npvCurrency_
Definition: trade.hpp:201
QuantLib::Real notional_
Definition: trade.hpp:202
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)
Definition: trade.cpp:58
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
string tradeType_
Definition: trade.hpp:196
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Definition: parsers.cpp:481
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ option()

const OptionData & option ( ) const

Definition at line 59 of file fxdigitaloption.hpp.

59{ return option_; }

◆ strike()

double strike ( ) const

Definition at line 60 of file fxdigitaloption.hpp.

60{ return strike_; }
+ Here is the caller graph for this function:

◆ payoffCurrency()

const string & payoffCurrency ( ) const

Definition at line 61 of file fxdigitaloption.hpp.

61{ return payoffCurrency_; }

◆ payoffAmount()

double payoffAmount ( ) const

Definition at line 62 of file fxdigitaloption.hpp.

62{ return payoffAmount_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 111 of file fxdigitaloption.cpp.

111 {
112 Trade::fromXML(node);
113 XMLNode* fxNode = XMLUtils::getChildNode(node, "FxDigitalOptionData");
114 QL_REQUIRE(fxNode, "No FxDigitalOptionData Node");
115 option_.fromXML(XMLUtils::getChildNode(fxNode, "OptionData"));
116 strike_ = XMLUtils::getChildValueAsDouble(fxNode, "Strike", true);
117 payoffCurrency_ = XMLUtils::getChildValue(fxNode, "PayoffCurrency", false);
118 payoffAmount_ = XMLUtils::getChildValueAsDouble(fxNode, "PayoffAmount", true);
119 foreignCurrency_ = XMLUtils::getChildValue(fxNode, "ForeignCurrency", true);
120 domesticCurrency_ = XMLUtils::getChildValue(fxNode, "DomesticCurrency", true);
121}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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 123 of file fxdigitaloption.cpp.

123 {
124 XMLNode* node = Trade::toXML(doc);
125 XMLNode* fxNode = doc.allocNode("FxDigitalOptionData");
126 XMLUtils::appendNode(node, fxNode);
127
128 XMLUtils::appendNode(fxNode, option_.toXML(doc));
129 XMLUtils::addChild(doc, fxNode, "Strike", strike_);
130 XMLUtils::addChild(doc, fxNode, "PayoffCurrency", payoffCurrency_);
131 XMLUtils::addChild(doc, fxNode, "PayoffAmount", payoffAmount_);
132 XMLUtils::addChild(doc, fxNode, "ForeignCurrency", foreignCurrency_);
133 XMLUtils::addChild(doc, fxNode, "DomesticCurrency", domesticCurrency_);
134
135 return node;
136}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
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:

Member Data Documentation

◆ option_

OptionData option_
private

Definition at line 71 of file fxdigitaloption.hpp.

◆ strike_

Real strike_
private

Definition at line 72 of file fxdigitaloption.hpp.

◆ payoffCurrency_

string payoffCurrency_
private

Definition at line 73 of file fxdigitaloption.hpp.

◆ payoffAmount_

Real payoffAmount_
private

Definition at line 74 of file fxdigitaloption.hpp.