Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Swaption Class Reference

Serializable Swaption. More...

#include <ored/portfolio/swaption.hpp>

+ Inheritance diagram for Swaption:
+ Collaboration diagram for Swaption:

Public Member Functions

 Swaption ()
 
 Swaption (const Envelope &env, const OptionData &optionData, const vector< LegData > &legData)
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
Inspectors
const OptionDataoptionData () const
 
const vector< LegData > & legData ()
 
- Public Member Functions inherited from Trade
 Trade ()
 Default constructor. More...
 
 Trade (const string &tradeType, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Base class constructor. More...
 
virtual ~Trade ()
 Default destructor. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &)=0
 
virtual std::map< std::string, RequiredFixings::FixingDatesfixings (const QuantLib::Date &settlementDate=QuantLib::Date()) const
 
const RequiredFixingsrequiredFixings () const
 
virtual std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const
 
void reset ()
 Reset trade, clear all base class data. This does not reset accumulated timings for this trade. More...
 
void resetPricingStats (const std::size_t numberOfPricings=0, const boost::timer::nanosecond_type cumulativePricingTime=0)
 Reset accumulated timings to given values. More...
 
string & id ()
 Set the trade id. More...
 
void setEnvelope (const Envelope &envelope)
 Set the envelope with counterparty and portfolio info. More...
 
void setAdditionalData (const std::map< std::string, boost::any > &additionalData)
 
TradeActionstradeActions ()
 Set the trade actions. More...
 
const string & id () const
 
const string & tradeType () const
 
const Envelopeenvelope () const
 
const set< string > & portfolioIds () const
 
const TradeActionstradeActions () const
 
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument () const
 
const std::vector< QuantLib::Leg > & legs () const
 
const std::vector< string > & legCurrencies () const
 
const std::vector< bool > & legPayers () const
 
const string & npvCurrency () const
 
virtual string notionalCurrency () const
 
const Date & maturity () const
 
virtual bool isExpired (const Date &d)
 
const string & issuer () const
 
template<typename T >
additionalDatum (const std::string &tag) const
 returns any additional datum. More...
 
const std::string & sensitivityTemplate () const
 
void validate () const
 Utility to validate that everything that needs to be set in this base class is actually set. More...
 
boost::timer::nanosecond_type getCumulativePricingTime () const
 Get cumulative timing spent on pricing. More...
 
std::size_t getNumberOfPricings () const
 Get number of pricings. More...
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Serialisation

OptionData optionData_
 
vector< LegDatalegData_
 
QuantLib::ext::shared_ptr< ore::data::Swapunderlying_
 
QuantLib::ext::shared_ptr< ExerciseBuilderexerciseBuilder_
 
Position::Type positionType_
 
Exercise::Type exerciseType_
 
Settlement::Type settlementType_
 
Settlement::Method settlementMethod_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
const std::map< std::string, boost::any > & additionalData () const override
 returns all additional data returned by the trade once built More...
 
bool hasCashflows () const override
 
bool isExercised () const
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 
std::vector< QuantLib::ext::shared_ptr< Instrument > > buildUnderlyingSwaps (const QuantLib::ext::shared_ptr< PricingEngine > &, const std::vector< Date > &)
 build underlying swaps for exposure simulation More...
 

Additional Inherited Members

- Protected Member Functions inherited from Trade
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 setLegBasedAdditionalData (const Size legNo, Size resultLegId=Null< Size >()) const
 
void setSensitivityTemplate (const EngineBuilder &builder)
 
void setSensitivityTemplate (const std::string &id)
 
- Protected Attributes inherited from Trade
string tradeType_
 
QuantLib::ext::shared_ptr< InstrumentWrapperinstrument_
 
std::vector< QuantLib::Leg > legs_
 
std::vector< string > legCurrencies_
 
std::vector< boollegPayers_
 
string npvCurrency_
 
QuantLib::Real notional_
 
