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

Serializable Asian Option. More...

#include <ored/portfolio/asianoption.hpp>

+ Inheritance diagram for AsianOption:
+ Collaboration diagram for AsianOption:

Public Member Functions

 AsianOption (const string &tradeType)
 
 AsianOption (const Envelope &env, const string &tradeType, const double quantity, const TradeStrike &strike, const OptionData &option, const ScheduleData &observationDates, const QuantLib::ext::shared_ptr< Underlying > &underlying, const Date &settlementDate, const std::string &currency)
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
QuantLib::Real notional () const override
 Trade interface. More...
 
string notionalCurrency () const override
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (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
 
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...
 

Inspectors

double quantity_ = 0.0
 
TradeStrike tradeStrike_
 
OptionData option_
 
ScheduleData observationDates_
 
QuantLib::ext::shared_ptr< Underlyingunderlying_
 
Date settlementDate_
 
string currency_
 
string assetName_
 
QuantLib::ext::shared_ptr< TradedelegatingBuilderTrade_
 
string indexName_
 
const string & asset () const
 
const TradeStrikestrike () const
 
double quantity () const
 
const OptionDataoption () const
 
const ScheduleDataobservationDates () const
 
const Date & settlementDate () const
 
const string & payCurrency () const
 
const string & indexName () const
 
const QuantLib::ext::shared_ptr< Underlying > & underlying () const
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 
void populateIndexName () const
 

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 Asian Option.

Definition at line 40 of file asianoption.hpp.

Constructor & Destructor Documentation

◆ AsianOption() [1/2]

AsianOption ( const string &  tradeType)
explicit

Definition at line 42 of file asianoption.hpp.

42: Trade(tradeType) {}
Trade()
Default constructor.
Definition: trade.hpp:59
const string & tradeType() const
Definition: trade.hpp:133

◆ AsianOption() [2/2]

AsianOption ( const Envelope env,
const string &  tradeType,
const double  quantity,
const TradeStrike strike,
const OptionData option,
const ScheduleData observationDates,
const QuantLib::ext::shared_ptr< Underlying > &  underlying,
const Date &  settlementDate,
const std::string &  currency 
)

Definition at line 43 of file asianoption.hpp.

49 currency_(currency) {}
const OptionData & option() const
Definition: asianoption.hpp:69
const QuantLib::ext::shared_ptr< Underlying > & underlying() const
Definition: asianoption.hpp:77
const Date & settlementDate() const
Definition: asianoption.hpp:71
QuantLib::ext::shared_ptr< Underlying > underlying_
Definition: asianoption.hpp:91
TradeStrike tradeStrike_
Definition: asianoption.hpp:88
ScheduleData observationDates_
Definition: asianoption.hpp:90
double quantity() const
Definition: asianoption.hpp:68
const TradeStrike & strike() const
Definition: asianoption.hpp:67
const ScheduleData & observationDates() const
Definition: asianoption.hpp:70

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 35 of file asianoption.cpp.

35 {
36
37 // ISDA taxonomy
38 if (underlying_->type() == "Equity") {
39 additionalData_["isdaAssetClass"] = string("Equity");
40 additionalData_["isdaBaseProduct"] = string("Option");
41 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
42 } else if (underlying_->type() == "FX") {
43 additionalData_["isdaAssetClass"] = string("Foreign Exchange");
44 additionalData_["isdaBaseProduct"] = string("Vanilla Option");
45 additionalData_["isdaSubProduct"] = string("");
46 } else if (underlying_->type() == "Commodity") {
47 // guessing that Commodities are treated like Equity
48 additionalData_["isdaAssetClass"] = string("Commodity");
49 additionalData_["isdaBaseProduct"] = string("Option");
50 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
51 }
52 else {
53 WLOG("ISDA taxonomy not set for trade " << id());
54 }
55 additionalData_["isdaTransaction"] = string("");
56
57 Currency payCcy = parseCurrency(currency_);
58
59 QL_REQUIRE(tradeActions().empty(), "TradeActions not supported for AsianOption");
60
61 Option::Type type = parseOptionType(option_.callPut());
62 QL_REQUIRE(option_.exerciseDates().size() == 1, "Expected exactly one exercise date");
63 Date expiryDate = parseDate(option_.exerciseDates().front());
64
65 string tradeTypeBuilder = tradeType_;
66
67 // Add Arithmetic/Geometric
68
69 if (option_.payoffType2() == "Arithmetic" || option_.payoffType2().empty())
70 tradeTypeBuilder += "Arithmetic";
71 else if (option_.payoffType2() == "Geometric")
72 tradeTypeBuilder += "Geometric";
73 else {
74 QL_FAIL("payoff type 2 must be 'Arithmetic' or 'Geometric'");
75 }
76
77 // Add Price/Strike
78
79 if (option_.payoffType() == "Asian")
80 tradeTypeBuilder += "Price";
81 else if (option_.payoffType() == "AverageStrike")
82 tradeTypeBuilder += "Strike";
83 else {
84 QL_FAIL("payoff type must be 'Asian' or 'AverageStrike'");
85 }
86
87 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeTypeBuilder);
88 QL_REQUIRE(builder, "No builder found for " << tradeTypeBuilder);
89
90 // check for delegating engine builder
91
92 if (auto db = QuantLib::ext::dynamic_pointer_cast<DelegatingEngineBuilder>(builder)) {
93
94 // let the delegating builder build the trade and link the results to this trade
95
96 delegatingBuilderTrade_ = db->build(this, engineFactory);
97
100 npvCurrency_ = delegatingBuilderTrade_->npvCurrency();
101 additionalData_ = delegatingBuilderTrade_->additionalData();
102 requiredFixings_ = delegatingBuilderTrade_->requiredFixings();
103 setSensitivityTemplate(delegatingBuilderTrade_->sensitivityTemplate());
104
105 // notional and notional currency are defined in overriden methods!
106
107 return;
108 }
109
110 // we do not have a delegating engine builder
111
112 QuantLib::ext::shared_ptr<AsianOptionEngineBuilder> asianOptionBuilder =
113 QuantLib::ext::dynamic_pointer_cast<AsianOptionEngineBuilder>(builder);
114
115 QL_REQUIRE(asianOptionBuilder, "engine builder is not an AsianOption engine builder" << tradeTypeBuilder);
116
117 std::string processType = asianOptionBuilder->processType();
118 QL_REQUIRE(!processType.empty(), "ProcessType must be configured, this is unexpected");
119
120 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(type, tradeStrike_.value()));
121
122 auto index = parseIndex(indexName());
123
124 if (auto fxIndex = QuantLib::ext::dynamic_pointer_cast<QuantExt::FxIndex>(index)) {
125 QL_REQUIRE(fxIndex->targetCurrency() == payCcy,
126 "FX domestic ccy " << fxIndex->targetCurrency() << " must match pay ccy " << payCcy);
127 assetName_ = fxIndex->sourceCurrency().code();
128 } else if (auto eqIndex = QuantLib::ext::dynamic_pointer_cast<QuantExt::EquityIndex2>(index)) {
129 // FIXME for EQ and COMM indices check whether EQ, COMM ccy = payCcy (in the engine builders probably)
130 assetName_ = eqIndex->name();
131 } else if (auto commIndex = QuantLib::ext::dynamic_pointer_cast<QuantExt::CommodityIndex>(index)) {
132 assetName_ = commIndex->underlyingName();
133 }
134
135 // FIXME the engine should handle the historical part of the averaging as well!
136 QuantLib::ext::shared_ptr<QuantLib::Instrument> asian;
137 auto exercise = QuantLib::ext::make_shared<QuantLib::EuropeanExercise>(expiryDate);
138 if (processType == "Discrete") {
139 QuantLib::Date today = engineFactory->market()->asofDate();
140 Real runningAccumulator = option_.payoffType2() == "Geometric" ? 1.0 : 0.0;
141 Size pastFixings = 0;
142 Schedule observationSchedule = makeSchedule(observationDates_);
143 std::vector<QuantLib::Date> observationDates = observationSchedule.dates();
144
145 // Sort for the engine's sake. Not needed - instrument also sorts...?
146 std::sort(observationDates.begin(), observationDates.end());
147
148 for (QuantLib::Date observationDate : observationDates) {
149 // TODO: Verify. Should today be read too? a enforcesTodaysHistoricFixings() be used?
150 if (observationDate < today ||
151 (observationDate == today && Settings::instance().enforcesTodaysHistoricFixings())) {
152 // FIXME all observation dates lead to a required fixing
153 requiredFixings_.addFixingDate(observationDate, indexName());
154 Real fixingValue = index->fixing(observationDate);
155 if (option_.payoffType2() == "Geometric") {
156 runningAccumulator *= fixingValue;
157 } else if (option_.payoffType2() == "Arithmetic") {
158 runningAccumulator += fixingValue;
159 }
160 ++pastFixings;
161 }
162 }
163 asian = QuantLib::ext::make_shared<QuantLib::DiscreteAveragingAsianOption>(
164 option_.payoffType2() == "Geometric" ? QuantLib::Average::Type::Geometric
165 : QuantLib::Average::Type::Arithmetic,
166 runningAccumulator, pastFixings, observationDates, payoff, exercise);
167 } else if (processType == "Continuous") {
168 // FIXME how is the accumulated average handled in this case?
169 asian = QuantLib::ext::make_shared<QuantLib::ContinuousAveragingAsianOption>(option_.payoffType2() == "Geometric"
170 ? QuantLib::Average::Type::Geometric
171 : QuantLib::Average::Type::Arithmetic,
172 payoff, exercise);
173 } else {
174 QL_FAIL("unexpected ProcessType, valid options are Discrete/Continuous");
175 }
176
177 // Only try to set an engine on the option instrument if it is not expired. This avoids errors in
178 // engine builders that rely on the expiry date being in the future.
179 string configuration = asianOptionBuilder->configuration(MarketContext::pricing);
180 if (!asian->isExpired()) {
181 asian->setPricingEngine(asianOptionBuilder->engine(assetName_, payCcy, expiryDate));
182 setSensitivityTemplate(*asianOptionBuilder);
183 } else {
184 DLOG("No engine attached for option on trade " << id() << " with expiry date " << io::iso_date(expiryDate)
185 << " because it is expired.");
186 }
187
188 Position::Type positionType = parsePositionType(option_.longShort());
189 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
190 Real mult = quantity_ * bsInd;
191
192 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
193 std::vector<Real> additionalMultipliers;
194 maturity_ = expiryDate;
195 maturity_ =
196 std::max(maturity_, addPremiums(additionalInstruments, additionalMultipliers, mult, option_.premiumData(),
197 positionType == QuantLib::Position::Long ? -1.0 : 1.0, payCcy, engineFactory,
198 configuration));
199
200 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(asian, mult, additionalInstruments, additionalMultipliers);
201
205}
QuantLib::ext::shared_ptr< Trade > delegatingBuilderTrade_
Definition: asianoption.hpp:97
const string & indexName() const
Definition: asianoption.hpp:73
const string & callPut() const
Definition: optiondata.hpp:71
const string & payoffType2() const
Definition: optiondata.hpp:73
const string & payoffType() const
Definition: optiondata.hpp:72
const string & longShort() const
Definition: optiondata.hpp:70
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
const vector< ScheduleDates > & dates() const
Definition: schedule.hpp:228
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
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::Real value() const
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
QuantLib::ext::shared_ptr< Index > parseIndex(const string &s)
Convert std::string to QuantLib::Index.
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
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
+ Here is the call graph for this function:

