47 string barrierTypeVal;
48 if (barrierType == Barrier::Type::DownIn)
50 else if (barrierType == Barrier::Type::UpIn)
52 else if (barrierType == Barrier::Type::DownOut)
54 else if (barrierType == Barrier::Type::UpOut)
57 QL_FAIL(
"Unknown Barrier Type: " << barrierType);
58 numbers_.emplace_back(
"Number",
"BarrierType", barrierTypeVal);
63 numbers_.emplace_back(
"Number",
"PutCall", putCall == Option::Call ?
"1" :
"-1");
66 numbers_.emplace_back(
"Number",
"LongShort", longShort == Position::Long ?
"1" :
"-1");
93 " REQUIRE Quantity >= 0;\n"
94 " REQUIRE PremiumDate <= SettlementDate;\n"
95 " REQUIRE OptionExpiry <= SettlementDate;\n"
97 " NUMBER barrierFixing, finalPrice, exercisePayoff, premium;\n"
98 " NUMBER notKnocked, factor, currentNotional, exerciseProbability;\n"
102 " IF BarrierStyle == -1 THEN\n"
103 " barrierFixing = BarrierUnderlying(OptionExpiry);\n"
104 " finalPrice = OptionUnderlying(OptionExpiry);\n"
106 " IF {BarrierType == 1 AND barrierFixing <= BarrierLevel}\n"
107 " OR {BarrierType == 2 AND barrierFixing >= BarrierLevel}\n"
108 " OR {BarrierType == 3 AND barrierFixing > BarrierLevel}\n"
109 " OR {BarrierType == 4 AND barrierFixing < BarrierLevel} THEN\n"
110 " exercisePayoff = LOGPAY(LongShort * Quantity * max(0, PutCall * (finalPrice - Strike)),\n"
111 " OptionExpiry, SettlementDate, PayCcy, 1, ExercisePayoff);\n"
116 " FOR d IN (2, SIZE(BarrierSchedule), 1) DO\n"
117 " IF BarrierType == 1 OR BarrierType == 3 THEN\n"
118 " notKnocked = notKnocked * (1 - BELOWPROB(BarrierUnderlying, BarrierSchedule[d-1],\n"
119 " BarrierSchedule[d], BarrierLevel));\n"
121 " notKnocked = notKnocked * (1 - ABOVEPROB(BarrierUnderlying, BarrierSchedule[d-1],\n"
122 " BarrierSchedule[d], BarrierLevel));\n"
126 " IF BarrierType == 1 OR BarrierType == 2 THEN\n"
127 " factor = 1 - notKnocked;\n"
129 " factor = notKnocked;\n"
132 " finalPrice = OptionUnderlying(OptionExpiry);\n"
133 " exercisePayoff = LOGPAY(Quantity * factor * max(0, PutCall * (finalPrice - Strike)),\n"
134 " OptionExpiry, SettlementDate, PayCcy, 1, ExercisePayoff);\n"
137 " premium = LOGPAY(Quantity * PremiumAmount, PremiumDate,\n"
138 " PremiumDate, PremiumCurrency, 0, Premium);\n"
140 " IF exercisePayoff != 0 THEN\n"
141 " exerciseProbability = 1;\n"
144 " currentNotional = Quantity * Strike;"
145 " Option = LongShort * (exercisePayoff - premium);\n",
148 {{
"ExerciseProbability",
"exerciseProbability"},
149 {
"currentNotional",
"currentNotional"},
150 {
"notionalCurrency",
"PayCcy"}},
166 QL_REQUIRE(tradeDataNode,
"EuropeanOptionBarrierData node not found");
180 optionUnderlyingBuilder.
fromXML(tmp);
187 barrierUnderlyingBuilder.
fromXML(tmp);
QuantLib::ext::shared_ptr< Underlying > barrierUnderlying_
QuantLib::ext::shared_ptr< Underlying > optionUnderlying_
ScheduleData barrierSchedule_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
std::vector< ScriptedTradeEventData > events_
std::vector< ScriptedTradeValueTypeData > currencies_
std::vector< ScriptedTradeValueTypeData > indices_
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 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 string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static void setNodeName(XMLDocument &doc, XMLNode *node, const string &name)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
European option with barrier wrapper for scripted trade.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Barrier::Type parseBarrierType(const std::string &s)
Convert std::string to QuantLib::BarrierType.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
#define LOG(text)
Logging Macro (Level = Notice)
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.