string notionalCurrency_
 
Date maturity_
 
string issuer_
 
string sensitivityTemplate_
 
bool sensitivityTemplateSet_ = false
 
std::size_t savedNumberOfPricings_ = 0
 
boost::timer::nanosecond_type savedCumulativePricingTime_ = 0
 
RequiredFixings requiredFixings_
 
std::map< std::string, boost::any > additionalData_
 

Detailed Description

Serializable Swaption.

Definition at line 39 of file swaption.hpp.

Constructor & Destructor Documentation

◆ Swaption() [1/2]

Swaption ( )

Definition at line 41 of file swaption.hpp.

41: Trade("Swaption") {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ Swaption() [2/2]

Swaption ( const Envelope env,
const OptionData optionData,
const vector< LegData > &  legData 
)

Definition at line 42 of file swaption.hpp.

43 : Trade("Swaption", env), optionData_(optionData), legData_(legData) {}
OptionData optionData_
Definition: swaption.hpp:69
vector< LegData > legData_
Definition: swaption.hpp:70
const vector< LegData > & legData()
Definition: swaption.hpp:50
const OptionData & optionData() const
Definition: swaption.hpp:49

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< EngineFactory > &  )
overridevirtual

Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.

Implements Trade.

Definition at line 62 of file swaption.cpp.