◆ notional()

QuantLib::Real notional ( ) const
overridevirtual

Trade interface.

Reimplemented from Trade.

Definition at line 306 of file asianoption.cpp.

306 {
307 return delegatingBuilderTrade_ != nullptr ? delegatingBuilderTrade_->notional() : Trade::notional();
308}
virtual QuantLib::Real notional() const
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
Definition: trade.hpp:153
+ Here is the call graph for this function:

◆ notionalCurrency()

string notionalCurrency ( ) const
overridevirtual

Reimplemented from Trade.

Definition at line 310 of file asianoption.cpp.

310 {
311 return delegatingBuilderTrade_ != nullptr ? delegatingBuilderTrade_->notionalCurrency() : Trade::notionalCurrency();
312}
virtual string notionalCurrency() const
Definition: trade.hpp:155
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 207 of file asianoption.cpp.

207 {
208 Trade::fromXML(node);
209 XMLNode* n = XMLUtils::getChildNode(node, tradeType() + "Data");
210 QL_REQUIRE(n, "No " + tradeType_ + "Data node found.");
211
212 quantity_ = XMLUtils::getChildValueAsDouble(n, "Quantity", true);
213
215
216 currency_ = XMLUtils::getChildValue(n, "Currency", false);
217
218 XMLNode* tmp = XMLUtils::getChildNode(n, "Underlying");
219 if (!tmp)
220 tmp = XMLUtils::getChildNode(n, "Name");
221 UnderlyingBuilder underlyingBuilder;
222 underlyingBuilder.fromXML(tmp);
223 underlying_ = underlyingBuilder.underlying();
224
225 option_.fromXML(XMLUtils::getChildNode(n, "OptionData"));
226
227 settlementDate_ = parseDate(XMLUtils::getChildValue(n, "Settlement", false));
228
229 observationDates_.fromXML(XMLUtils::getChildNode(n, "ObservationDates"));
230}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
Definition: tradestrike.cpp:50
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 232 of file asianoption.cpp.

