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

Trade base class. More...

#include <ored/portfolio/trade.hpp>

+ Inheritance diagram for Trade:
+ Collaboration diagram for Trade:

Public Member Functions

 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
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
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...
 
Setters
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...
 
Inspectors
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
 
- 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...
 

Utility

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_
 
string id_
 
Envelope envelope_
 
TradeActions tradeActions_
 
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...
 
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)
 

Detailed Description

Trade base class.

Instrument interface to pricing and risk applications Derived classes should

Definition at line 55 of file trade.hpp.

Constructor & Destructor Documentation

◆ Trade() [1/2]

Trade ( )

Default constructor.

Definition at line 59 of file trade.hpp.

59{}

◆ Trade() [2/2]

Trade ( const string &  tradeType,
const Envelope env = Envelope(),
const TradeActions ta = TradeActions() 
)

Base class constructor.

Definition at line 62 of file trade.hpp.

64 reset();
65 }
TradeActions tradeActions_
Definition: trade.hpp:238
string tradeType_
Definition: trade.hpp:196
Envelope envelope_
Definition: trade.hpp:237
void reset()
Reset trade, clear all base class data. This does not reset accumulated timings for this trade.
Definition: trade.cpp:130
const string & tradeType() const
Definition: trade.hpp:133
+ Here is the call graph for this function:

◆ ~Trade()

virtual ~Trade ( )
virtual

Default destructor.

Definition at line 68 of file trade.hpp.

68{}

Member Function Documentation

◆ build()

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

◆ fixings()

virtual std::map< std::string, RequiredFixings::FixingDates > fixings ( const QuantLib::Date &  settlementDate = QuantLib::Date()) const
virtual

Return the fixings that will be requested in order to price this Trade given the settlementDate.

If the settlementDate is not provided, the current evaluation date is taken as the settlement date. If a Trade does not have any fixings, this method will return an empty map. The map key is the ORE name of the index and the map value is the set of fixing dates.

Warning:
This method will return an empty map if the Trade has not been built.

Reimplemented in CompositeTrade.

Definition at line 85 of file trade.hpp.

85 {
86 return requiredFixings_.fixingDatesIndices(settlementDate);
87 }
std::map< std::string, FixingDates > fixingDatesIndices(const QuantLib::Date &settlementDate=QuantLib::Date()) const
RequiredFixings requiredFixings_
Definition: trade.hpp:223
+ Here is the call graph for this function:

◆ requiredFixings()

const RequiredFixings & requiredFixings ( ) const

Return the full required fixing information

Definition at line 90 of file trade.hpp.

90{ return requiredFixings_; }
+ Here is the caller graph for this function:

◆ underlyingIndices()

virtual std::map< AssetClass, std::set< std::string > > underlyingIndices ( const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceDataManager = nullptr) const
virtual

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Reimplemented in BalanceGuaranteedSwap, BarrierOption, FxOptionWithBarrier, EquityOptionWithBarrier, CallableSwap, CliquetOption, CommodityAveragePriceOption, CommodityDigitalAveragePriceOption, CommodityOptionStrip, CommoditySwap, CommoditySwaption, FailedTrade, FlexiSwap, IndexCreditDefaultSwapOption, RiskParticipationAgreement, Accumulator, Ascot, AsianOption, Autocallable_01, BasketOption, BasketVarianceSwap, BestEntryOption, Bond, BondOption, BondPosition, BondRepo, BondTRS, CapFloor, CBO, SyntheticCDO, CommodityDigitalOption, CommodityForward, CommodityOption, CommodityPosition, CommoditySpreadOption, CompositeTrade, ConvertibleBond, CreditDefaultSwap, CreditDefaultSwapOption, CreditLinkedSwap, DoubleDigitalOption, EquityDigitalOption, EquityDoubleTouchOption, EquityEuropeanBarrierOption, EquityForward, EquityFutureOption, EquityOption, EquityOptionPosition, EquityOutperformanceOption, EquityPosition, EquityTouchOption, EuropeanOptionBarrier, ForwardBond, ForwardRateAgreement, FxAverageForward, FxDigitalBarrierOption, FxDigitalOption, FxDoubleTouchOption, FxEuropeanBarrierOption, FxForward, FxKIKOBarrierOption, FxOption, FxSwap, FxTouchOption, GenericBarrierOption, IndexCreditDefaultSwap, KnockOutSwap, MultiLegOption, PairwiseVarSwap, PerformanceOption_01, RainbowOption, ScriptedTrade, Swap, Swaption, TaRF, TRS, VarSwap, WindowBarrierOption, and WorstOfBasketSwap.

