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

#include <ored/portfolio/varianceswap.hpp>

+ Inheritance diagram for VarSwap:
+ Collaboration diagram for VarSwap:

Public Member Functions

void build (const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
 
const string & longShort ()
 
const std::string & name () const
 
const QuantLib::ext::shared_ptr< ore::data::Underlying > & underlying () const
 
const string & currency ()
 
double strike ()
 
double notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
const string & startDate ()
 
const string & endDate ()
 
const string & calendar ()
 
AssetClass assetClassUnderlying ()
 
const string & momentType ()
 
const bool addPastDividends ()
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
- 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 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...
 

Protected Member Functions

 VarSwap (AssetClass assetClassUnderlying)
 
 VarSwap (ore::data::Envelope &env, string longShort, const QuantLib::ext::shared_ptr< ore::data::Underlying > &underlying, string currency, double strike, double notional, string startDate, string endDate, AssetClass assetClassUnderlying, string momentType, bool addPastDividends)
 
- 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

AssetClass assetClassUnderlying_
 
QuantLib::ext::shared_ptr< ore::data::Underlyingunderlying_
 
- 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_
 

Private Member Functions

void initIndexName ()
 

Private Attributes

string longShort_
 
string currency_
 
double strike_
 
double notional_
 
string startDate_
 
string endDate_
 
string calendar_
 
string momentType_
 
bool addPastDividends_
 
QuantLib::Date start_
 
QuantLib::Calendar cal_
 
std::string indexName_
 
bool oldXml_
 

Detailed Description

Definition at line 35 of file varianceswap.hpp.

Constructor & Destructor Documentation

◆ VarSwap() [1/2]

VarSwap ( AssetClass  assetClassUnderlying)
protected

Definition at line 57 of file varianceswap.hpp.

Trade()
Default constructor.
Definition: trade.hpp:59
AssetClass assetClassUnderlying()
AssetClass assetClassUnderlying_

◆ VarSwap() [2/2]

VarSwap ( ore::data::Envelope env,
string  longShort,
const QuantLib::ext::shared_ptr< ore::data::Underlying > &  underlying,
string  currency,
double  strike,
double  notional,
string  startDate,
string  endDate,
AssetClass  assetClassUnderlying,
string  momentType,
bool  addPastDividends 
)
protected

Definition at line 59 of file varianceswap.hpp.

66 }
QuantLib::ext::shared_ptr< ore::data::Underlying > underlying_
const string & endDate()
const string & startDate()
double notional() const override
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
const QuantLib::ext::shared_ptr< ore::data::Underlying > & underlying() const
const string & momentType()
const string & longShort()
const string & currency()
const bool addPastDividends()
+ Here is the call graph for this function:

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  engineFactory)
override

Definition at line 36 of file varianceswap.cpp.

