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

Serializable Fx Average Forward. More...

#include <ored/portfolio/fxaverageforward.hpp>

+ Inheritance diagram for FxAverageForward:
+ Collaboration diagram for FxAverageForward:

Public Member Functions

 FxAverageForward ()
 Default constructor. More...
 
 FxAverageForward (const Envelope &env, const ScheduleData &observationDates, const string &paymentDate, bool fixedPayer, const std::string &referenceCurrency, double referenceNotional, const std::string settlementCurrency, double settlementNotional, const std::string &fxIndex, const string &settlement="Cash")
 Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
Inspectors
const ScheduleDataobservationDates () const
 
const string & paymentDate () const
 
bool fixedPayer () const
 
const string & referenceCurrency () const
 
double referenceNotional () const
 
const string & settlementCurrency () const
 
double settlementNotional () const
 
const std::string & fxIndex () const
 
const string & settlement () 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...
 
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

ScheduleData observationDates_
 
string paymentDate_
 
bool fixedPayer_
 
string referenceCurrency_
 
double referenceNotional_
 
string settlementCurrency_
 
double settlementNotional_
 
std::string fxIndex_
 Needed for past fixings. More...
 
std::string settlement_
 
bool inverted_ = false
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
const std::map< std::string, boost::any > & additionalData () const override
 returns all additional data returned by the trade once built More...
 

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 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 Average Forward.

Payoff: (fixedPayer ? 1 : -1) * (referenceNotional * averageFX - settlementNotional)

Definition at line 33 of file fxaverageforward.hpp.

Constructor & Destructor Documentation

◆ FxAverageForward() [1/2]

Default constructor.

Definition at line 36 of file fxaverageforward.hpp.

