24#include <boost/lexical_cast.hpp>
31static const std::string window_barrier_script =
32 "REQUIRE BarrierType == 1 OR BarrierType == 2 OR BarrierType == 3 OR BarrierType == 4;\n"
34 "NUMBER i, Payoff, TriggerProbability, ExerciseProbability, isUp, currentNotional;\n"
36 "IF BarrierType == 1 OR BarrierType == 3 THEN\n"
37 " TriggerProbability = BELOWPROB(Underlying, StartDate, EndDate, BarrierLevel);\n"
39 " TriggerProbability = ABOVEPROB(Underlying, StartDate, EndDate, BarrierLevel);\n"
42 "Payoff = Quantity * PutCall * (Underlying(Expiry) - Strike);\n"
43 "IF Payoff > 0.0 THEN\n"
44 " IF BarrierType == 1 OR BarrierType == 2 THEN\n"
45 " Option = PAY(Payoff * TriggerProbability, Expiry, Settlement, PayCcy);\n"
46 " ExerciseProbability = TriggerProbability;\n"
48 " Option = PAY(Payoff * (1 - TriggerProbability), Expiry, Settlement, PayCcy);\n"
49 " ExerciseProbability = (1 - TriggerProbability);\n"
53 "Option = LongShort * Option;\n"
54 "currentNotional = Quantity * Strike;\n";
75 numbers_.emplace_back(
"Number",
"LongShort", positionType == Position::Long ?
"1" :
"-1");
76 numbers_.emplace_back(
"Number",
"PutCall",
85 "WindowBarrierOption: exactly one payment date required under PaymentData/Dates/Date");
87 events_.emplace_back(
"Settlement", settlementDate);
89 std::string barrierType;
93 "WindowBarrierOption: exactly one barrier level required, got " <<
barrier_.
levels().size());
103 QL_FAIL(
"WindowBarrierOption: invalid barrier level " <<
barrier_.
type());
105 numbers_.emplace_back(
"Number",
"BarrierType", barrierType);
106 numbers_.emplace_back(
"Number",
"BarrierLevel", boost::lexical_cast<std::string>(
barrier_.
levels().front().value()));
115 window_barrier_script,
"Option",
116 {{
"currentNotional",
"currentNotional"},
117 {
"notionalCurrency",
"PayCcy"},
118 {
"TriggerProbability",
"TriggerProbability"},
119 {
"ExerciseProbability",
"ExerciseProbability"}},
134 std::string assetClass = boost::any_cast<std::string>(
additionalData_[
"isdaAssetClass"]);
135 if (assetClass ==
"Equity") {
137 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
138 }
else if (assetClass ==
"Commodity") {
141 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
142 }
else if (assetClass ==
"Foreign Exchange") {
146 WLOG(
"ISDA taxonomy incomplete for trade " <<
id());
157 QL_REQUIRE(dataNode,
tradeType() +
"Data node not found");
167 underlyingBuilder.
fromXML(tmp);
175 QL_REQUIRE(barrierNode,
"No BarrierData node");
const std::string & type() const
virtual void fromXML(ore::data::XMLNode *node) override
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::vector< ore::data::TradeBarrier > levels() const
const std::string & style() const
const string & callPut() const
const string & longShort() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const boost::optional< OptionPaymentData > & paymentData() const
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
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_
XMLNode * toXML(XMLDocument &doc) const
void setCurrency(const std::string ¤cy)
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
QuantLib::Real value() const
const QuantLib::ext::shared_ptr< Underlying > & underlying()
void fromXML(XMLNode *node) override
void setIsdaTaxonomyFields() override
void fromXML(XMLNode *node) override
QuantLib::ext::shared_ptr< Underlying > underlying_
XMLNode * toXML(XMLDocument &doc) const override
std::string fixingAmount_
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
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.
Map text representations to QuantLib/QuantExt types.
string conversion utilities
window barrier option - wrapper for scripted trade