Build QuantLib/QuantExt instrument, link pricing engine.
61 {
62
63
66 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
67
69
70 Date today = Settings::instance().evaluationDate();
71 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
72
73
80 if (barrierType == Barrier::DownIn || barrierType == Barrier::DownOut)
81 type = Option::Type::Put;
82 else
83 type = Option::Type::Call;
88
89 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for EquityOption");
91 QL_REQUIRE(
barrier_.
levels().size() == 1,
"Double barriers not supported for EquityTouchOptions");
93 QL_REQUIRE(rebate == 0, "Rebates not supported for EquityTouchOptions");
94 QL_REQUIRE(payoffAtExpiry == true || barrierType == Barrier::Type::DownIn || barrierType == Barrier::Type::UpIn,
95 "Payoff at hit not supported for EquityNoTouchOptions");
96
97
98 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new CashOrNothingPayoff(
type, level, 1.0));
99 Leg leg;
100
101 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(new SimpleCashFlow(1.0, expiryDate)));
102
103 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<AmericanExercise>(expiryDate, payoffAtExpiry);
104
105 QuantLib::ext::shared_ptr<Instrument>
barrier = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
106 QuantLib::ext::shared_ptr<Instrument> underlying = QuantLib::ext::make_shared<Swap>(Leg(), leg);
107
108 QL_REQUIRE(
eqIndex_ !=
"",
"No eqIndex provided");
109 QL_REQUIRE(
calendar_ !=
"",
"No calendar provided");
110
112
113
114 bool triggered = false;
115 Calendar cal =
eqIndex->fixingCalendar();
117
118 Date d = start;
119
120 while (d < today && !triggered) {
121
122 Real fixing =
eqIndex->pastFixing(d);
123
124 if (fixing == 0.0 || fixing == Null<Real>()) {
125 ALOG(
"Got invalid Equity fixing for index " <<
eqIndex_ <<
" on " << d
126 << "Skipping this date, assuming no trigger");
127 } else {
129 }
130
131 d = cal.advance(d, 1, Days);
132 }
133 }
134
135
136 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(
tradeType_);
137 QL_REQUIRE(builder,
"No builder found for " <<
tradeType_);
138 QuantLib::ext::shared_ptr<EquityTouchOptionEngineBuilder> eqTouchOptBuilder =
139 QuantLib::ext::dynamic_pointer_cast<EquityTouchOptionEngineBuilder>(builder);
140 barrier->setPricingEngine(eqTouchOptBuilder->engine(assetName, ccy,
type_));
142 if (
type_ ==
"One-Touch") {
143
144
145 builder = engineFactory->builder("Swap");
146 QL_REQUIRE(builder, "No builder found for Swap");
147 QuantLib::ext::shared_ptr<SwapEngineBuilderBase> swapBuilder =
148 QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
149 underlying->setPricingEngine(swapBuilder->engine(ccy, std::string(), std::string()));
150 }
151
152 bool isLong = (positionType == Position::Long) ? true : false;
153
154 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
155 std::vector<Real> additionalMultipliers;
159
160 Handle<Quote> spot = market->equitySpot(assetName);
161 instrument_ = QuantLib::ext::make_shared<SingleBarrierOptionWrapper>(
162 barrier, isLong, expiryDate,
false, underlying, barrierType, spot, level, rebate, ccy, start,
eqIndex, cal,
payoffAmount_,
163 payoffAmount_, additionalInstruments, additionalMultipliers);
167 maturity_ = std::max(lastPremiumDate, expiryDate);
168
169 if (start != Date()) {
170 for (Date d = start; d <= expiryDate; d = cal.advance(d, 1 * Days))
172 }
173
176}
std::vector< ore::data::TradeBarrier > levels() const
const std::string & style() const
const string & equityName() const
const string & type() const
bool checkBarrier(Real spot, Barrier::Type type, Real level)
const string & longShort() const
const bool & payoffAtExpiry() const
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
TradeActions & tradeActions()
Set the trade actions.
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)
RequiredFixings requiredFixings_
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > parseEquityIndex(const string &s)
Convert std::string (e.g SP5) to QuantExt::EquityIndex.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
#define ALOG(text)
Logging Macro (Level = Alert)