31 QL_REQUIRE(n !=
nullptr,
"EquityOptionUnderlyingData: expected child node Underlying");
34 QL_REQUIRE(n !=
nullptr,
"EquityOptionUnderlyingData: expected child node OptionData");
52 for (
auto const n : c) {
76 DLOG(
"EquityOptionPosition::build() called for " <<
id());
77 QL_REQUIRE(!
data_.
underlyings().empty(),
"EquityOptionPosition::build(): no underlyings given");
91 auto eq = *engineFactory->market()->equityCurve(u.underlying().name(),
93 weights_.push_back(u.underlying().weight());
94 QL_REQUIRE(!eq->currency().empty(),
95 "did not get currency for equity name '" << u.underlying().name() <<
"', is this set up?");
98 Real posInd = (pos == QuantLib::Position::Long ? 1.0 : -1.0);
104 QuantLib::Exercise::Type exerciseType =
parseExerciseType(u.optionData().style());
105 QL_REQUIRE(u.optionData().exerciseDates().size() == 1,
"Invalid number of exercise dates");
106 Date optionExpiry =
parseDate(u.optionData().exerciseDates().front());
107 QuantLib::ext::shared_ptr<Exercise> exercise;
108 switch (exerciseType) {
109 case QuantLib::Exercise::Type::European: {
110 exercise = QuantLib::ext::make_shared<EuropeanExercise>(optionExpiry);
113 case QuantLib::Exercise::Type::American: {
114 exercise = QuantLib::ext::make_shared<AmericanExercise>(optionExpiry, u.optionData().payoffAtExpiry());
118 QL_FAIL(
"Option Style " << u.optionData().style() <<
" is not supported");
120 options_.push_back(QuantLib::ext::make_shared<VanillaOption>(
121 QuantLib::ext::make_shared<PlainVanillaPayoff>(optionType, u.strike()), exercise));
122 if (!
options_.back()->isExpired()) {
123 std::string tradeTypeBuilder =
124 (exerciseType == QuantLib::Exercise::Type::European ?
"EquityOption" :
"EquityOptionAmerican");
125 QuantLib::ext::shared_ptr<VanillaOptionEngineBuilder> builder =
126 QuantLib::ext::dynamic_pointer_cast<VanillaOptionEngineBuilder>(engineFactory->builder(tradeTypeBuilder));
127 QL_REQUIRE(builder,
"EquityOptionPosition::build(): no engine builder for '" << tradeTypeBuilder <<
"'");
128 options_.back()->setPricingEngine(builder->engine(u.underlying().name(), eq->currency(), optionExpiry));
135 std::ostringstream strikeStr;
136 strikeStr << u.strike();
138 string underlyingName = u.underlying().name();
139 if (engineFactory->referenceData() && engineFactory->referenceData()->hasData(
"Equity", underlyingName)) {
140 const auto& underlyingRef = engineFactory->referenceData()->getData(
"Equity", underlyingName);
141 if (
auto equityRef = QuantLib::ext::dynamic_pointer_cast<EquityReferenceDatum>(underlyingRef))
142 underlyingName = equityRef->equityData().equityId;
144 indices_.push_back(QuantLib::ext::make_shared<QuantExt::GenericIndex>(
145 "GENERIC-MD/EQUITY_OPTION/PRICE/" + underlyingName +
"/" + eq->currency().code() +
"/" +
147 (optionType == Option::Call ?
"C" :
"P"), optionExpiry));
166 qlInstr->setPricingEngine(QuantLib::ext::make_shared<EquityOptionPositionInstrumentWrapperEngine>());
167 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qlInstr);
179 QuantLib::ext::static_pointer_cast<EquityOptionPositionInstrumentWrapper>(
instrument_->qlInstrument())
180 ->setNpvCurrencyConversion(conversion);
194std::map<AssetClass, std::set<std::string>>
196 std::map<AssetClass, std::set<std::string>> result;
204 const Real quantity,
const std::vector<QuantLib::ext::shared_ptr<QuantLib::VanillaOption>>& options,
205 const std::vector<Real>& weights,
const std::vector<Real>& positions,
const std::vector<Handle<Quote>>& fxConversion)
206 : quantity_(quantity), options_(options), weights_(weights), positions_(positions), fxConversion_(fxConversion) {
207 QL_REQUIRE(
options_.size() ==
weights_.size(),
"EquityOptionPositionInstrumentWrapper: options size ("
208 <<
options_.size() <<
") must match weights size ("
211 "EquityPositionInstrumentWrapper: fxConversion size ("
213 for (
auto const& o : options)
215 for (
auto const& fx : fxConversion)
236 QL_REQUIRE(a !=
nullptr,
"wrong argument type in EquityOptionPositionInstrumentWrapper");
246 Instrument::fetchResults(r);
251 for (Size i = 0; i <
arguments_.options_.size(); ++i) {
259 result *=
arguments_.npvCcyConversion_->value();
Abstract engine builders for European and American Options.
const Instrument::results * results_
const std::vector< EquityOptionUnderlyingData > & underlyings() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
std::vector< EquityOptionUnderlyingData > underlyings_
std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > options_
std::vector< Real > positions_
std::vector< QuantLib::ext::shared_ptr< QuantExt::GenericIndex > > indices_
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
void fromXML(XMLNode *node) override
std::vector< Handle< Quote > > fxConversion_
void setNpvCurrencyConversion(const std::string &ccy, const Handle< Quote > &conversion)
XMLNode * toXML(XMLDocument &doc) const override
std::vector< Real > weights_
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
EquityOptionPositionData data_
std::vector< std::string > currencies_
std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > options_
std::vector< Real > positions_
std::vector< Handle< Quote > > fxConversion_
std::vector< Real > weights_
Handle< Quote > npvCcyConversion_
void calculate() const override
void fetchResults(const QuantLib::PricingEngine::results *) const override
std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > options_
std::vector< Real > positions_
bool isExpired() const override
EquityOptionPositionInstrumentWrapper(const Real quantity, const std::vector< QuantLib::ext::shared_ptr< QuantLib::VanillaOption > > &options, const std::vector< Real > &positions, const std::vector< Real > &weights, const std::vector< Handle< Quote > > &fxConversion={})
std::vector< Handle< Quote > > fxConversion_
std::vector< Real > weights_
Handle< Quote > npvCcyConversion_
void setupArguments(QuantLib::PricingEngine::arguments *) const override
void setNpvCurrencyConversion(const Handle< Quote > &npvCcyConversion)
Serializable Equity Option Underlying Data, this represents one underlying in EquityOptionPositionDat...
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
EquityUnderlying underlying_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void fromXML(XMLNode *node) override
void setSensitivityTemplate(const EngineBuilder &builder)
virtual XMLNode * toXML(XMLDocument &doc) const override
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void checkNode(XMLNode *n, const string &expectedName)
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
Equity Option Position trade data model and serialization.
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
#define DLOG(text)
Logging Macro (Level = Debug)
std::string to_string(const LocationInfo &l)
Serializable Credit Default Swap.
Reference data model and serialization.
Swap::arguments * arguments_