Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.
49 {
50 DLOG(
"Building Bond Option: " <<
id());
51
52
57
58 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
59 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("BondOption");
62
64 QuantLib::ext::shared_ptr<QuantExt::BondOption> bondoption;
65
66
67 underlying_ = QuantLib::ext::make_shared<ore::data::Bond>(Envelope(), bondData_);
68
70
78
79 auto qlBondInstr = QuantLib::ext::dynamic_pointer_cast<QuantLib::Bond>(
underlying_->instrument()->qlInstrument());
80 QL_REQUIRE(qlBondInstr, "BondOption::build(): could not cast to QuantLib::Bond");
82 QL_REQUIRE(!p, "BondOption::build(): underlying leg must be receiver");
83 }
84
85 boost::variant<QuantLib::Bond::Price, QuantLib::InterestRate> callabilityPrice;
87 if (priceType_ == "Dirty") {
88 callabilityPrice = QuantLib::Bond::Price(
strike_.
value(), QuantLib::Bond::Price::Dirty);
89 } else if (priceType_ == "Clean") {
90 callabilityPrice = QuantLib::Bond::Price(
strike_.
value(), QuantLib::Bond::Price::Clean);
91 } else {
92 QL_FAIL("BondOption::build(): price type \"" << priceType_ << "\" not recognised.");
93 }
94 } else {
95
96 DayCounter dayCounter = Actual365Fixed();
97 Frequency freq = Annual;
98
101 const string& dc = cn.dayCounter();
102 if (!dc.empty())
104 if (cn.schedule().rules().size() > 0)
105 freq =
parsePeriod(cn.schedule().rules().front().tenor()).frequency();
106 }
108 }
109
110 Callability::Type callabilityType =
112
116 QuantLib::ext::shared_ptr<Callability>
callability;
118 CallabilitySchedule callabilitySchedule = std::vector<QuantLib::ext::shared_ptr<Callability>>(1,
callability);
119
121
123
124 QuantLib::ext::shared_ptr<BondOptionEngineBuilder> bondOptionBuilder =
125 QuantLib::ext::dynamic_pointer_cast<BondOptionEngineBuilder>(builder);
126 QL_REQUIRE(bondOptionBuilder, "No Builder found for bondOption: " << id());
127
128 QuantLib::ext::shared_ptr<BlackBondOptionEngine> blackEngine = QuantLib::ext::dynamic_pointer_cast<BlackBondOptionEngine>(
131 bondoption->setPricingEngine(blackEngine);
133
134 Real multiplier =
136
137 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
138 std::vector<Real> additionalMultipliers;
140 multiplier > 0.0 ? -1.0 : 1.0, currency, engineFactory,
141 bondOptionBuilder->configuration(MarketContext::pricing));
142
143 instrument_.reset(
new VanillaInstrument(bondoption, multiplier, additionalInstruments, additionalMultipliers));
144
145
147}
const CallabilitySchedule & callability() const
const boost::shared_ptr< QuantLib::Bond > underlying_
const string & securityId() const
bool hasCreditRisk() const
const string & volatilityCurveId() const
const std::vector< LegData > & coupons() const
void populateFromBondReferenceData(const QuantLib::ext::shared_ptr< BondReferenceDatum > &referenceDatum, const std::string &startDate="", const std::string &endDate="")
populate data from reference datum and check data for completeness
const string & referenceCurveId() const
const string & calendar() const
const string & creditCurveId() const
Real bondNotional() const
BondData originalBondData_
const string & callPut() const
const string & longShort() const
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
QuantLib::Date latestPremiumDate() const
std::vector< bool > legPayers_
std::vector< string > legCurrencies_
std::vector< QuantLib::Leg > legs_
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_
const QuantLib::Compounding & compounding()
QuantLib::Real value() const
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
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.
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
#define DLOG(text)
Logging Macro (Level = Debug)