62 {
63
64 DLOG("Swaption::build() for " << id());
65
66 // 1 ISDA taxonomy
67
68 additionalData_["isdaAssetClass"] = string("Interest Rate");
69 additionalData_["isdaBaseProduct"] = string("Option");
70 additionalData_["isdaSubProduct"] = string("Swaption");
71 additionalData_["isdaTransaction"] = string("");
72
73 // 4 fill currencies and set notional to null (will be retrieved via notional())
74
75 npvCurrency_ = notionalCurrency_ = "USD"; // only if no legs are given, not relevant in this case
76
77 if (!legData_.empty()) {
78 npvCurrency_ = notionalCurrency_ = legData_[0].currency();
79 }
80
81 // 2 build underlying swap and copy its required fixings
82
83 underlying_ = QuantLib::ext::make_shared<ore::data::Swap>(Envelope(), legData_);
84 underlying_->build(engineFactory);
85 requiredFixings_.addData(underlying_->requiredFixings());
86
87 // 3 build the exercise and parse some fields
88
89 DLOG("Swaption::build() for " << id() << ": build exercise");
90
91 exerciseBuilder_ = QuantLib::ext::make_shared<ExerciseBuilder>(optionData_, underlying_->legs());
92
95 settlementMethod_ = optionData_.settlementMethod() == "" ? defaultSettlementMethod(settlementType_)
96 : parseSettlementMethod(optionData_.settlementMethod());
98
99 notional_ = Null<Real>();
100
101 Date today = Settings::instance().evaluationDate();
102
103 // 5 if the swaption is exercised (as per option data / exercise data), build the cashflows that remain to be paid
104
105 if (exerciseBuilder_->isExercised()) {
106 Date exerciseDate = exerciseBuilder_->exerciseDate();
107 maturity_ = std::max(today, exerciseDate); // will be updated below
108
109 if (optionData_.settlement() == "Physical") {
110
111 // 5.1 if physical exercise, inlcude the "exercise-into" cashflows of the underlying
112
113 for (Size i = 0; i < underlying_->legs().size(); ++i) {
114 legs_.push_back(Leg());
115 legCurrencies_.push_back(underlying_->legCurrencies()[i]);
116 legPayers_.push_back(underlying_->legPayers()[i]);
117 for (auto const& c : underlying_->legs()[i]) {
118 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(c)) {
119 if (exerciseDate <= cpn->accrualStartDate()) {
120 legs_.back().push_back(c);
121 maturity_ = std::max(maturity_, c->date());
122 if (notional_ == Null<Real>())
123 notional_ = cpn->nominal();
124 }
125 } else if (exerciseDate <= c->date()) {
126 legs_.back().push_back(c);
127 maturity_ = std::max(maturity_, c->date());
128 }
129 }
130 }
131
132 } else {
133
134 // 5.2 if cash exercise, include the cashSettlement payment
135
136 if (exerciseBuilder_->cashSettlement()) {
137 legs_.push_back(Leg());
138 legs_.back().push_back(exerciseBuilder_->cashSettlement());
139 legCurrencies_.push_back(npvCurrency_);
140 legPayers_.push_back(false);
141 maturity_ = std::max(maturity_, exerciseBuilder_->cashSettlement()->date());
142 }
143 }
144
145 // 5.3 include the exercise fee payment
146
147 if (exerciseBuilder_->feeSettlement()) {
148 legs_.push_back(Leg());
149 legs_.back().push_back(exerciseBuilder_->feeSettlement());
150 legCurrencies_.push_back(npvCurrency_);
151 legPayers_.push_back(true);
152 maturity_ = std::max(maturity_, exerciseBuilder_->feeSettlement()->date());
153 }
154
155 // 5.4 add unconditional premiums, build instrument (as swap) and exit
156
157 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
158 std::vector<Real> additionalMultipliers;
159 Date lastPremiumDate = addPremiums(additionalInstruments, additionalMultipliers, Position::Long ? 1.0 : -1.0,
160 optionData_.premiumData(), positionType_ == Position::Long ? -1.0 : 1.0,
161 parseCurrency(npvCurrency_), engineFactory,
162 engineFactory->configuration(MarketContext::pricing));
163 auto builder = QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(engineFactory->builder("Swap"));
164 QL_REQUIRE(builder, "could not get swap builder to build exercised swaption instrument.");
165 auto swap = QuantLib::ext::make_shared<QuantLib::Swap>(legs_, legPayers_);
166 swap->setPricingEngine(builder->engine(parseCurrency(npvCurrency_),
167 envelope().additionalField("discount_curve", false),
168 envelope().additionalField("security_spread", false)));
169 setSensitivityTemplate(*builder);
170 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(swap, positionType_ == Position::Long ? 1.0 : -1.0,
171 additionalInstruments, additionalMultipliers);
172 maturity_ = std::max(maturity_, lastPremiumDate);
173 DLOG("Building exercised swaption done.");
174 return;
175 }
176
177 // 6 if we do not have an active exercise as of today, or no underlying legs we only build unconditional premiums
178
179 if (exerciseBuilder_->exercise() == nullptr || exerciseBuilder_->exercise()->dates().empty() ||
180 exerciseBuilder_->exercise()->dates().back() <= today || legData_.empty()) {
181 legs_ = {{QuantLib::ext::make_shared<QuantLib::SimpleCashFlow>(0.0, today)}};
182 legCurrencies_.push_back(npvCurrency_);
183 legPayers_.push_back(false);
184 maturity_ = today;
185 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
186 std::vector<Real> additionalMultipliers;
187 Date lastPremiumDate = addPremiums(additionalInstruments, additionalMultipliers, Position::Long ? 1.0 : -1.0,
188 optionData_.premiumData(), positionType_ == Position::Long ? -1.0 : 1.0,
189 parseCurrency(npvCurrency_), engineFactory,
190 engineFactory->configuration(MarketContext::pricing));
191 auto builder = QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(engineFactory->builder("Swap"));
192 QL_REQUIRE(builder, "could not get swap builder to build expired swaption instrument.");
193 auto swap = QuantLib::ext::make_shared<QuantLib::Swap>(legs_, legPayers_);
194 swap->setPricingEngine(builder->engine(parseCurrency(npvCurrency_),
195 envelope().additionalField("discount_curve", false),
196 envelope().additionalField("security_spread", false)));
197 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(swap, positionType_ == Position::Long ? 1.0 : -1.0,
198 additionalInstruments, additionalMultipliers);
199 setSensitivityTemplate(*builder);
200 maturity_ = std::max(maturity_, lastPremiumDate);
201 DLOG("Building (non-exercised) swaption without alive exercise dates done.");
202 return;
203 }
204
205 // 7 fill legs, only include coupons after first exercise
206
207 legCurrencies_ = underlying_->legCurrencies();
208 legPayers_ = underlying_->legPayers();
209 legs_.clear();
210 Date firstExerciseDate = exerciseBuilder_->exercise()->dates().front();
211 for (auto const& l : underlying_->legs()) {
212 legs_.push_back(Leg());
213 for (auto const& c : l) {
214 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(c)) {
215 if (firstExerciseDate <= cpn->accrualStartDate()) {
216 legs_.back().push_back(c);
217 }
218 } else if (firstExerciseDate <= c->date()) {
219 legs_.back().push_back(c);
220 }
221 }
222 }
223
224 // 8 build swaption
225
226 if (settlementType_ == Settlement::Physical)
227 maturity_ = underlying_->maturity();
228 else
229 maturity_ = exerciseBuilder_->noticeDates().back();
230
231 if (exerciseType_ != Exercise::European && settlementType_ == Settlement::Cash &&
232 settlementMethod_ == Settlement::ParYieldCurve)
233 WLOG("Cash-settled Bermudan/American Swaption (id = "
234 << id() << ") with ParYieldCurve settlement method not supported by Lgm engine. "
235 << "Approximate pricing using CollateralizedCashPrice pricing methodology");
236
237 std::vector<QuantLib::Currency> ccys;
238 for (auto const& c : underlying_->legCurrencies())
239 ccys.push_back(parseCurrency(c));
240 auto swaption =
241 QuantLib::ext::make_shared<QuantExt::MultiLegOption>(underlying_->legs(), underlying_->legPayers(), ccys,
243
244 std::string builderType;
245 std::vector<std::string> builderPrecheckMessages;
246 // for European swaptions that are not handled by the black pricer, we fall back to the numeric Bermudan pricer
247 if (exerciseType_ == Exercise::European &&
248 QuantExt::BlackMultiLegOptionEngineBase::instrumentIsHandled(*swaption, builderPrecheckMessages)) {
249 builderType = "EuropeanSwaption";
250 } else {
251 QL_REQUIRE(
252 QuantExt::NumericLgmMultiLegOptionEngineBase::instrumentIsHandled(*swaption, builderPrecheckMessages),
253 "Swaption::build(): instrument is not handled by the available engines: " +
254 boost::join(builderPrecheckMessages, ", "));
255 if (exerciseType_ == Exercise::European || exerciseType_ == Exercise::Bermudan)
256 builderType = "BermudanSwaption";
257 else if (exerciseType_ == Exercise::American)
258 builderType = "AmericanSwaption";
259 }
260
261 DLOG("Getting builder for '" << builderType << "', got " << builderPrecheckMessages.size()
262 << " builder precheck messages:");
263 for (auto const& m : builderPrecheckMessages) {
264 DLOG(m);
265 }
266
267 auto swaptionBuilder = QuantLib::ext::dynamic_pointer_cast<SwaptionEngineBuilder>(engineFactory->builder(builderType));
268 QL_REQUIRE(swaptionBuilder, "Swaption::build(): internal error: could not cast to SwaptionEngineBuilder");
269
270 auto swapBuilder = QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(engineFactory->builder("Swap"));
271 QL_REQUIRE(swapBuilder, "Swaption::build(): internal error: could not cast to SwapEngineBuilder");
272
273 // 9.1 determine index (if several, pick first) got get the engine
274
275 QuantLib::ext::shared_ptr<InterestRateIndex> index;
276
277 for (auto const& l : underlying_->legs()) {
278 for (auto const& c : l) {
279 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c)) {
280 if (index == nullptr) {
281 if (auto tmp = QuantLib::ext::dynamic_pointer_cast<IborIndex>(cpn->index())) {
282 DLOG("found ibor / ois index '" << tmp->name() << "'");
283 index = tmp;
284 } else if (auto tmp = QuantLib::ext::dynamic_pointer_cast<SwapIndex>(cpn->index())) {
285 DLOG("found cms index " << tmp->name() << ", use key '" << tmp->iborIndex()->name()
286 << "' to look up vol");
287 index = tmp->iborIndex();
288 } else if (auto tmp = QuantLib::ext::dynamic_pointer_cast<BMAIndex>(cpn->index())) {
289 DLOG("found bma/sifma index '" << tmp->name() << "'");
290 index = tmp;
291 }
292 }
293 }
294 }
295 }
296
297 if (index == nullptr) {
298 DLOG("no ibor, ois, bma/sifma, cms index found, use ccy key to look up vol");
299 }
300
301 // 9.2 determine strikes for calibration basket (simple approach, a la summit)
302
303 std::vector<Real> strikes(exerciseBuilder_->noticeDates().size(), Null<Real>());
304 for (Size i = 0; i < exerciseBuilder_->noticeDates().size(); ++i) {
305 Real firstFixedRate = Null<Real>(), lastFixedRate = Null<Real>();
306 Real firstFloatSpread = Null<Real>(), lastFloatSpread = Null<Real>();
307 for (auto const& l : underlying_->legs()) {
308 for (auto const& c : l) {
309 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<FixedRateCoupon>(c)) {
310 if (cpn->accrualStartDate() >= exerciseBuilder_->noticeDates()[i] && firstFixedRate == Null<Real>())
311 firstFixedRate = cpn->rate();
312 lastFixedRate = cpn->rate();
313 } else if (auto cpn = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c)) {
314 if (cpn->accrualStartDate() >= exerciseBuilder_->noticeDates()[i] &&
315 firstFloatSpread == Null<Real>())
316 firstFloatSpread = cpn->spread();
317 lastFloatSpread = cpn->spread();
318 if (index == nullptr) {
319 if (auto tmp = QuantLib::ext::dynamic_pointer_cast<IborIndex>(cpn->index())) {
320 DLOG("found ibor / ois index '" << tmp->name() << "'");
321 index = tmp;
322 } else if (auto tmp = QuantLib::ext::dynamic_pointer_cast<SwapIndex>(cpn->index())) {
323 DLOG("found cms index " << tmp->name() << ", use key '" << tmp->iborIndex()->name()
324 << "' to look up vol");
325 index = tmp->iborIndex();
326 } else if (auto tmp = QuantLib::ext::dynamic_pointer_cast<BMAIndex>(cpn->index())) {
327 DLOG("found bma/sifma index '" << tmp->name() << "'");
328 index = tmp;
329 }
330 }
331 }
332 }
333 }
334 // if no first fixed rate (float spread) was found, fall back on the last values
335 if(firstFixedRate == Null<Real>())
336 firstFixedRate = lastFixedRate;
337 if(firstFloatSpread == Null<Real>())
338 firstFloatSpread = lastFloatSpread;
339 // construct calibration strike
340 if (firstFixedRate != Null<Real>()) {
341 strikes[i] = firstFixedRate;
342 if (firstFloatSpread != Null<Real>()) {
343 strikes[i] -= firstFloatSpread;
344 }
345 }
346 DLOG("calibration strike for ex date "
347 << QuantLib::io::iso_date(exerciseBuilder_->noticeDates()[i]) << " is "
348 << (strikes[i] == Null<Real>() ? "ATMF" : std::to_string(strikes[i])) << " (fixed rate "
349 << (firstFixedRate == Null<Real>() ? "NA" : std::to_string(firstFixedRate)) << ", spread "
350 << (firstFloatSpread == Null<Real>() ? "NA" : std::to_string(firstFloatSpread)) << ")");
351 }
352
353 // 9.3 get engine and set it
354
355 cpu_timer timer;
356 // use ibor / ois index as key, if possible, otherwise the npv currency
357 auto swaptionEngine = swaptionBuilder->engine(
358 id(), index == nullptr ? npvCurrency_ : IndexNameTranslator::instance().oreName(index->name()),
359 exerciseBuilder_->noticeDates(), underlying_->maturity(), strikes, exerciseType_ == Exercise::American,
360 envelope().additionalField("discount_curve", false), envelope().additionalField("security_spread", false));
361 timer.stop();
362 DLOG("Swaption model calibration time: " << timer.format(default_places, "%w") << " s");
363 swaption->setPricingEngine(swaptionEngine);
364 setSensitivityTemplate(*swaptionBuilder);
365
366 // 9.4 build underlying swaps, add premiums, build option wrapper
367
368 auto swapEngine =
369 swapBuilder->engine(parseCurrency(npvCurrency_), envelope().additionalField("discount_curve", false),
370 envelope().additionalField("security_spread", false));
371
372 std::vector<QuantLib::ext::shared_ptr<Instrument>> underlyingSwaps =
373 buildUnderlyingSwaps(swapEngine, exerciseBuilder_->noticeDates());
374
375 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
376 std::vector<Real> additionalMultipliers;
377 Real multiplier = positionType_ == Position::Long ? 1.0 : -1.0;
378 Date lastPremiumDate = addPremiums(additionalInstruments, additionalMultipliers, Position::Long ? 1.0 : -1.0,
380 engineFactory, swaptionBuilder->configuration(MarketContext::pricing));
381
382 instrument_ = QuantLib::ext::make_shared<BermudanOptionWrapper>(
383 swaption, positionType_ == Position::Long ? true : false, exerciseBuilder_->noticeDates(),
384 settlementType_ == Settlement::Physical ? true : false, underlyingSwaps, 1.0, 1.0, additionalInstruments,
385 additionalMultipliers);
386
387 maturity_ = std::max(maturity_, lastPremiumDate);
388
389 DLOG("Building Swaption done");
390}
const string & settlementMethod() const
Definition: optiondata.hpp:82
const string & longShort() const
Definition: optiondata.hpp:70
const string & style() const
Definition: optiondata.hpp:74
const string & settlement() const
Definition: optiondata.hpp:81
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
void addData(const RequiredFixings &requiredFixings)
std::vector< QuantLib::ext::shared_ptr< Instrument > > buildUnderlyingSwaps(const QuantLib::ext::shared_ptr< PricingEngine > &, const std::vector< Date > &)
build underlying swaps for exposure simulation
Definition: swaption.cpp:393
QuantLib::ext::shared_ptr< ExerciseBuilder > exerciseBuilder_
Definition: swaption.hpp:77
QuantLib::ext::shared_ptr< ore::data::Swap > underlying_
Definition: swaption.hpp:76
Exercise::Type exerciseType_
Definition: swaption.hpp:79
Settlement::Method settlementMethod_
Definition: swaption.hpp:81
Settlement::Type settlementType_
Definition: swaption.hpp:80
Position::Type positionType_
Definition: swaption.hpp:78
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
QuantLib::Real notional_
Definition: trade.hpp:202
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)
Definition: trade.cpp:58
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
RequiredFixings requiredFixings_
Definition: trade.hpp:223
const Envelope & envelope() const
Definition: trade.hpp:135
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Definition: parsers.cpp:466
Settlement::Method parseSettlementMethod(const std::string &s)
Convert text to QuantLib::Settlement::Method.
Definition: parsers.cpp:450
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
Definition: parsers.cpp:434
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
Size size(const ValueType &v)
Definition: value.cpp:145
vector< Real > strikes
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ optionData()

