23#include <boost/lexical_cast.hpp>
30 static const std::string best_of_asset_or_cash_rainbow_option_script =
31 " REQUIRE SIZE(Underlyings) == SIZE(Weights);\n"
32 " NUMBER u, thisPrice, bestPrice, Payoff, currentNotional;\n"
33 " NUMBER expUnderValue[SIZE(Underlyings)];\n"
34 " bestPrice = Strike;\n"
35 " FOR u IN (1, SIZE(Underlyings), 1) DO\n"
36 " expUnderValue[u] = Underlyings[u](Expiry);\n"
37 " thisPrice = Underlyings[u](Expiry) * Weights[u];\n"
38 " IF thisPrice > bestPrice THEN\n"
39 " bestPrice = thisPrice;\n"
42 " Option = LongShort * Notional * PAY(bestPrice, Expiry, Settlement, PayCcy);\n"
43 " currentNotional = Notional * Strike;\n";
45 static const std::string worst_of_asset_or_cash_rainbow_option_script =
46 " REQUIRE SIZE(Underlyings) == SIZE(Weights);\n"
47 " NUMBER u, thisPrice, worstPrice, Payoff, currentNotional;\n"
48 " NUMBER expUnderValue[SIZE(Underlyings)];\n"
49 " worstPrice = Strike;\n"
50 " FOR u IN (1, SIZE(Underlyings), 1) DO\n"
51 " expUnderValue[u] = Underlyings[u](Expiry);\n"
52 " thisPrice = Underlyings[u](Expiry) * Weights[u];\n"
53 " IF thisPrice < worstPrice THEN\n"
54 " worstPrice = thisPrice;\n"
57 " Option = LongShort * Notional * PAY(worstPrice, Expiry, Settlement, PayCcy);\n"
58 " currentNotional = Notional * Strike;\n";
60 static const std::string max_rainbow_option_script =
61 " REQUIRE SIZE(Underlyings) == SIZE(Weights);\n"
63 " NUMBER u, thisPrice, maxPrice, Payoff, ExerciseProbability, currentNotional;\n"
64 " NUMBER expUnderValue[SIZE(Underlyings)];\n"
66 " FOR u IN (1, SIZE(Underlyings), 1) DO\n"
67 " expUnderValue[u] = Underlyings[u](Expiry);\n"
68 " thisPrice = Underlyings[u](Expiry) * Weights[u];\n"
69 " IF thisPrice > maxPrice THEN\n"
70 " maxPrice = thisPrice;\n"
74 " Payoff = max(PutCall * (maxPrice - Strike), 0);\n"
76 " Option = LongShort * Notional * PAY(Payoff, Expiry, Settlement, PayCcy);\n"
78 " IF Payoff > 0 THEN\n"
79 " ExerciseProbability = 1;\n"
81 " currentNotional = Notional * Strike;\n";
83 static const std::string min_rainbow_option_script =
84 " REQUIRE SIZE(Underlyings) == SIZE(Weights);\n"
85 " REQUIRE SIZE(Underlyings) > 0;\n"
87 " NUMBER u, thisPrice, minPrice, Payoff, ExerciseProbability, currentNotional;\n"
88 " NUMBER expUnderValue[SIZE(Underlyings)];\n"
89 " minPrice = Underlyings[1](Expiry) * Weights[1];\n"
90 " FOR u IN (1, SIZE(Underlyings), 1) DO\n"
91 " expUnderValue[u] = Underlyings[u](Expiry);\n"
92 " thisPrice = Underlyings[u](Expiry) * Weights[u];\n"
93 " IF thisPrice < minPrice THEN\n"
94 " minPrice = thisPrice;\n"
98 " Payoff = max(PutCall * (minPrice - Strike), 0);\n"
100 " Option = LongShort * Notional * PAY(Payoff, Expiry, Settlement, PayCcy);\n"
102 " IF Payoff > 0 THEN\n"
103 " ExerciseProbability = 1;\n"
105 " currentNotional = Notional * Strike;\n";
121 numbers_.emplace_back(
"Number",
"LongShort",
128 std::string scriptToUse;
130 scriptToUse = best_of_asset_or_cash_rainbow_option_script;
132 scriptToUse = worst_of_asset_or_cash_rainbow_option_script;
134 scriptToUse = max_rainbow_option_script;
137 scriptToUse = min_rainbow_option_script;
150 {{
"currentNotional",
"currentNotional"},
151 {
"notionalCurrency",
"PayCcy"},
152 {
"expectedUnderlyingValue",
"expUnderValue"}},
165 std::string assetClass = boost::any_cast<std::string>(
additionalData_[
"isdaAssetClass"]);
166 if (assetClass ==
"Equity") {
168 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
170 else if (assetClass ==
"Commodity") {
173 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
175 else if (assetClass ==
"Foreign Exchange") {
180 WLOG(
"ISDA taxonomy incomplete for trade " <<
id());
186 std::vector<std::string> underlyings, weights;
189 QL_REQUIRE(u->weight() != Null<Real>(),
"underlying '" << u->name() <<
"' has no weight");
190 weights.push_back(boost::lexical_cast<std::string>(u->weight()));
192 indices_.emplace_back(
"Index",
"Underlyings", underlyings);
193 numbers_.emplace_back(
"Number",
"Weights", weights);
199 QL_REQUIRE(dataNode,
tradeType() +
"Data node not found");
204 QL_REQUIRE(underlyingsNode,
"No Underlyings node");
206 for (
auto const& n : underlyings) {
const string & callPut() const
const string & payoffType() const
const string & longShort() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const vector< string > & exerciseDates() const
void setIsdaTaxonomyFields() override
std::vector< QuantLib::ext::shared_ptr< Underlying > > underlyings_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
std::vector< ScriptedTradeEventData > events_
std::vector< ScriptedTradeValueTypeData > currencies_
std::vector< ScriptedTradeValueTypeData > indices_
virtual void setIsdaTaxonomyFields()
std::vector< ScriptedTradeValueTypeData > numbers_
std::map< std::string, ScriptedTradeScriptData > script_
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & tradeType() const
std::map< std::string, boost::any > additionalData_
const QuantLib::ext::shared_ptr< Underlying > & underlying()
void fromXML(XMLNode *node) override
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
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)
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 WLOG(text)
Logging Macro (Level = Warning)
QL_DEPRECATED_ENABLE_WARNING std::string scriptedIndexName(const QuantLib::ext::shared_ptr< Underlying > &underlying)
Serializable Credit Default Swap.
rainbow option wrapper for scripted trade
string conversion utilities