Definition at line 34 of file trade.cpp.

34 {
35 XMLUtils::checkNode(node, "Trade");
36 tradeType_ = XMLUtils::getChildValue(node, "TradeType", true);
37 if (XMLNode* envNode = XMLUtils::getChildNode(node, "Envelope")) {
38 envelope_.fromXML(envNode);
39 }
41 XMLNode* taNode = XMLUtils::getChildNode(node, "TradeActions");
42 if (taNode)
43 tradeActions_.fromXML(taNode);
44}
virtual void fromXML(XMLNode *node) override
Definition: envelope.cpp:27
virtual void fromXML(XMLNode *node) override
void clear()
Clear the trade actions.
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
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:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Reimplemented in BalanceGuaranteedSwap, BarrierOption, FxOptionWithBarrier, EquityOptionWithBarrier, CallableSwap, CliquetOption, CommodityAveragePriceOption, CommodityDigitalAveragePriceOption, CommodityOptionStrip, CommoditySwap, CommoditySwaption, CreditLinkedSwap, FailedTrade, FlexiSwap, IndexCreditDefaultSwap, IndexCreditDefaultSwapOption, RiskParticipationAgreement, ScriptedTrade, VarSwap, Accumulator, Ascot, AsianOption, Autocallable_01, BasketOption, BasketVarianceSwap, BestEntryOption, Bond, BondOption, BondPosition, BondRepo, BondTRS, CapFloor, CBO, SyntheticCDO, CommodityDigitalOption, CommodityForward, CommodityOption, CommodityPosition, CommoditySpreadOption, CompositeTrade, ConvertibleBond, CreditDefaultSwap, CreditDefaultSwapOption, DoubleDigitalOption, EquityDigitalOption, EquityDoubleTouchOption, EquityEuropeanBarrierOption, EquityForward, EquityFutureOption, EquityOption, EquityOptionPosition, EquityOutperformanceOption, EquityPosition, EquityTouchOption, EuropeanOptionBarrier, ForwardBond, ForwardRateAgreement, FxAverageForward, FxDigitalBarrierOption, FxDigitalOption, FxDoubleTouchOption, FxEuropeanBarrierOption, FxForward, FxKIKOBarrierOption, FxOption, FxSwap, FxTouchOption, GenericBarrierOption, KnockOutSwap, MultiLegOption, PairwiseVarSwap, PerformanceOption_01, RainbowOption, Swap, Swaption, TaRF, TRS, WindowBarrierOption, and WorstOfBasketSwap.

Definition at line 46 of file trade.cpp.

46 {
47 // Crete Trade Node with Id attribute.
48 XMLNode* node = doc.allocNode("Trade");
49 QL_REQUIRE(node, "Failed to create trade node");
50 XMLUtils::addAttribute(doc, node, "id", id_);
51 XMLUtils::addChild(doc, node, "TradeType", tradeType_);
53 if (!tradeActions_.empty())
55 return node;
56}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: envelope.cpp:75
bool empty() const
Returns true of this set of actions is empty.
virtual XMLNode * toXML(XMLDocument &doc) const override
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:
+ Here is the caller graph for this function:

◆ reset()

void reset ( )

Reset trade, clear all base class data. This does not reset accumulated timings for this trade.

Definition at line 130 of file trade.cpp.

130 {
131 // save accumulated timings from wrapper to trade before resetting
132 if (instrument_ != nullptr) {
133 savedNumberOfPricings_ += instrument_->getNumberOfPricings();
134 savedCumulativePricingTime_ += instrument_->getCumulativePricingTime();
135 }
136 // reset members
137 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>();
138 legs_.clear();
139 legCurrencies_.clear();
140 legPayers_.clear();
141 npvCurrency_.clear();
142 notional_ = Null<Real>();
143 notionalCurrency_.clear();
144 maturity_ = Date();
145 issuer_.clear();
147 sensitivityTemplate_.clear();
149}
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
string sensitivityTemplate_
Definition: trade.hpp:206
std::vector< string > legCurrencies_
Definition: trade.hpp:199
string issuer_
Definition: trade.hpp:205
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
QuantLib::Real notional_
Definition: trade.hpp:202
bool sensitivityTemplateSet_
Definition: trade.hpp:207
boost::timer::nanosecond_type savedCumulativePricingTime_
Definition: trade.hpp:210
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
std::size_t savedNumberOfPricings_
Definition: trade.hpp:209
string notionalCurrency_
Definition: trade.hpp:203
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetPricingStats()

