Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
autocallable_01.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17 */
18
21
22namespace ore {
23namespace data {
24
25void Autocallable_01::build(const QuantLib::ext::shared_ptr<EngineFactory>& factory) {
26
27 // set script parameters
28
29 clear();
31
32 numbers_.emplace_back("Number", "NotionalAmount", notionalAmount_);
33 numbers_.emplace_back("Number", "DeterminationLevel", determinationLevel_);
34 numbers_.emplace_back("Number", "TriggerLevel", triggerLevel_);
35
36 Position::Type position = parsePositionType(position_);
37 numbers_.emplace_back("Number", "LongShort", position == Position::Long ? "1" : "-1");
38
39 currencies_.emplace_back("Currency", "PayCcy", payCcy_);
40
41 events_.emplace_back("FixingDates", fixingDates_);
42 events_.emplace_back("SettlementDates", settlementDates_);
43
44 numbers_.emplace_back("Number", "AccumulationFactors", accumulationFactors_);
45 numbers_.emplace_back("Number", "Cap", cap_);
46
47 // set product tag
48
49 productTag_ = "MultiAssetOption({AssetClass})";
50
51 // set script
52
54 "NUMBER i, terminated, currentNotional;\n"
55 "FOR i IN (1, SIZE(FixingDates), 1) DO\n"
56 " IF terminated == 0 AND Underlying(FixingDates[i]) <= TriggerLevel THEN\n"
57 " Option = LOGPAY( LongShort * NotionalAmount * AccumulationFactors[i], FixingDates[i],\n"
58 " SettlementDates[i], PayCcy);\n"
59 " terminated = 1;\n"
60 " END;\n"
61 " IF terminated == 0 AND i == SIZE(FixingDates) AND Underlying(FixingDates[i]) > "
62 "DeterminationLevel THEN\n"
63 " Option = LOGPAY( -LongShort * NotionalAmount * min( Cap, Underlying(FixingDates[i]) -\n"
64 " DeterminationLevel ),\n"
65 " FixingDates[i], SettlementDates[i], PayCcy);\n"
66 " END;\n"
67 "END;\n",
68 "Option", {{"currentNotional", "NotionalAmount"}, {"notionalCurrency", "PayCcy"}}, {})}};
69
70 // build trade
71
72 ScriptedTrade::build(factory);
73}
74
77
78 // ISDA taxonomy, asset class set in the base class build
79 // asset class set in the base class already
80 std::string assetClass = boost::any_cast<std::string>(additionalData_["isdaAssetClass"]);
81 if (assetClass == "Equity") {
82 additionalData_["isdaBaseProduct"] = string("Other");
83 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
84 }
85 else if (assetClass == "Commodity") {
86 // isda taxonomy missing for this class, using the same as equity
87 additionalData_["isdaBaseProduct"] = string("Other");
88 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
89 }
90 else if (assetClass == "Foreign Exchange") {
91 additionalData_["isdaBaseProduct"] = string("Exotic");
92 additionalData_["isdaSubProduct"] = string("Target");
93 }
94 else {
95 WLOG("ISDA taxonomy incomplete for trade " << id());
96 }
97 additionalData_["isdaTransaction"] = string("");
98}
99
100void Autocallable_01::initIndices() { indices_.emplace_back("Index", "Underlying", scriptedIndexName(underlying_)); }
101
103 Trade::fromXML(node);
104 XMLNode* tradeDataNode = XMLUtils::getChildNode(node, "Autocallable01Data");
105 QL_REQUIRE(tradeDataNode, "Autocallable01Data node not found");
106 notionalAmount_ = XMLUtils::getChildValue(tradeDataNode, "NotionalAmount");
107 determinationLevel_ = XMLUtils::getChildValue(tradeDataNode, "DeterminationLevel");
108 triggerLevel_ = XMLUtils::getChildValue(tradeDataNode, "TriggerLevel");
109
110 XMLNode* tmp = XMLUtils::getChildNode(tradeDataNode, "Underlying");
111 if (!tmp)
112 tmp = XMLUtils::getChildNode(tradeDataNode, "Name");
113 UnderlyingBuilder underlyingBuilder;
114 underlyingBuilder.fromXML(tmp);
115 underlying_ = underlyingBuilder.underlying();
116
117 position_ = XMLUtils::getChildValue(tradeDataNode, "Position", true);
118 payCcy_ = XMLUtils::getChildValue(tradeDataNode, "PayCcy", true);
119 fixingDates_.fromXML(XMLUtils::getChildNode(XMLUtils::getChildNode(tradeDataNode, "FixingDates"), "ScheduleData"));
121 XMLUtils::getChildNode(XMLUtils::getChildNode(tradeDataNode, "SettlementDates"), "ScheduleData"));
122 accumulationFactors_ = XMLUtils::getChildrenValues(tradeDataNode, "AccumulationFactors", "Factor");
123 cap_ = XMLUtils::getChildValue(tradeDataNode, "Cap");
124 initIndices();
125}
126
128 XMLNode* node = Trade::toXML(doc);
129 XMLNode* tradeNode = doc.allocNode("Autocallable01Data");
130 XMLUtils::appendNode(node, tradeNode);
131 XMLUtils::addChild(doc, tradeNode, "NotionalAmount", notionalAmount_);
132 XMLUtils::addChild(doc, tradeNode, "DeterminationLevel", determinationLevel_);
133 XMLUtils::addChild(doc, tradeNode, "TriggerLevel", triggerLevel_);
134 XMLUtils::appendNode(tradeNode, underlying_->toXML(doc));
135 XMLUtils::addChild(doc, tradeNode, "Position", position_);
136 XMLUtils::addChild(doc, tradeNode, "PayCcy", payCcy_);
137 XMLNode* f = doc.allocNode("FixingDates");
139 XMLUtils::appendNode(tradeNode, f);
140 XMLNode* s = doc.allocNode("SettlementDates");
142 XMLUtils::appendNode(tradeNode, s);
143 XMLUtils::addChildren(doc, tradeNode, "AccumulationFactors", "Factor", accumulationFactors_);
144 XMLUtils::addChild(doc, tradeNode, "Cap", cap_);
145 return node;
146}
147
148} // namespace data
149} // namespace ore
autocallable_01 wrapper for scripted trade
void setIsdaTaxonomyFields() override
vector< string > accumulationFactors_
void fromXML(XMLNode *node) override
QuantLib::ext::shared_ptr< Underlying > underlying_
XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
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
Definition: trade.cpp:34
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
const QuantLib::ext::shared_ptr< Underlying > & underlying()
Definition: underlying.hpp:266
void fromXML(XMLNode *node) override
Definition: underlying.cpp:305
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
Definition: xmlutils.cpp:502
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
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
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
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
@ data
Definition: log.hpp:77
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
QL_DEPRECATED_ENABLE_WARNING std::string scriptedIndexName(const QuantLib::ext::shared_ptr< Underlying > &underlying)
Definition: utilities.cpp:614
Serializable Credit Default Swap.
Definition: namespaces.docs:23
some utility functions