36 {
37 Currency ccy = ore::data::parseCurrency(currency_);
43
44 // ISDA taxonomy
46 additionalData_["isdaAssetClass"] = string("Foreign Exchange");
47 additionalData_["isdaBaseProduct"] = string("Simple Exotic");
48 additionalData_["isdaSubProduct"] = string("Vol/Var");
50 additionalData_["isdaAssetClass"] = string("Equity");
51 additionalData_["isdaBaseProduct"] = string("Swap");
53 additionalData_["isdaSubProduct"] = string("Parameter Return Variance");
54 else
55 additionalData_["isdaSubProduct"] = string("Parameter Return Volatility");
57 // guessing, that we should treat Commodities as Equities
58 additionalData_["isdaAssetClass"] = string("Commodity");
59 additionalData_["isdaBaseProduct"] = string("Swap");
62 additionalData_["isdaSubProduct"] = string("Parameter Return Variance");
63 else
64 additionalData_["isdaSubProduct"] = string("Parameter Return Volatility");
65 } else {
66 WLOG("ISDA taxonomy not set for trade " << id());
67 }
68 // skip the transaction level mapping for now
69 additionalData_["isdaTransaction"] = string("");
70
71 if (cal_.empty()) {
72 cal_ = ore::data::parseCalendar(ccy.code());
73 }
74
75 QL_REQUIRE(strike_ > 0 && !close_enough(strike_, 0.0),
76 "VarSwap::build() strike must be positive (" << strike_ << ")");
77 QL_REQUIRE(notional_ > 0 || close_enough(notional_, 0.0),
78 "VarSwap::build() notional must be non-negative (" << notional_ << ")");
79
80 // Input strike is annualised Vol
81 // The quantlib strike and notional are in terms of variance, not volatility, so we convert here.
82 Real varianceStrike = strike_ * strike_;
83 Real varianceNotional = notional_ / (2 * 100 * strike_);
84
85 QuantLib::ext::shared_ptr<QuantExt::VarianceSwap2> varSwap(new QuantExt::VarianceSwap2(
86 longShort, varianceStrike, momentType == MomentType::Variance ? varianceNotional : notional_, start_, endDate,
88
89 // Pricing Engine
90 QuantLib::ext::shared_ptr<ore::data::EngineBuilder> builder = engineFactory->builder(tradeType_);
91 QL_REQUIRE(builder, "No builder found for " << tradeType_);
92 QuantLib::ext::shared_ptr<VarSwapEngineBuilder> varSwapBuilder = QuantLib::ext::dynamic_pointer_cast<VarSwapEngineBuilder>(builder);
93
94 varSwap->setPricingEngine(varSwapBuilder->engine(name(), ccy, assetClassUnderlying_, momentType));
95 setSensitivityTemplate(*varSwapBuilder);
96
97 // set up other Trade details
98 instrument_ = QuantLib::ext::shared_ptr<ore::data::InstrumentWrapper>(new ore::data::VanillaInstrument(varSwap));
99
103
104 // add required fixings
105 for (Date d = cal_.advance(start_, -1 * Days); d <= endDate; d = cal_.advance(d, 1 * Days)) {
106 requiredFixings_.addFixingDate(d, indexName_, varSwap->maturityDate());
107 }
108}
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
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
string tradeType_
Definition: trade.hpp:196
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
Vanilla Instrument Wrapper.
const std::string & name() const
QuantLib::Date start_
QuantLib::Calendar cal_
std::string indexName_
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
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
MomentType parseMomentType(const std::string &s)
Convert text to ore::data::MomentType.
Definition: parsers.cpp:1361
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:

◆ longShort()

const string & longShort ( )

Definition at line 39 of file varianceswap.hpp.

39{ return longShort_; }
+ Here is the caller graph for this function:

◆ name()

const std::string & name ( ) const

Definition at line 40 of file varianceswap.hpp.

40{ return underlying_->name(); }
+ Here is the caller graph for this function:

◆ underlying()

const QuantLib::ext::shared_ptr< ore::data::Underlying > & underlying ( ) const

Definition at line 41 of file varianceswap.hpp.

41{ return underlying_; }

◆ currency()

const string & currency ( )

Definition at line 42 of file varianceswap.hpp.

42{ return currency_; }

◆ strike()

double strike ( )

Definition at line 43 of file varianceswap.hpp.

43{ return strike_; }

◆ notional()

QuantLib::Real notional ( ) const
overridevirtual

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

Reimplemented from Trade.

Definition at line 110 of file varianceswap.cpp.

110 {
113 Real varianceNotional = notional_ / (2 * 100 * strike_);
114 return varianceNotional * 10000;
115 } else
116 return notional_ * 100;
117}
+ Here is the call graph for this function:

◆ startDate()

const string & startDate ( )

Definition at line 46 of file varianceswap.hpp.

46{ return startDate_; }

◆ endDate()

const string & endDate ( )

Definition at line 47 of file varianceswap.hpp.

47{ return endDate_; }
+ Here is the caller graph for this function:

◆ calendar()

const string & calendar ( )

Definition at line 48 of file varianceswap.hpp.

48{ return calendar_; }

◆ assetClassUnderlying()

AssetClass assetClassUnderlying ( )

Definition at line 49 of file varianceswap.hpp.

49{ return assetClassUnderlying_; }

◆ momentType()

const string & momentType ( )

Definition at line 50 of file varianceswap.hpp.

50{ return momentType_; }
+ Here is the caller graph for this function:

◆ addPastDividends()

const bool addPastDividends ( )

Definition at line 51 of file varianceswap.hpp.