void resetPricingStats ( const std::size_t  numberOfPricings = 0,
const boost::timer::nanosecond_type  cumulativePricingTime = 0 
)

Reset accumulated timings to given values.

Definition at line 107 of file trade.hpp.

108 {
109 savedNumberOfPricings_ = numberOfPricings;
110 savedCumulativePricingTime_ = cumulativePricingTime;
111 if (instrument_ != nullptr)
112 instrument_->resetPricingStats();
113 }

◆ id() [1/2]

string & id ( )

Set the trade id.

Definition at line 118 of file trade.hpp.

118{ return id_; }
+ Here is the caller graph for this function:

◆ setEnvelope()

void setEnvelope ( const Envelope envelope)

Set the envelope with counterparty and portfolio info.

Definition at line 122 of file trade.cpp.

122 {
124}
const Envelope & envelope() const
Definition: trade.hpp:135
+ Here is the call graph for this function:

◆ setAdditionalData()

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

Definition at line 126 of file trade.cpp.

126 {
128}
virtual const std::map< std::string, boost::any > & additionalData() const
returns all additional data returned by the trade once built
Definition: trade.cpp:151
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
+ Here is the call graph for this function:

◆ tradeActions() [1/2]

TradeActions & tradeActions ( )

Set the trade actions.

Definition at line 126 of file trade.hpp.

126{ return tradeActions_; }
+ Here is the caller graph for this function:

◆ id() [2/2]

const string & id ( ) const

Definition at line 131 of file trade.hpp.

131{ return id_; }

◆ tradeType()

const string & tradeType ( ) const

Definition at line 133 of file trade.hpp.

133{ return tradeType_; }
+ Here is the caller graph for this function:

◆ envelope()

const Envelope & envelope ( ) const

Definition at line 135 of file trade.hpp.

135{ return envelope_; }
+ Here is the caller graph for this function:

◆ portfolioIds()

const set< string > & portfolioIds ( ) const

Definition at line 137 of file trade.hpp.

137{ return envelope().portfolioIds(); }
const set< string > & portfolioIds() const
Definition: envelope.hpp:103
+ Here is the call graph for this function:

◆ tradeActions() [2/2]

const TradeActions & tradeActions ( ) const

Definition at line 139 of file trade.hpp.

139{ return tradeActions_; }

◆ instrument()

const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument ( ) const

Definition at line 141 of file trade.hpp.

141{ return instrument_; }
+ Here is the caller graph for this function:

◆ legs()

const std::vector< QuantLib::Leg > & legs ( ) const

Definition at line 143 of file trade.hpp.

143{ return legs_; }
+ Here is the caller graph for this function:

◆ legCurrencies()

const std::vector< string > & legCurrencies ( ) const

Definition at line 145 of file trade.hpp.

145{ return legCurrencies_; }
+ Here is the caller graph for this function:

◆ legPayers()

const std::vector< bool > & legPayers ( ) const

Definition at line 147 of file trade.hpp.

147{ return legPayers_; }
+ Here is the caller graph for this function:

◆ npvCurrency()

const string & npvCurrency ( ) const

Definition at line 149 of file trade.hpp.

149{ return npvCurrency_; }
+ Here is the caller graph for this function:

◆ notional()

virtual QuantLib::Real notional ( ) const
virtual

Return the current notional in npvCurrency. See individual sub-classes for the precise definition.

Reimplemented in PairwiseVarSwap, AsianOption, CBO, CommodityForward, CommoditySwap, CommoditySwaption, CompositeTrade, CreditDefaultSwap, CreditLinkedSwap, EquitySwap, FxForward, FxSwap, IndexCreditDefaultSwap, IndexCreditDefaultSwapOption, ScriptedTrade, Swap, Swaption, TRS, and VarSwap.

Definition at line 153 of file trade.hpp.

153{ return notional_; }
+ Here is the caller graph for this function:

◆ notionalCurrency()