232 {
233 XMLNode* node = Trade::toXML(doc);
234 XMLNode* n = doc.allocNode(tradeType() + "Data");
235 XMLUtils::appendNode(node, n);
236 XMLUtils::addChild(doc, n, "Quantity", quantity_);
238 XMLUtils::addChild(doc, n, "Currency", currency_);
239 XMLUtils::appendNode(n, underlying_->toXML(doc));
241 if (settlementDate_ != Null<Date>())
243 auto tmp = observationDates_.toXML(doc);
244 XMLUtils::setNodeName(doc, tmp, "ObservationDates");
245 XMLUtils::appendNode(n, tmp);
246 return node;
247}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
XMLNode * toXML(XMLDocument &doc) const
Definition: tradestrike.cpp:86
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
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ asset()

const string & asset ( ) const

Definition at line 66 of file asianoption.hpp.

66{ return assetName_; } // only available after build()

◆ strike()

const TradeStrike & strike ( ) const

Definition at line 67 of file asianoption.hpp.

67{ return tradeStrike_; }

◆ quantity()

double quantity ( ) const

Definition at line 68 of file asianoption.hpp.

68{ return quantity_; }

◆ option()

const OptionData & option ( ) const

Definition at line 69 of file asianoption.hpp.

69{ return option_; }

