Build QuantLib/QuantExt instrument, link pricing engine.
46 {
47 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxBarrierOption");
48
50
54
55
57 Date payDate = expiryDate;
59 if (opd) {
60 if (opd->rulesBased()) {
61 Calendar payCalendar = opd->calendar();
62 payDate = payCalendar.advance(expiryDate, opd->lag(), Days, opd->convention());
63 } else {
64 if (opd->dates().size() > 1)
66 "Found more than 1 payment date. The first one will be used.")
68 payDate = opd->dates().front();
69 }
70 }
71 QL_REQUIRE(payDate >= expiryDate, "Settlement date cannot be earlier than expiry date");
72
74 QL_REQUIRE(rebate >= 0, "rebate must be non-negative");
75
76
77
79
80
81
83 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(type,
strike()));
84
85 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
86
87
88
89 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
90 std::vector<Real> additionalMultipliers;
93
94 QuantLib::ext::shared_ptr<Instrument> vanilla;
95 QuantLib::ext::shared_ptr<Instrument>
barrier;
96 QuantLib::ext::shared_ptr<InstrumentWrapper> instWrapper;
97
98 bool exercised = false;
99 Real exercisePrice = Null<Real>();
100
101 if (payDate > expiryDate) {
102
104 if (oed) {
105 QL_REQUIRE(oed->date() == expiryDate, "The supplied exercise date ("
106 << io::iso_date(oed->date())
107 << ") should equal the option's expiry date ("
108 << io::iso_date(expiryDate) << ").");
109 exercised = true;
110 exercisePrice = oed->price();
111 }
112
113 QuantLib::ext::shared_ptr<Index> index;
116 QL_REQUIRE(index, "Barrier option trade with delayed payment "
117 << id() << ": the FXIndex node needs to be populated.");
119 }
120 vanilla = QuantLib::ext::make_shared<CashSettledEuropeanOption>(payoff->optionType(), payoff->strike(), expiryDate,
122 exercised, exercisePrice);
123 } else {
124 vanilla = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
125 }
126
127 boost::variant<Barrier::Type, DoubleBarrier::Type> barrierType;
130 barrier = QuantLib::ext::make_shared<QuantLib::BarrierOption>(QuantLib::ext::get<Barrier::Type>(barrierType),
barrier_.
levels()[0].value(),
131 rebate, payoff, exercise);
132 } else {
134 barrier = QuantLib::ext::make_shared<QuantLib::DoubleBarrierOption>(QuantLib::ext::get<DoubleBarrier::Type>(barrierType),
136 }
137
138 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> barrierEngine =
barrierPricingEngine(engineFactory, expiryDate, payDate);
139 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> vanillaEngine =
vanillaPricingEngine(engineFactory, expiryDate, payDate);
140
141
142 barrier->setPricingEngine(barrierEngine);
143 vanilla->setPricingEngine(vanillaEngine);
144
145 QuantLib::ext::shared_ptr<QuantLib::Index> index =
getIndex();
146 const QuantLib::Handle<QuantLib::Quote>& spot =
spotQuote();
148 instWrapper = QuantLib::ext::make_shared<SingleBarrierOptionWrapper>(
149 barrier, positionType == Position::Long ?
true :
false, expiryDate,
150 settleType == Settlement::Physical ? true : false, vanilla, QuantLib::ext::get<Barrier::Type>(barrierType),
153 else
154 instWrapper = QuantLib::ext::make_shared<DoubleBarrierOptionWrapper>(
155 barrier, positionType == Position::Long ?
true :
false, expiryDate,
156 settleType == Settlement::Physical ? true : false, vanilla, QuantLib::ext::get<DoubleBarrier::Type>(barrierType),
159
161
162 Calendar fixingCal = index ? index->fixingCalendar() :
calendar_;
164 for (Date d = fixingCal.adjust(
startDate_); d <= expiryDate; d = fixingCal.advance(d, 1 * Days)) {
166 }
167 }
168
169
170 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
173}
const std::string & type() const
std::vector< ore::data::TradeBarrier > levels() const
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > vanillaPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate)=0
virtual std::string indexFixingName()=0
virtual QuantLib::Real tradeMultiplier()=0
virtual Currency tradeCurrency()=0
virtual void checkBarriers()=0
check validity of barriers
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > barrierPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate)=0
virtual const QuantLib::Handle< QuantLib::Quote > & spotQuote()=0
virtual const QuantLib::Real strike()=0
virtual QuantLib::ext::shared_ptr< QuantLib::Index > getIndex()=0
void log() const
generate Boost log record to pass to corresponding sinks
const string & callPut() const
const string & longShort() const
const string & style() const
const string & settlement() const
bool isAutomaticExercise() const
Automatic exercise assumed false if not explicitly provided.
const boost::optional< OptionPaymentData > & paymentData() const
const boost::optional< OptionExerciseData > & exerciseData() const
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
QuantLib::Date latestPremiumDate() 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)
Utility classes for Structured warnings, contains the Trade ID and Type.
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)
RequiredFixings requiredFixings_
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
const string & tradeType() const
DoubleBarrier::Type parseDoubleBarrierType(const std::string &s)
Convert std::string to QuantLib::DoubleBarrierType.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
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.
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.