const OptionData & optionData ( ) const

Definition at line 49 of file swaption.hpp.

49{ return optionData_; }
+ Here is the caller graph for this function:

◆ legData()

const vector< LegData > & legData ( )

Definition at line 50 of file swaption.hpp.

50{ return legData_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 483 of file swaption.cpp.

483 {
484 Trade::fromXML(node);
485 XMLNode* swapNode = XMLUtils::getChildNode(node, "SwaptionData");
486 optionData_.fromXML(XMLUtils::getChildNode(swapNode, "OptionData"));
487 legData_.clear();
488 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(swapNode, "LegData");
489 for (Size i = 0; i < nodes.size(); i++) {
490 LegData ld;
491 ld.fromXML(nodes[i]);
492 legData_.push_back(ld);
493 }
494}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 496 of file swaption.cpp.

496 {
497 XMLNode* node = Trade::toXML(doc);
498 XMLNode* swaptionNode = doc.allocNode("SwaptionData");
499 XMLUtils::appendNode(node, swaptionNode);
500
501 XMLUtils::appendNode(swaptionNode, optionData_.toXML(doc));
502 for (Size i = 0; i < legData_.size(); i++)
503 XMLUtils::appendNode(swaptionNode, legData_[i].toXML(doc));
504
505 return node;
506}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: swaption.cpp:496
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ notional()

QuantLib::Real notional ( ) const
overridevirtual

Return the current notional in npvCurrency. See individual sub-classes for the precise definition.

Reimplemented from Trade.

Definition at line 437 of file swaption.cpp.

437 {
438 Real tmp = 0.0;
439 for (auto const& l : underlying_->legs()) {
440 tmp = std::max(tmp, currentNotional(l));
441 }
442 return tmp;
443}
Real currentNotional(const Leg &leg)
Definition: legdata.cpp:2435
+ Here is the call graph for this function:

◆ additionalData()

const std::map< std::string, boost::any > & additionalData ( ) const
overridevirtual

returns all additional data returned by the trade once built

Reimplemented from Trade.

Definition at line 447 of file swaption.cpp.

447 {
448 // use the build time as of date to determine current notionals
449 Date asof = Settings::instance().evaluationDate();
450 for (Size i = 0; i < std::min(legData_.size(), legs_.size()); ++i) {
451 string legID = to_string(i + 1);
452 additionalData_["legType[" + legID + "]"] = legData_[i].legType();
453 additionalData_["isPayer[" + legID + "]"] = legData_[i].isPayer();
454 additionalData_["notionalCurrency[" + legID + "]"] = legData_[i].currency();
455 for (Size j = 0; j < legs_[i].size(); ++j) {
456 QuantLib::ext::shared_ptr<CashFlow> flow = legs_[i][j];
457 // pick flow with earliest future payment date on this leg
458 if (flow->date() > asof) {
459 additionalData_["amount[" + legID + "]"] = flow->amount();
460 additionalData_["paymentDate[" + legID + "]"] = to_string(flow->date());
461 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(flow);
462 if (coupon) {
463 additionalData_["currentNotional[" + legID + "]"] = coupon->nominal();
464 additionalData_["rate[" + legID + "]"] = coupon->rate();
465 QuantLib::ext::shared_ptr<FloatingRateCoupon> frc = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(flow);
466 if (frc) {
467 additionalData_["index[" + legID + "]"] = frc->index()->name();
468 additionalData_["spread[" + legID + "]"] = frc->spread();
469 }
470 }
471 break;
472 }
473 }
474 if (legs_[i].size() > 0) {
475 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(legs_[i][0]);
476 if (coupon)
477 additionalData_["originalNotional[" + legID + "]"] = coupon->nominal();
478 }
479 }
480 return additionalData_;
481}
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ hasCashflows()

bool hasCashflows ( ) const
overridevirtual

Utility method indicating if the trade has cashflows for the cashflow report. The default implementation returns true so that a trade is automatically considered when cashflows are being written. To prevent a trade from being asked for its cashflows, the method can be overridden to return false.

Reimplemented from Trade.

Definition at line 61 of file swaption.hpp.

61{ return false; }

◆ isExercised()

bool isExercised ( ) const

Definition at line 445 of file swaption.cpp.

445{ return exerciseBuilder_->isExercised(); }
+ Here is the caller graph for this function:

◆ underlyingIndices()

map< AssetClass, set< string > > underlyingIndices ( const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceDataManager = nullptr) const
overridevirtual

Reimplemented from Trade.

Definition at line 509 of file swaption.cpp.

509 {
510 map<AssetClass, set<string>> result;
511 if (auto s = envelope().additionalField("security_spread", false); !s.empty())
512 result[AssetClass::BOND] = {s};
513 return result;
514}
+ Here is the call graph for this function:

◆ buildUnderlyingSwaps()

std::vector< QuantLib::ext::shared_ptr< Instrument > > buildUnderlyingSwaps ( const QuantLib::ext::shared_ptr< PricingEngine > &  swapEngine,
const std::vector< Date > &  exerciseDates 
)
private

build underlying swaps for exposure simulation

Definition at line 393 of file swaption.cpp.

394 {
395 std::vector<QuantLib::ext::shared_ptr<Instrument>> swaps;
396 for (Size i = 0; i < exerciseDates.size(); ++i) {
397 std::vector<Leg> legs = underlying_->legs();
398 std::vector<bool> payer = underlying_->legPayers();
399 for (Size j = 0; j < legs.size(); ++j) {
400 Date ed = exerciseDates[i];
401 auto it = std::lower_bound(legs[j].begin(), legs[j].end(), exerciseDates[i],
402 [&ed](const QuantLib::ext::shared_ptr<CashFlow>& c, const Date& d) {
403 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(c)) {
404 return cpn->accrualStartDate() < ed;
405 } else {
406 return c->date() < ed;
407 }
408 });
409 if (it != legs[j].begin())
410 --it;
411 legs[j].erase(legs[j].begin(), it);
412 }
413 auto newSwap = QuantLib::ext::make_shared<QuantLib::Swap>(legs, payer);
414 if (swapEngine != nullptr) {
415 newSwap->setPricingEngine(swapEngine);
416 }
417 swaps.push_back(newSwap);
418 for (auto const& l : legs) {
419 if (l.empty()) {
420 WLOG("Added empty leg to underlying swap for exercise " << QuantLib::io::iso_date(exerciseDates[i])
421 << "!");
422 } else {
423 Date d;
424 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(l.front())) {
425 d = cpn->accrualStartDate();
426 } else {
427 d = l.front()->date();
428 }
429 DLOG("Added leg with start date " << QuantLib::io::iso_date(d) << " for exercise "
430 << QuantLib::io::iso_date(exerciseDates[i]));
431 }
432 }
433 }
434 return swaps;
435}
const std::vector< QuantLib::Leg > & legs() const
Definition: trade.hpp:143
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ optionData_

OptionData optionData_
private

Definition at line 69 of file swaption.hpp.

◆ legData_

vector<LegData> legData_
private

Definition at line 70 of file swaption.hpp.

◆ underlying_

QuantLib::ext::shared_ptr<ore::data::Swap> underlying_
private

Definition at line 76 of file swaption.hpp.

◆ exerciseBuilder_

QuantLib::ext::shared_ptr<ExerciseBuilder> exerciseBuilder_
private

Definition at line 77 of file swaption.hpp.

◆ positionType_

Position::Type positionType_
private

Definition at line 78 of file swaption.hpp.

◆ exerciseType_

Exercise::Type exerciseType_
private

Definition at line 79 of file swaption.hpp.

◆ settlementType_

Settlement::Type settlementType_
private

Definition at line 80 of file swaption.hpp.

◆ settlementMethod_

Settlement::Method settlementMethod_
private

Definition at line 81 of file swaption.hpp.