◆ observationDates()

const ScheduleData & observationDates ( ) const

Definition at line 70 of file asianoption.hpp.

70{ return observationDates_; }
+ Here is the caller graph for this function:

◆ settlementDate()

const Date & settlementDate ( ) const

Definition at line 71 of file asianoption.hpp.

71{ return settlementDate_; }

◆ payCurrency()

const string & payCurrency ( ) const

Definition at line 72 of file asianoption.hpp.

72{ return currency_; }

◆ indexName()

const string & indexName ( ) const

Definition at line 73 of file asianoption.hpp.

73 {
75 return indexName_;
76 }
void populateIndexName() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ underlying()

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

Definition at line 77 of file asianoption.hpp.

77{ return underlying_; }

◆ underlyingIndices()

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

Reimplemented from Trade.

Definition at line 250 of file asianoption.cpp.

250 {
251 std::map<AssetClass, std::set<std::string>> result;
252 if (isEquityIndex(indexName())) {
253 result[AssetClass::EQ].insert(indexName());
254 } else if (isFxIndex(indexName_)) {
255 result[AssetClass::FX].insert(indexName());
256 } else if (isCommodityIndex(indexName_)) {
257 result[AssetClass::COM].insert(indexName());
258 }
259 return result;
260}
bool isEquityIndex(const string &indexName)
Return true if the indexName is that of an EquityIndex, otherwise false.
bool isCommodityIndex(const string &indexName)
Return true if the indexName is that of an CommodityIndex, otherwise false.
bool isFxIndex(const std::string &indexName)
+ Here is the call graph for this function:

