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

#include <qle/instruments/multilegoption.hpp>

+ Inheritance diagram for MultiLegOption:
+ Collaboration diagram for MultiLegOption:

Classes

class  arguments
 
class  engine
 
class  results
 

Public Member Functions

 MultiLegOption (const std::vector< Leg > &legs, const std::vector< bool > &payer, const std::vector< Currency > &currency, const QuantLib::ext::shared_ptr< Exercise > &exercise=QuantLib::ext::shared_ptr< Exercise >(), const Settlement::Type settlementType=Settlement::Physical, Settlement::Method settlementMethod=Settlement::PhysicalOTC)
 exercise = nullptr means that the instrument is identical to the underlying itself (i.e. a swap) More...
 
const std::vector< Leg > & legs () const
 
const std::vector< bool > & payer () const
 
const std::vector< Currency > & currency () const
 
const QuantLib::ext::shared_ptr< Exercise > exercise () const
 
const Settlement::Type settlementType () const
 
const Settlement::Method settlementMethod () const
 
void deepUpdate () override
 
bool isExpired () const override
 
void setupArguments (PricingEngine::arguments *) const override
 
void fetchResults (const PricingEngine::results *) const override
 
const Date & maturityDate () const
 
Real underlyingNpv () const
 

Private Attributes

const std::vector< Leg > legs_
 
const std::vector< boolpayer_
 
const std::vector< Currency > currency_
 
const QuantLib::ext::shared_ptr< Exercise > exercise_
 
const Settlement::Type settlementType_
 
const Settlement::Method settlementMethod_
 
Date maturity_
 
Real underlyingNpv_
 

Detailed Description

Definition at line 36 of file multilegoption.hpp.

Constructor & Destructor Documentation

◆ MultiLegOption()

MultiLegOption ( const std::vector< Leg > &  legs,
const std::vector< bool > &  payer,
const std::vector< Currency > &  currency,
const QuantLib::ext::shared_ptr< Exercise > &  exercise = QuantLib::ext::shared_ptr<Exercise>(),
const Settlement::Type  settlementType = Settlement::Physical,
Settlement::Method  settlementMethod = Settlement::PhysicalOTC 
)

exercise = nullptr means that the instrument is identical to the underlying itself (i.e. a swap)

Definition at line 25 of file multilegoption.cpp.

30
31 QL_REQUIRE(legs_.size() > 0, "MultiLegOption: No legs are given");
32 QL_REQUIRE(payer_.size() == legs_.size(),
33 "MultiLegOption: payer size (" << payer.size() << ") does not match legs size (" << legs_.size() << ")");
34 QL_REQUIRE(currency_.size() == legs_.size(), "MultiLegOption: currency size (" << currency_.size()
35 << ") does not match legs size ("
36 << legs_.size() << ")");
37 // find maturity date
38
39 maturity_ = Date::minDate();
40 for (auto const& l : legs_) {
41 if (!l.empty())
42 maturity_ = std::max(maturity_, l.back()->date());
43 }
44
45 // register with underlying cashflows
46
47 for (auto const& l : legs_) {
48 for (auto const& c : l) {
49 registerWith(c);
50 if (auto lazy = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c))
51 lazy->alwaysForwardNotifications();
52 }
53 }
54
55} // MultiLegOption
const Settlement::Method settlementMethod_
const std::vector< Leg > & legs() const
const QuantLib::ext::shared_ptr< Exercise > exercise_
const Settlement::Type settlementType() const
const Settlement::Method settlementMethod() const
const Settlement::Type settlementType_
const std::vector< bool > payer_
const std::vector< Leg > legs_
const QuantLib::ext::shared_ptr< Exercise > exercise() const
const std::vector< Currency > & currency() const
const std::vector< Currency > currency_
const std::vector< bool > & payer() const
+ Here is the call graph for this function:

Member Function Documentation

◆ legs()

const std::vector< Leg > & legs ( ) const

Definition at line 48 of file multilegoption.hpp.

48{ return legs_; }
+ Here is the caller graph for this function:

◆ payer()

const std::vector< bool > & payer ( ) const

Definition at line 49 of file multilegoption.hpp.

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