virtual string notionalCurrency ( ) const
virtual

Reimplemented in AsianOption, CBO, EquitySwap, FxForward, FxSwap, ScriptedTrade, and Swap.

Definition at line 155 of file trade.hpp.

155{ return notionalCurrency_; }
+ Here is the caller graph for this function:

◆ maturity()

const Date & maturity ( ) const

Definition at line 157 of file trade.hpp.

157{ return maturity_; }
+ Here is the caller graph for this function:

◆ isExpired()

virtual bool isExpired ( const Date &  d)
virtual

Reimplemented in FxForward.

Definition at line 159 of file trade.hpp.

159{ return d >= maturity_; }

◆ issuer()

const string & issuer ( ) const

Definition at line 161 of file trade.hpp.

161{ return issuer_; }

◆ additionalDatum()

T additionalDatum ( const std::string &  tag) const

returns any additional datum.

Definition at line 242 of file trade.hpp.

242 {
243 std::map<std::string,boost::any>::const_iterator value =
244 additionalData_.find(tag);
245 QL_REQUIRE(value != additionalData_.end(),
246 tag << " not provided");
247 return boost::any_cast<T>(value->second);
248}
SafeStack< ValueType > value

◆ additionalData()

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

returns all additional data returned by the trade once built

Reimplemented in CallableSwap, CapFloor, CommoditySwap, CompositeTrade, CreditDefaultSwap, FxAverageForward, IndexCreditDefaultSwap, Swap, and Swaption.

Definition at line 151 of file trade.cpp.

151{ return additionalData_; }
+ Here is the caller graph for this function:

◆ sensitivityTemplate()

const std::string & sensitivityTemplate ( ) const

returns the sensi template, e.g. "IR_Analytical" for this trade, this is only available after build() has been called

Definition at line 305 of file trade.cpp.

305 {
307 StructuredTradeWarningMessage(
308 id(), tradeType(), "No valid sensitivty template.",
309 "Either build() was not called, or the trade builder did not set the sensitivity template.")
310 .log();
311 }
313}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate()

void validate ( ) const

Utility to validate that everything that needs to be set in this base class is actually set.

Definition at line 104 of file trade.cpp.

104 {
105 QL_REQUIRE(id_ != "", "Trade id has not been set.");
106 QL_REQUIRE(tradeType_ != "", "Trade id has not been set.");
107 QL_REQUIRE(instrument_ || legs_.size() > 0,
108 "Trade " << id_ << " requires either QuantLib instruments or legs to be created.");
109 QL_REQUIRE(npvCurrency_ != "", "NPV currency has not been set for trade " << id_ << ".");
110 // QL_REQUIRE(notional_ != Null<Real>(), "Notional has not been set for trade " << id_ << ".");
111 // QL_REQUIRE(notionalCurrency_ != "", "Notional currency has not been set for trade " << id_ << ".");
112 QL_REQUIRE(maturity_ != Null<Date>(), "Maturity not set for trade " << id_ << ".");
113 QL_REQUIRE(envelope_.initialized(), "Envelope not set for trade " << id_ << ".");
114 if (legs_.size() > 0) {
115 QL_REQUIRE(legs_.size() == legPayers_.size(),
116 "Inconsistent number of pay/receive indicators for legs in trade " << id_ << ".");
117 QL_REQUIRE(legs_.size() == legCurrencies_.size(),
118 "Inconsistent number of leg currencies for legs in trade " << id_ << ".");
119 }
120}
bool initialized() const
Check if the envelope is initialized.
Definition: envelope.hpp:116
+ Here is the call graph for this function:

◆ hasCashflows()

virtual bool hasCashflows ( ) const
virtual

Utility method indicating if the trade has cashflows for the cashflow report. The default implementation returns true so that a trade is automatically considered when cashflows are being written. To prevent a trade from being asked for its cashflows, the method can be overridden to return false.

Reimplemented in CapFloor, CommodityAveragePriceOption, CommodityDigitalAveragePriceOption, CommodityDigitalOption, CommodityOption, CommodityOptionStrip, CommoditySwaption, and Swaption.

Definition at line 182 of file trade.hpp.

182{ return true; }

◆ getCumulativePricingTime()

boost::timer::nanosecond_type getCumulativePricingTime ( ) const

Get cumulative timing spent on pricing.

Definition at line 186 of file trade.hpp.