36: Trade("FxAverageForward") {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ FxAverageForward() [2/2]

FxAverageForward ( const Envelope env,
const ScheduleData observationDates,
const string &  paymentDate,
bool  fixedPayer,
const std::string &  referenceCurrency,
double  referenceNotional,
const std::string  settlementCurrency,
double  settlementNotional,
const std::string &  fxIndex,
const string &  settlement = "Cash" 
)

Constructor.

Definition at line 38 of file fxaverageforward.hpp.

43 : Trade("FxAverageForward", env),
const string & referenceCurrency() const
const string & settlement() const
const string & paymentDate() const
std::string fxIndex_
Needed for past fixings.
const string & settlementCurrency() const
const std::string & fxIndex() const
const ScheduleData & observationDates() 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 33 of file fxaverageforward.cpp.

33 {
34
35 // ISDA taxonomy
36 additionalData_["isdaAssetClass"] = string("Foreign Exchange");
37 additionalData_["isdaBaseProduct"] = string(settlement_ == "Cash" ? "NDF" : "Forward");
38 additionalData_["isdaSubProduct"] = string("");
39 additionalData_["isdaTransaction"] = string("");
40
41 LOG("FxAverageForward::build() called");
42 QL_REQUIRE(!settlementCurrency_.empty(), "settlement currency must not be blank");
43 QL_REQUIRE(!referenceCurrency_.empty(), "reference currency must not be blank");
44 QL_REQUIRE(!fxIndex_.empty(), "fx index must not be blank");
45 Currency refCcy = parseCurrency(referenceCurrency_);
46 Currency payCcy = parseCurrency(settlementCurrency_);
47 Date payDate = parseDate(paymentDate_);
48 Schedule observationSchedule = makeSchedule(observationDates_);
49 QL_REQUIRE(payDate >= observationSchedule.dates().back(),
50 "payment date >= last observation date required");
51
52 QL_REQUIRE(!fxIndex_.empty(), "FX settlement index must be specified for averaging forwards");
53 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndex = buildFxIndex(fxIndex_, payCcy.code(), refCcy.code(), engineFactory->market(),
54 engineFactory->configuration(MarketContext::pricing));
55 for (const auto& date : observationSchedule.dates()) {
56 if (date <= Settings::instance().evaluationDate())
58 }
59
60
61 // Set up Legs
62 inverted_ = parseFxIndex(fxIndex_)->targetCurrency() != payCcy;
63 legs_ = {{QuantLib::ext::make_shared<SimpleCashFlow>(settlementNotional_, payDate)},
64 {QuantLib::ext::make_shared<QuantExt::AverageFXLinkedCashFlow>(payDate, observationSchedule.dates(),
68
69 // Set up instrument and engine
70 QuantLib::ext::shared_ptr<QuantLib::Swap> swap(new QuantLib::Swap(legs_, legPayers_));
71 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("Swap");
72 QuantLib::ext::shared_ptr<SwapEngineBuilderBase> swapBuilder = QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
73 QL_REQUIRE(swapBuilder, "No Builder found for Swap " << id());
74 swap->setPricingEngine(swapBuilder->engine(payCcy, std::string(), std::string()));
75 setSensitivityTemplate(*swapBuilder);
76 instrument_.reset(new VanillaInstrument(swap));
77
81 maturity_ = payDate;
82
83 LOG("FxAverageForward::build() done");
84}
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
string npvCurrency_
Definition: trade.hpp:201
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
QuantLib::Real notional_
Definition: trade.hpp:202
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
RequiredFixings requiredFixings_
Definition: trade.hpp:223
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
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot, const Handle< YieldTermStructure > &sourceYts, const Handle< YieldTermStructure > &targetYts, const bool useConventions)
Convert std::string to QuantExt::FxIndex.
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
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
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
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
+ Here is the call graph for this function:

◆ observationDates()

const ScheduleData & observationDates ( ) const

Definition at line 54 of file fxaverageforward.hpp.

54{ return observationDates_; }

◆ paymentDate()

const string & paymentDate ( ) const

Definition at line 55 of file fxaverageforward.hpp.

55{ return paymentDate_; }

◆ fixedPayer()

bool fixedPayer ( ) const

Definition at line 56 of file fxaverageforward.hpp.

56{ return fixedPayer_; }

◆ referenceCurrency()

const string & referenceCurrency ( ) const

Definition at line 57 of file fxaverageforward.hpp.

57{ return referenceCurrency_; }

◆ referenceNotional()

double referenceNotional ( ) const

Definition at line 58 of file fxaverageforward.hpp.

58{ return referenceNotional_; }

◆ settlementCurrency()

const string & settlementCurrency ( ) const

Definition at line 59 of file fxaverageforward.hpp.

59{ return settlementCurrency_; }

◆ settlementNotional()

double settlementNotional ( ) const

Definition at line 60 of file fxaverageforward.hpp.

60{ return settlementNotional_; }

◆ fxIndex()

const std::string & fxIndex ( ) const

Definition at line 61 of file fxaverageforward.hpp.

61{ return fxIndex_; }
+ Here is the caller graph for this function:

◆ settlement()

const string & settlement ( ) const

Definition at line 62 of file fxaverageforward.hpp.

62{ return settlement_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 104 of file fxaverageforward.cpp.

104 {
105 Trade::fromXML(node);
106 XMLNode* fxNode = XMLUtils::getChildNode(node, "FxAverageForwardData");
107 QL_REQUIRE(fxNode, "No FxAverageForwardData Node");
108 paymentDate_ = XMLUtils::getChildValue(fxNode, "PaymentDate", true);
109 XMLNode* tmp = XMLUtils::getChildNode(fxNode, "ObservationDates");
110 QL_REQUIRE(tmp, "No ObservationDates provided in FxAverageForwardData");
112 fixedPayer_ = XMLUtils::getChildValueAsBool(fxNode, "FixedPayer", true);
113 referenceCurrency_ = XMLUtils::getChildValue(fxNode, "ReferenceCurrency", true);
114 referenceNotional_ = XMLUtils::getChildValueAsDouble(fxNode, "ReferenceNotional", true);
115 settlementCurrency_ = XMLUtils::getChildValue(fxNode, "SettlementCurrency", true);
116 settlementNotional_ = XMLUtils::getChildValueAsDouble(fxNode, "SettlementNotional", true);
117 fxIndex_ = XMLUtils::getChildValue(fxNode, "FXIndex", true);
118 settlement_ = XMLUtils::getChildValue(fxNode, "Settlement", false);
119 if (settlement_ == "")
120 settlement_ = "Cash";
121}
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
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 bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
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 fxaverageforward.cpp.

123 {
124 XMLNode* node = Trade::toXML(doc);
125 XMLNode* fxNode = doc.allocNode("FxAverageForwardData");
126 XMLUtils::appendNode(node, fxNode);
127
128 XMLNode* schedNode = observationDates_.toXML(doc);
129 XMLUtils::setNodeName(doc, schedNode, "ObservationDates");
130 XMLUtils::appendNode(fxNode, schedNode);
131
132 XMLUtils::addChild(doc, fxNode, "PaymentDate", paymentDate_);
133 XMLUtils::addChild(doc, fxNode, "FixedPayer", std::to_string(fixedPayer_));
134 XMLUtils::addChild(doc, fxNode, "ReferenceCurrency", referenceCurrency_);
135 XMLUtils::addChild(doc, fxNode, "ReferenceNotional", referenceNotional_);
136 XMLUtils::addChild(doc, fxNode, "SettlementCurrency", settlementCurrency_);
137 XMLUtils::addChild(doc, fxNode, "SettlementNotional", settlementNotional_);
138 XMLUtils::addChild(doc, fxNode, "FXIndex", fxIndex_);
139 XMLUtils::addChild(doc, fxNode, "Settlement", settlement_);
140
141 return node;
142}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static void setNodeName(XMLDocument &doc, XMLNode *node, const string &name)
Definition: xmlutils.cpp:478
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:

◆ additionalData()

const std::map< std::string, boost::any > & additionalData ( ) const
overridevirtual

returns all additional data returned by the trade once built

Reimplemented from Trade.

Definition at line 86 of file fxaverageforward.cpp.

86 {
87 additionalData_.clear();
88 additionalData_["settlementNotional"] = settlementNotional_;
89 additionalData_["settlementCurrency"] = settlementCurrency_;
90 additionalData_["referenceCurrency"] = referenceCurrency_;
91 additionalData_["referenceNotional"] = referenceNotional_;
92 if (legs_.size() == 2 && !legs_[1].empty()) {
93 auto avg = QuantLib::ext::dynamic_pointer_cast<QuantExt::AverageFXLinkedCashFlow>(legs_[1].front());
94 if (avg) {
95 for (auto [date, value] : avg->fixings())
96 additionalData_["fixing_" + ore::data::to_string(date)] = value;
97 }
98 additionalData_["average rate"] = inverted_ ? 1.0 / avg->fxRate() : avg->fxRate();
99 additionalData_["effective rate"] = avg->fxRate();
100 }
101 return additionalData_;
102}
SafeStack< ValueType > value
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

Member Data Documentation

◆ observationDates_

ScheduleData observationDates_
private

Definition at line 74 of file fxaverageforward.hpp.

◆ paymentDate_

string paymentDate_
private

Definition at line 75 of file fxaverageforward.hpp.

◆ fixedPayer_

bool fixedPayer_
private

Definition at line 76 of file fxaverageforward.hpp.

◆ referenceCurrency_

string referenceCurrency_
private

Definition at line 77 of file fxaverageforward.hpp.

◆ referenceNotional_

double referenceNotional_
private

Definition at line 78 of file fxaverageforward.hpp.

◆ settlementCurrency_

string settlementCurrency_
private

Definition at line 79 of file fxaverageforward.hpp.

◆ settlementNotional_

double settlementNotional_
private

Definition at line 80 of file fxaverageforward.hpp.

◆ fxIndex_

std::string fxIndex_
private

Needed for past fixings.

Definition at line 82 of file fxaverageforward.hpp.

◆ settlement_

std::string settlement_
private

Definition at line 83 of file fxaverageforward.hpp.

◆ inverted_

bool inverted_ = false
private

Definition at line 84 of file fxaverageforward.hpp.