◆ currency()

const std::vector< Currency > & currency ( ) const

Definition at line 50 of file multilegoption.hpp.

50{ return currency_; }
+ Here is the caller graph for this function:

◆ exercise()

const QuantLib::ext::shared_ptr< Exercise > exercise ( ) const

Definition at line 51 of file multilegoption.hpp.

51{ return exercise_; }
+ Here is the caller graph for this function:

◆ settlementType()

const Settlement::Type settlementType ( ) const

Definition at line 52 of file multilegoption.hpp.

52{ return settlementType_; }
+ Here is the caller graph for this function:

◆ settlementMethod()

const Settlement::Method settlementMethod ( ) const

Definition at line 53 of file multilegoption.hpp.

53{ return settlementMethod_; }
+ Here is the caller graph for this function:

◆ deepUpdate()

void deepUpdate ( )
override

Definition at line 57 of file multilegoption.cpp.

57 {
58 for (auto& l : legs_) {
59 for (auto& c : l) {
60 if (auto lazy = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c))
61 lazy->deepUpdate();
62 }
63 }
64 update();
65}

◆ isExpired()

bool isExpired ( ) const
override

Definition at line 67 of file multilegoption.cpp.

67 {
68 Date today = Settings::instance().evaluationDate();
69 if (exercise_ == nullptr || exercise_->dates().empty()) {
70 return today >= maturityDate();
71 } else {
72 // only the option itself is represented, not something we exercised into
73 return today >= exercise_->dates().back();
74 }
75}
const Date & maturityDate() const
+ Here is the call graph for this function:

◆ setupArguments()

void setupArguments ( PricingEngine::arguments *  args) const
override

Definition at line 83 of file multilegoption.cpp.

83 {
84 MultiLegOption::arguments* tmp = dynamic_cast<MultiLegOption::arguments*>(args);
85 QL_REQUIRE(tmp != nullptr, "MultiLegOption: wrong pricing engine argument type");
86 tmp->legs = legs_;
87 tmp->payer = payer_;
88 tmp->currency = currency_;
89 tmp->exercise = exercise_;
90 tmp->settlementType = settlementType_;
91 tmp->settlementMethod = settlementMethod_;
92}

◆ fetchResults()

void fetchResults ( const PricingEngine::results *  r) const
override

Definition at line 94 of file multilegoption.cpp.

94 {
95 Instrument::fetchResults(r);
96 const MultiLegOption::results* results = dynamic_cast<const MultiLegOption::results*>(r);
97 if (results) {
98 underlyingNpv_ = results->underlyingNpv;
99 } else {
100 underlyingNpv_ = Null<Real>();
101 }
102}

◆ maturityDate()

const Date & maturityDate ( ) const

Definition at line 60 of file multilegoption.hpp.

60{ return maturity_; }
+ Here is the caller graph for this function:

◆ underlyingNpv()

Real underlyingNpv ( ) const

Definition at line 77 of file multilegoption.cpp.

77 {
78 calculate();
79 QL_REQUIRE(underlyingNpv_ != Null<Real>(), "MultiLegOption: underlying npv not available");
80 return underlyingNpv_;
81}

Member Data Documentation

◆ legs_

const std::vector<Leg> legs_
private

Definition at line 64 of file multilegoption.hpp.

◆ payer_

const std::vector<bool> payer_
private

Definition at line 65 of file multilegoption.hpp.

◆ currency_

const std::vector<Currency> currency_
private

Definition at line 66 of file multilegoption.hpp.

◆ exercise_

const QuantLib::ext::shared_ptr<Exercise> exercise_
private

Definition at line 67 of file multilegoption.hpp.

◆ settlementType_

const Settlement::Type settlementType_
private

Definition at line 68 of file multilegoption.hpp.

◆ settlementMethod_

const Settlement::Method settlementMethod_
private

Definition at line 69 of file multilegoption.hpp.

◆ maturity_

Date maturity_
private

Definition at line 70 of file multilegoption.hpp.

◆ underlyingNpv_

Real underlyingNpv_
mutableprivate

Definition at line 72 of file multilegoption.hpp.