186 {
187 return savedCumulativePricingTime_ + (instrument_ != nullptr ? instrument_->getCumulativePricingTime() : 0);
188 }

◆ getNumberOfPricings()

std::size_t getNumberOfPricings ( ) const

Get number of pricings.

Definition at line 191 of file trade.hpp.

191 {
192 return savedNumberOfPricings_ + (instrument_ != nullptr ? instrument_->getNumberOfPricings() : 0);
193 }

◆ addPremiums()

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 
)
protected

Definition at line 58 of file trade.cpp.

61 {
62
63 Date latestPremiumPayDate = Date::minDate();
64
65 for (auto const& d : premiumData.premiumData()) {
66 QL_REQUIRE(d.amount != Null<Real>(), "Trade contains invalid premium data.");
67
68 Currency premiumCurrency = parseCurrencyWithMinors(d.ccy);
69 Real premiumAmount = convertMinorToMajorCurrency(d.ccy, d.amount);
70 auto fee = QuantLib::ext::make_shared<QuantExt::Payment>(premiumAmount, premiumCurrency, d.payDate);
71
72 addMultipliers.push_back(premiumMultiplier);
73
74 Handle<YieldTermStructure> yts = factory->market()->discountCurve(d.ccy, configuration);
75 Handle<Quote> fx;
76 if (tradeCurrency.code() != d.ccy) {
77 fx = factory->market()->fxRate(d.ccy + tradeCurrency.code(), configuration);
78 }
79 QuantLib::ext::shared_ptr<PricingEngine> discountingEngine(new QuantExt::PaymentDiscountingEngine(yts, fx));
80 fee->setPricingEngine(discountingEngine);
81
82 // 1) Add to additional instruments for pricing
83 addInstruments.push_back(fee);
84
85 // 2) Add a trade leg for cash flow reporting, divide the amount by the multiplier, because the leg entries
86 // are multiplied with the trade multiplier in the cashflow report (and if used elsewhere)
87 legs_.push_back(
88 Leg(1, QuantLib::ext::make_shared<SimpleCashFlow>(fee->cashFlow()->amount() * premiumMultiplier / tradeMultiplier,
89 fee->cashFlow()->date())));
90 legCurrencies_.push_back(fee->currency().code());
91
92 // premium * premiumMultiplier reflects the correct pay direction, set payer to false therefore
93 legPayers_.push_back(false);
94
95 // update latest premium pay date
96 latestPremiumPayDate = std::max(latestPremiumPayDate, d.payDate);
97
98 DLOG("added fee " << d.amount << " " << d.ccy << " payable on " << d.payDate << " to trade");
99 }
100
101 return latestPremiumPayDate;
102}
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
QuantLib::Real convertMinorToMajorCurrency(const std::string &s, QuantLib::Real value)
Convert a value from a minor ccy to major.
Definition: parsers.cpp:324
#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:

◆ setLegBasedAdditionalData()

void setLegBasedAdditionalData ( const Size  legNo,
Size  resultLegId = Null<Size>() 
) const
protected

Definition at line 153 of file trade.cpp.