51{ return addPastDividends_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 119 of file varianceswap.cpp.

119 {
120 Trade::fromXML(node);
121 XMLNode* vNode = XMLUtils::getChildNode(node, tradeType() + "Data");
122 if (!vNode) {
123 vNode = XMLUtils::getChildNode(node, "VarianceSwapData");
124 oldXml_ = true;
125 }
126 startDate_ = XMLUtils::getChildValue(vNode, "StartDate", true);
127 endDate_ = XMLUtils::getChildValue(vNode, "EndDate", true);
128 currency_ = XMLUtils::getChildValue(vNode, "Currency", true);
129
130 XMLNode* tmp = XMLUtils::getChildNode(vNode, "Underlying");
131 if (!tmp) {
132 tmp = XMLUtils::getChildNode(vNode, "Name");
133 QL_REQUIRE(tmp, "Must provide a valid Underlying or Name node");
134 }
135 UnderlyingBuilder underlyingBuilder;
136 underlyingBuilder.fromXML(tmp);
137 underlying_ = underlyingBuilder.underlying();
138
139 longShort_ = XMLUtils::getChildValue(vNode, "LongShort", true);
140 strike_ = XMLUtils::getChildValueAsDouble(vNode, "Strike", true);
141 notional_ = XMLUtils::getChildValueAsDouble(vNode, "Notional", true);
142 calendar_ = XMLUtils::getChildValue(vNode, "Calendar", true);
143 momentType_ = XMLUtils::getChildValue(vNode, "MomentType", false);
144 if (momentType_ == "")
145 momentType_ = "Variance";
146 string addPastDividendsStr = XMLUtils::getChildValue(vNode, "AddPastDividends", false);
147 if (addPastDividendsStr == "")
148 addPastDividends_ = false;
149 else
150 addPastDividends_ = parseBool(addPastDividendsStr);
152}
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
const string & tradeType() const
Definition: trade.hpp:133
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
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 154 of file varianceswap.cpp.

154 {
155 XMLNode* node = Trade::toXML(doc);
156 XMLNode* vNode;
157 if (oldXml_) {
158 vNode = doc.allocNode("VarianceSwapData");
159 } else {
160 vNode = doc.allocNode(tradeType() + "Data");
161 }
162 XMLUtils::appendNode(node, vNode);
163 XMLUtils::addChild(doc, vNode, "StartDate", startDate_);
164 XMLUtils::addChild(doc, vNode, "EndDate", endDate_);
165 XMLUtils::addChild(doc, vNode, "Currency", currency_);
166 XMLUtils::appendNode(vNode, underlying_->toXML(doc));
167 XMLUtils::addChild(doc, vNode, "LongShort", longShort_);
168 XMLUtils::addChild(doc, vNode, "Strike", strike_);
169 XMLUtils::addChild(doc, vNode, "Notional", notional_);
170 XMLUtils::addChild(doc, vNode, "Calendar", calendar_);
171 XMLUtils::addChild(doc, vNode, "MomentType", momentType_);
172 XMLUtils::addChild(doc, vNode, "AddPastDividends", addPastDividends_);
173 return node;
174}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
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:

◆ initIndexName()

void initIndexName ( )
private

Definition at line 176 of file varianceswap.cpp.

176 {
178 indexName_ = "FX-" + name();
180 indexName_ = "EQ-" + name();
182 indexName_ = "COM-" + name();
183 else {
184 QL_FAIL("asset class " << assetClassUnderlying_ << " not supported.");
185 }
186}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ assetClassUnderlying_

AssetClass assetClassUnderlying_
protected

Definition at line 68 of file varianceswap.hpp.

◆ underlying_

QuantLib::ext::shared_ptr<ore::data::Underlying> underlying_
protected

Definition at line 71 of file varianceswap.hpp.

◆ longShort_

string longShort_
private

Definition at line 75 of file varianceswap.hpp.

◆ currency_

string currency_
private

Definition at line 76 of file varianceswap.hpp.

◆ strike_

double strike_
private

Definition at line 77 of file varianceswap.hpp.

◆ notional_

double notional_
private

Definition at line 78 of file varianceswap.hpp.

◆ startDate_

string startDate_
private

Definition at line 79 of file varianceswap.hpp.

◆ endDate_

string endDate_
private

Definition at line 80 of file varianceswap.hpp.

◆ calendar_

string calendar_
private

Definition at line 81 of file varianceswap.hpp.

◆ momentType_

string momentType_
private

Definition at line 82 of file varianceswap.hpp.

◆ addPastDividends_

bool addPastDividends_
private

Definition at line 83 of file varianceswap.hpp.

◆ start_

QuantLib::Date start_
private

Definition at line 86 of file varianceswap.hpp.

◆ cal_

QuantLib::Calendar cal_
private

Definition at line 87 of file varianceswap.hpp.

◆ indexName_

std::string indexName_
private

The index name. Not sure why the index was not just used in the trade XML. This is set to "FX-" + name for FX and left as name for the others for the moment.

Definition at line 92 of file varianceswap.hpp.

◆ oldXml_

bool oldXml_
private

Definition at line 95 of file varianceswap.hpp.