◆ populateIndexName()

void populateIndexName ( ) const
protected

Definition at line 262 of file asianoption.cpp.

262 {
263 if (!indexName_.empty())
264 return;
265 if (underlying_->type() == "Equity") {
266 indexName_ = "EQ-" + underlying_->name();
267 } else if (underlying_->type() == "FX") {
268 indexName_ = "FX-" + underlying_->name();
269 } else if (underlying_->type() == "Commodity") {
270 QuantLib::ext::shared_ptr<CommodityUnderlying> comUnderlying =
271 QuantLib::ext::dynamic_pointer_cast<CommodityUnderlying>(underlying_);
272 std::string tmp = "COMM-" + comUnderlying->name();
273 if (comUnderlying->priceType().empty() || comUnderlying->priceType() == "Spot") {
274 indexName_ = tmp;
275 } else if (comUnderlying->priceType() == "FutureSettlement") {
276 auto conventions = InstrumentConventions::instance().conventions();
277 QL_REQUIRE(conventions->has(comUnderlying->name()),
278 "future settlement requires conventions for commodity '" << comUnderlying->name() << "'");
279 auto convention =
280 QuantLib::ext::dynamic_pointer_cast<CommodityFutureConvention>(conventions->get(comUnderlying->name()));
281 Size futureMonthsOffset =
282 comUnderlying->futureMonthOffset() == Null<Size>() ? 0 : comUnderlying->futureMonthOffset();
283 Size deliveryRollDays =
284 comUnderlying->deliveryRollDays() == Null<Size>() ? 0 : comUnderlying->deliveryRollDays();
285 Calendar cal = parseCalendar(comUnderlying->deliveryRollCalendar());
286 ConventionsBasedFutureExpiry expiryCalculator(*convention);
287 QL_REQUIRE(option_.exerciseDates().size() == 1, "expected exactly one exercise date");
288 Date expiryDate = parseDate(option_.exerciseDates().front());
289 Date adjustedObsDate =
290 deliveryRollDays != 0 ? cal.advance(expiryDate, deliveryRollDays * Days) : expiryDate;
291 auto tmp = parseCommodityIndex(comUnderlying->name(), false, Handle<QuantExt::PriceTermStructure>(),
292 convention->calendar(), true);
293 tmp = tmp->clone(expiryCalculator.nextExpiry(true, adjustedObsDate, futureMonthsOffset));
294 indexName_ = tmp->name();
295 } else {
296 QL_FAIL("underlying price type '" << comUnderlying->priceType() << "' for commodity underlying '"
297 << comUnderlying->name() << "' not handled.");
298 }
299 } else if (underlying_->type() == "Basic") {
300 indexName_ = underlying_->name();
301 } else {
302 QL_FAIL("invalid underlying type: " << underlying_->type());
303 }
304}
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > parseCommodityIndex(const string &name, bool hasPrefix, const Handle< PriceTermStructure > &ts, const Calendar &cal, const bool enforceFutureIndex)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ quantity_

double quantity_ = 0.0
protected

Definition at line 87 of file asianoption.hpp.

◆ tradeStrike_

TradeStrike tradeStrike_
protected

Definition at line 88 of file asianoption.hpp.

◆ option_

OptionData option_
protected

Definition at line 89 of file asianoption.hpp.

◆ observationDates_

ScheduleData observationDates_
protected

Definition at line 90 of file asianoption.hpp.

◆ underlying_

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

Definition at line 91 of file asianoption.hpp.

◆ settlementDate_

Date settlementDate_
protected

Definition at line 92 of file asianoption.hpp.

◆ currency_

string currency_
protected

Definition at line 94 of file asianoption.hpp.

◆ assetName_

string assetName_
protected

Definition at line 95 of file asianoption.hpp.

◆ delegatingBuilderTrade_

QuantLib::ext::shared_ptr<Trade> delegatingBuilderTrade_
protected

Definition at line 97 of file asianoption.hpp.

◆ indexName_

string indexName_
mutableprotected

Definition at line 99 of file asianoption.hpp.