34#include <ql/errors.hpp>
35#include <ql/exercise.hpp>
36#include <ql/instruments/barrieroption.hpp>
38#include <boost/make_shared.hpp>
46 const string& currency, Real notional,
const QuantLib::ext::shared_ptr<ore::data::Underlying>& underlying1,
47 const QuantLib::ext::shared_ptr<ore::data::Underlying>& underlying2,
48 Real initialPrice1, Real initialPrice2, Real strike,
const string& initialPriceCurrency1,
const string& initialPriceCurrency2,
49 Real knockInPrice, Real knockOutPrice,
string fxIndex1,
string fxIndex2)
50 :
Trade(
"EquityOutperformanceOption", env), option_(option), currency_(currency),
amount_(notional),
51 underlying1_(underlying1), underlying2_(underlying2), initialPrice1_(initialPrice1), initialPrice2_(initialPrice2),
52 strikeReturn_(strike), knockInPrice_(knockInPrice), knockOutPrice_(knockOutPrice), initialPriceCurrency1_(initialPriceCurrency1),
53 initialPriceCurrency2_(initialPriceCurrency2), fxIndex1_(fxIndex1), fxIndex2_(fxIndex2) {
58 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
65 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex1 =
nullptr;
66 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex2 =
nullptr;
73 auto eqCurve1 = *engineFactory->market()->equityCurve(
name1());
74 Currency eqCurrency1 = eqCurve1->currency();
77 if (ccy1 != eqCurrency1) {
78 QL_REQUIRE(!
fxIndex1_.empty(),
"FX settlement index must be specified: " << ccy1 <<
" " << eqCurrency1 <<
" " <<
fxIndex1_);
89 auto eqCurve2 = *engineFactory->market()->equityCurve(
name2());
90 Currency eqCurrency2 = eqCurve2->currency();
93 if (ccy2 != eqCurrency2) {
94 QL_REQUIRE(!
fxIndex2_.empty(),
"FX settlement index must be specified");
101 QuantLib::ext::shared_ptr<Exercise> exercise;
102 exercise = QuantLib::ext::make_shared<EuropeanExercise>(valuationDate);
107 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(
tradeType_);
108 QL_REQUIRE(builder,
"No builder found for " <<
tradeType_);
109 QuantLib::ext::shared_ptr<EquityOutperformanceOptionEngineBuilder> eqOptBuilder = QuantLib::ext::dynamic_pointer_cast<EquityOutperformanceOptionEngineBuilder>(builder);
111 inst->setPricingEngine(eqOptBuilder->engine(
name1(),
name2(), ccy));
116 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
119 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
120 std::vector<Real> additionalMultipliers;
124 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
new VanillaInstrument(inst, mult, additionalInstruments, additionalMultipliers));
134 QL_REQUIRE(eqNode,
"No EquityOutperformanceOptionData Node");
152 underlyingBuilder1.
fromXML(tmp1);
163 underlyingBuilder2.
fromXML(tmp2);
Wrapper for option instruments, tracks whether option has been exercised or not.
Serializable object holding generic trade data, reporting dimensions.
Serializable object holding option data.
const string & callPut() const
const string & longShort() const
const string & style() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
virtual void fromXML(XMLNode *node) override
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 setSensitivityTemplate(const EngineBuilder &builder)
virtual XMLNode * toXML(XMLDocument &doc) const override
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
const QuantLib::ext::shared_ptr< Underlying > & underlying()
void fromXML(XMLNode *node) override
Vanilla Instrument Wrapper.
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
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)
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
QuantLib::Real convertMinorToMajorCurrency(const std::string &s, QuantLib::Real value)
Convert a value from a minor ccy to major.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
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.
Map text representations to QuantLib/QuantExt types.
leg data model and serialization
Classes and functions for log message handling.
market data related utilties
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)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.