153 {
154 if (legs_.size() < i + 1)
155 return;
156 Date asof = Settings::instance().evaluationDate();
157 string legID = std::to_string(resultLegId == Null<Size>() ? i + 1 : resultLegId);
158 for (Size j = 0; j < legs_[i].size(); ++j) {
159 QuantLib::ext::shared_ptr<CashFlow> flow = legs_[i][j];
160 // pick flow with earliest future payment date on this leg
161 if (flow->date() > asof) {
162 Real flowAmount = 0.0;
163 try {
164 flowAmount = flow->amount();
165 } catch (std::exception& e) {
166 ALOG("flow amount could not be determined for trade " << id() << ", set to zero: " << e.what());
167 }
168 additionalData_["amount[" + legID + "]"] = flowAmount;
169 additionalData_["paymentDate[" + legID + "]"] = ore::data::to_string(flow->date());
170 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(flow);
171 if (coupon) {
172 Real currentNotional = 0;
173 try {
174 currentNotional = coupon->nominal();
175 } catch (std::exception& e) {
176 ALOG("current notional could not be determined for trade " << id()
177 << ", set to zero: " << e.what());
178 }
179 additionalData_["currentNotional[" + legID + "]"] = currentNotional;
180
181 Real rate = 0;
182 try {
183 rate = coupon->rate();
184 } catch (std::exception& e) {
185 ALOG("coupon rate could not be determined for trade " << id() << ", set to zero: " << e.what());
186 }
187 additionalData_["rate[" + legID + "]"] = rate;
188
189 if (auto frc = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(flow)) {
190 additionalData_["index[" + legID + "]"] = frc->index()->name();
191 additionalData_["spread[" + legID + "]"] = frc->spread();
192 }
193
194 if (auto eqc = QuantLib::ext::dynamic_pointer_cast<QuantExt::EquityCoupon>(flow)) {
195 auto arc = eqc->pricer()->additionalResultCache();
196 additionalData_["initialPrice[" + legID + "]"] = arc.initialPrice;
197 additionalData_["endEquityFixing[" + legID + "]"] = arc.endFixing;
198 if (arc.startFixing != Null<Real>())
199 additionalData_["startEquityFixing[" + legID + "]"] = arc.startFixing;
200 if (arc.startFixingTotal != Null<Real>())
201 additionalData_["startEquityFixingTotal[" + legID + "]"] =
202 arc.startFixingTotal;
203 if (arc.endFixingTotal != Null<Real>())
204 additionalData_["endEquityFixingTotal[" + legID + "]"] = arc.endFixingTotal;
205 if (arc.startFxFixing != Null<Real>())
206 additionalData_["startFxFixing[" + legID + "]"] = arc.startFxFixing;
207 if (arc.endFxFixing != Null<Real>())
208 additionalData_["endFxFixing[" + legID + "]"] = arc.endFxFixing;
209 if (arc.pastDividends != Null<Real>())
210 additionalData_["pastDividends[" + legID + "]"] = arc.pastDividends;
211 if (arc.forecastDividends != Null<Real>())
212 additionalData_["forecastDividends[" + legID + "]"] = arc.forecastDividends;
213 }
214
215 if (auto cpic = QuantLib::ext::dynamic_pointer_cast<QuantExt::CPICoupon>(flow)) {
216 Real baseCPI;
217 baseCPI = cpic->baseCPI();
218 if (baseCPI == Null<Real>()) {
219 try {
220 baseCPI =
221 QuantLib::CPI::laggedFixing(cpic->cpiIndex(), cpic->baseDate() + cpic->observationLag(),
222 cpic->observationLag(), cpic->observationInterpolation());
223 } catch (std::exception& e) {
224 ALOG("CPICoupon baseCPI could not be interpolated for additional results for trade " << id()
225 << ".")
226 }
227 }
228
229 additionalData_["baseCPI[" + legID + "]"] = baseCPI;
230 } else if (auto cpicf = QuantLib::ext::dynamic_pointer_cast<QuantLib::CPICashFlow>(flow)) {
231 Real baseCPI;
232 baseCPI = cpicf->baseFixing();
233 if (baseCPI == Null<Real>()) {
234 try {
235 baseCPI = QuantLib::CPI::laggedFixing(cpicf->cpiIndex(),
236 cpicf->baseDate() + cpicf->observationLag(),
237 cpicf->observationLag(), cpicf->interpolation());
238 } catch (std::exception& e) {
239 ALOG("CPICashFlow baseCPI could not be interpolated for additional results for trade " << id()
240 << ".")
241 }
242 }
243
244 additionalData_["baseCPI[" + legID + "]"] = baseCPI;
245 }
246 }
247 break;
248 }
249 }
250 if (legs_[i].size() > 0) {
251 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(legs_[i][0]);
252 if (coupon) {
253 Real originalNotional = 0.0;
254 try {
255 originalNotional = coupon->nominal();
256 } catch (std::exception& e) {
257 ALOG("original nominal could not be determined for trade " << id() << ", set to zero: " << e.what());
258 }
259 additionalData_["originalNotional[" + legID + "]"] = originalNotional;
260 if (auto eqc = QuantLib::ext::dynamic_pointer_cast<QuantExt::EquityCoupon>(coupon)) {
261 Real quantity = eqc->quantity();
262 if (quantity == Null<Real>()) {
263 if (eqc->legInitialNotional() != Null<Real>() && eqc->initialPrice() != Null<Real>()) {
264 quantity = eqc->legInitialNotional() / eqc->initialPrice();
265 }
266 }
267 additionalData_["initialQuantity[" + legID + "]"] = quantity;
268
269 Real currentPrice = Null<Real>();
270 if (eqc->equityCurve()->isValidFixingDate(asof)) {
271 currentPrice = eqc->equityCurve()->equitySpot()->value();
272 }
273 if (currentPrice != Null<Real>() && originalNotional != Null<Real>()) {
274 additionalData_["currentQuantity" + legID + "]"] = originalNotional / currentPrice;
275 }
276 }
277 }
278 }
279 for (Size j = 0; j < legs_[i].size(); ++j) {
280 QuantLib::ext::shared_ptr<CashFlow> flow = legs_[i][j];
281 if (flow->date() > asof) {
282 Size k = 0;
283 for (auto const& [fixingDate, index, multiplier] :
285 auto label = "[" + legID + "][" + std::to_string(j) + "][" + std::to_string(k) + "]";
286 additionalData_["indexingFixingDate" + label] = fixingDate;
287 additionalData_["indexingIndex" + label] =
288 index == nullptr ? "na" : IndexNameTranslator::instance().oreName(index->name());
289 additionalData_["indexingMultiplier" + label] = multiplier;
290 }
291 }
292 }
293}
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
std::vector< std::tuple< Date, boost::shared_ptr< Index >, Real > > getIndexedCouponOrCashFlowFixingDetails(const boost::shared_ptr< CashFlow > &c)
Real currentNotional(const Leg &leg)
Definition: legdata.cpp:2435
Size size(const ValueType &v)
Definition: value.cpp:145
Real originalNotional(const Leg &leg)
Definition: legdata.cpp:2449
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSensitivityTemplate() [1/2]

