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

Serializable FX Option. More...

#include <ored/portfolio/fxoption.hpp>

+ Inheritance diagram for FxOption:
+ Collaboration diagram for FxOption:

Public Member Functions

 FxOption ()
 Default constructor. More...
 
 FxOption (const Envelope &env, const OptionData &option, const string &boughtCurrency, double boughtAmount, const string &soldCurrency, double soldAmount, const std::string &fxIndex="")
 Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
Inspectors
const string & boughtCurrency () const
 
double boughtAmount () const
 
const string & soldCurrency () const
 
double soldAmount () const
 
const std::string & fxIndex () const
 
- Public Member Functions inherited from VanillaOptionTrade
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
void setNotionalAndCurrencies ()
 
const OptionDataoption () const
 
const string & asset () const
 
const string & currency () const
 
TradeStrike strike () const
 
double quantity () const
 
const QuantLib::Date forwardDate () const
 
const QuantLib::Date paymentDate () 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

std::string fxIndex_
 If the option has automatic exercise, need an FX index for settlement. More...
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 

Additional Inherited Members

- Protected Member Functions inherited from VanillaOptionTrade
 VanillaOptionTrade (AssetClass assetClassUnderlying)
 
 VanillaOptionTrade (const Envelope &env, AssetClass assetClassUnderlying, OptionData option, string assetName, string currency, double quantity, TradeStrike strike, const QuantLib::ext::shared_ptr< QuantLib::Index > &index=nullptr, const std::string &indexName="", QuantLib::Date forwardDate=QuantLib::Date())
 
- 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 VanillaOptionTrade
AssetClass assetClassUnderlying_
 
OptionData option_
 
string assetName_
 
string currency_
 
Currency underlyingCurrency_
 
double quantity_
 
TradeStrike strike_
 
QuantLib::ext::shared_ptr< QuantLib::Index > index_
 An index is needed if the option is to be automatically exercised on expiry. More...
 
std::string indexName_
 Hold the external index name if needed e.g. in the case of an FX index. More...
 
QuantLib::Date expiryDate_
 Store the option expiry date. More...
 
QuantLib::Date forwardDate_
 Store the (optional) forward date. More...
 
QuantLib::Date paymentDate_
 Store the (optional) payment date. More...
 
- 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 Option.

Definition at line 38 of file fxoption.hpp.

Constructor & Destructor Documentation

◆ FxOption() [1/2]

FxOption ( )

Default constructor.

Definition at line 41 of file fxoption.hpp.

string tradeType_
Definition: trade.hpp:196
VanillaOptionTrade(AssetClass assetClassUnderlying)

◆ FxOption() [2/2]

FxOption ( const Envelope env,
const OptionData option,
const string &  boughtCurrency,
double  boughtAmount,
const string &  soldCurrency,
double  soldAmount,
const std::string &  fxIndex = "" 
)

Constructor.

Definition at line 43 of file fxoption.hpp.

46 TradeStrike(soldAmount / boughtAmount, soldCurrency)),
48 tradeType_ = "FxOption";
49 }
double soldAmount() const
Definition: fxoption.hpp:59
const string & soldCurrency() const
Definition: fxoption.hpp:58
std::string fxIndex_
If the option has automatic exercise, need an FX index for settlement.
Definition: fxoption.hpp:71
const string & boughtCurrency() const
Definition: fxoption.hpp:56
const std::string & fxIndex() const
Definition: fxoption.hpp:60
double boughtAmount() const
Definition: fxoption.hpp:57
const OptionData & option() const

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 41 of file fxoption.cpp.