void setSensitivityTemplate ( const EngineBuilder builder)
protected

Definition at line 295 of file trade.cpp.

295 {
296 sensitivityTemplate_ = builder.engineParameter("SensitivityTemplate", {}, false, std::string());
298}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSensitivityTemplate() [2/2]

void setSensitivityTemplate ( const std::string &  id)
protected

Definition at line 300 of file trade.cpp.

300 {
303}
string & id()
Set the trade id.
Definition: trade.hpp:118
+ Here is the call graph for this function:

Member Data Documentation

◆ tradeType_

string tradeType_
protected

Definition at line 196 of file trade.hpp.

◆ instrument_

QuantLib::ext::shared_ptr<InstrumentWrapper> instrument_
protected

Definition at line 197 of file trade.hpp.

◆ legs_

std::vector<QuantLib::Leg> legs_
protected

Definition at line 198 of file trade.hpp.

◆ legCurrencies_

std::vector<string> legCurrencies_
protected

Definition at line 199 of file trade.hpp.

◆ legPayers_

std::vector<bool> legPayers_
protected

Definition at line 200 of file trade.hpp.

◆ npvCurrency_

string npvCurrency_
protected

Definition at line 201 of file trade.hpp.

◆ notional_

QuantLib::Real notional_
protected

Definition at line 202 of file trade.hpp.

◆ notionalCurrency_

string notionalCurrency_
protected

Definition at line 203 of file trade.hpp.

◆ maturity_

Date maturity_
protected

Definition at line 204 of file trade.hpp.

◆ issuer_

string issuer_
protected

Definition at line 205 of file trade.hpp.

◆ sensitivityTemplate_

string sensitivityTemplate_
protected

Definition at line 206 of file trade.hpp.

◆ sensitivityTemplateSet_

bool sensitivityTemplateSet_ = false
protected

Definition at line 207 of file trade.hpp.

◆ savedNumberOfPricings_

std::size_t savedNumberOfPricings_ = 0
protected

Definition at line 209 of file trade.hpp.

◆ savedCumulativePricingTime_

boost::timer::nanosecond_type savedCumulativePricingTime_ = 0
protected

Definition at line 210 of file trade.hpp.

◆ requiredFixings_

RequiredFixings requiredFixings_
protected

Definition at line 223 of file trade.hpp.

◆ additionalData_

std::map<std::string,boost::any> additionalData_
mutableprotected

Definition at line 224 of file trade.hpp.

◆ id_

string id_
private

Definition at line 236 of file trade.hpp.

◆ envelope_

Envelope envelope_
private

Definition at line 237 of file trade.hpp.

◆ tradeActions_

TradeActions tradeActions_
private

Definition at line 238 of file trade.hpp.