41 {
42
43 // ISDA taxonomy
44 additionalData_["isdaAssetClass"] = string("Foreign Exchange");
45 additionalData_["isdaBaseProduct"] = string("Vanilla Option");
46 additionalData_["isdaSubProduct"] = string("");
47 additionalData_["isdaTransaction"] = string("");
48
49 additionalData_["boughtCurrency"] = assetName_;
50 additionalData_["boughtAmount"] = quantity_;
51 additionalData_["soldCurrency"] = currency_;
52 additionalData_["soldAmount"] = quantity_ * strike_.value();
53
54 QuantLib::Date today = Settings::instance().evaluationDate();
55 const QuantLib::ext::shared_ptr<Market>& market = engineFactory->market();
56
57 // If automatic exercise, check that we have a non-empty FX index string, parse it and attach curves from market.
59
60 QL_REQUIRE(!fxIndex_.empty(),
61 "FX option trade " << id() << " has automatic exercise so the FXIndex node needs to be populated.");
62
63 // The strike is the number of units of sold currency (currency_) per unit of bought currency (assetName_).
64 // So, the convention here is that the sold currency is domestic and the bought currency is foreign.
65 // Note: intentionally use null calendar and 0 day fixing lag here because we will ask the FX index for its
66 // value on the expiry date without adjustment.
68 engineFactory->configuration(MarketContext::pricing));
69
70 // Populate the external index name so that fixings work.
72 }
73
74 const ext::optional<OptionPaymentData>& opd = option_.paymentData();
76 QuantLib::Date paymentDate = expiryDate_;
77 if (option_.settlement() == "Physical" && opd) {
78 if (opd->rulesBased()) {
79 const Calendar& cal = opd->calendar();
80 QL_REQUIRE(cal != Calendar(), "Need a non-empty calendar for rules based payment date.");
81 paymentDate = cal.advance(expiryDate_, opd->lag(), Days, opd->convention());
82 } else {
83 if (opd->dates().size() > 1)
85 id(), tradeType(), "Trade build", "Found more than 1 payment date. The first one will be used.")
86 .log();
87 paymentDate = opd->dates().front();
88 }
89
90 QL_REQUIRE(paymentDate >= expiryDate_, "Settlement date must be greater than or equal to expiry date.");
91
92 if (expiryDate_ <= today) {
93 // building an fx forward instrument instead of the option
94 Date fixingDate;
95 Currency boughtCcy = parseCurrency(assetName_);
96 Currency soldCcy = parseCurrency(currency_);
97 ext::shared_ptr<QuantLib::Instrument> instrument =
98 ext::make_shared<QuantExt::FxForward>(quantity_, boughtCcy, soldAmount(), soldCcy, maturity_, false,
99 true, paymentDate, soldCcy, fixingDate);
100 instrument_.reset(new VanillaInstrument(instrument));
101 if (option_.exerciseData()) {
102 if (option_.exerciseData()->date() <= expiryDate_) {
103 // option is exercised
104 // fxforward flow are flows from trade data
105 legs_ = {{ext::make_shared<SimpleCashFlow>(quantity_, paymentDate)},
106 {ext::make_shared<SimpleCashFlow>(soldAmount(), paymentDate)}};
108 legPayers_ = {false, true};
109 } else
110 QL_REQUIRE(option_.exerciseData()->date() <= expiryDate_,
111 "Trade build error, exercise after option expiry is not allowed");
112 } else {
113 // option not exercised
114 // set flows = 0
115 legs_ = {};
116 }
119 }
120 // Build the trade using the shared functionality in the base class.
121 VanillaOptionTrade::build(engineFactory);
123 } else {
124 VanillaOptionTrade::build(engineFactory);
125 }
126}
void log() const
generate Boost log record to pass to corresponding sinks
Definition: log.cpp:491
const string & settlement() const
Definition: optiondata.hpp:81
bool isAutomaticExercise() const
Automatic exercise assumed false if not explicitly provided.
Definition: optiondata.hpp:117
const boost::optional< OptionPaymentData > & paymentData() const
Definition: optiondata.hpp:93
const boost::optional< OptionExerciseData > & exerciseData() const
Definition: optiondata.hpp:92
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
Utility classes for Structured warnings, contains the Trade ID and Type.
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
Definition: trade.hpp:141
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
const string & tradeType() const
Definition: trade.hpp:133
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
QuantLib::Real value() const
QuantLib::Date expiryDate_
Store the option expiry date.
QuantLib::Date paymentDate_
Store the (optional) payment date.
const QuantLib::Date paymentDate() const
QuantLib::Date forwardDate_
Store the (optional) forward date.
std::string indexName_
Hold the external index name if needed e.g. in the case of an FX index.
QuantLib::ext::shared_ptr< QuantLib::Index > index_
An index is needed if the option is to be automatically exercised on expiry.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
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
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
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)
Definition: marketdata.cpp:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ boughtCurrency()

const string & boughtCurrency ( ) const

Definition at line 56 of file fxoption.hpp.

56{ return assetName_; }
+ Here is the caller graph for this function:

◆ boughtAmount()

double boughtAmount ( ) const

Definition at line 57 of file fxoption.hpp.

57{ return quantity_; }
+ Here is the caller graph for this function:

◆ soldCurrency()

const string & soldCurrency ( ) const

Definition at line 58 of file fxoption.hpp.

58{ return currency_; }
+ Here is the caller graph for this function:

◆ soldAmount()

double soldAmount ( ) const

Definition at line 59 of file fxoption.hpp.

59{ return strike_.value() * quantity_; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fxIndex()

const std::string & fxIndex ( ) const

Definition at line 60 of file fxoption.hpp.

60{ return fxIndex_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 128 of file fxoption.cpp.

128 {
130 XMLNode* fxNode = XMLUtils::getChildNode(node, "FxOptionData");
131 QL_REQUIRE(fxNode, "No FxOptionData Node");
132 option_.fromXML(XMLUtils::getChildNode(fxNode, "OptionData"));
133 assetName_ = XMLUtils::getChildValue(fxNode, "BoughtCurrency", true);
134 currency_ = XMLUtils::getChildValue(fxNode, "SoldCurrency", true);
135 double boughtAmount = XMLUtils::getChildValueAsDouble(fxNode, "BoughtAmount", true);
136 double soldAmount = XMLUtils::getChildValueAsDouble(fxNode, "SoldAmount", true);
137 strike_ = TradeStrike(soldAmount / boughtAmount, currency_);
139 fxIndex_ = XMLUtils::getChildValue(fxNode, "FXIndex", false);
140 QL_REQUIRE(boughtAmount > 0.0, "positive BoughtAmount required");
141 QL_REQUIRE(soldAmount > 0.0, "positive SoldAmount required");
142}
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 144 of file fxoption.cpp.

144 {
145 // TODO: Should call parent class to xml?
146 XMLNode* node = Trade::toXML(doc);
147 XMLNode* fxNode = doc.allocNode("FxOptionData");
148 XMLUtils::appendNode(node, fxNode);
149
150 XMLUtils::appendNode(fxNode, option_.toXML(doc));
151 XMLUtils::addChild(doc, fxNode, "BoughtCurrency", boughtCurrency());
152 XMLUtils::addChild(doc, fxNode, "BoughtAmount", boughtAmount());
153 XMLUtils::addChild(doc, fxNode, "SoldCurrency", soldCurrency());
154 XMLUtils::addChild(doc, fxNode, "SoldAmount", soldAmount());
155
156 if (!fxIndex_.empty())
157 XMLUtils::addChild(doc, fxNode, "FXIndex", fxIndex_);
158
159 return node;
160}
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

◆ fxIndex_

std::string fxIndex_
private

If the option has automatic exercise, need an FX index for settlement.

Definition at line 71 of file fxoption.hpp.