Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Classes | List of all members
CurrencySwap Class Reference

Currency Interest Rate Swap More...

#include <qle/instruments/currencyswap.hpp>

+ Inheritance diagram for CurrencySwap:
+ Collaboration diagram for CurrencySwap:

Classes

class  arguments
 
class  engine
 
class  results
 

Public Member Functions

LazyObject interface
void alwaysForwardNotifications () override
 
Observable interface
void deepUpdate () override
 
Additional interface
Date startDate () const
 
Date maturityDate () const
 
Real legBPS (Size j) const
 
Real legNPV (Size j) const
 
Real inCcyLegBPS (Size j) const
 
Real inCcyLegNPV (Size j) const
 
DiscountFactor startDiscounts (Size j) const
 
DiscountFactor endDiscounts (Size j) const
 
DiscountFactor npvDateDiscount () const
 
const Leg & leg (Size j) const
 
const Currency & legCurrency (Size j) const
 
std::vector< Leg > legs ()
 
std::vector< Currency > currencies ()
 

Instrument interface

std::vector< Leg > legs_
 
std::vector< Real > payer_
 
std::vector< Currency > currency_
 
bool isPhysicallySettled_
 
bool isResettable_
 
std::vector< Real > legNPV_
 
std::vector< Real > inCcyLegNPV_
 
std::vector< Real > legBPS_
 
std::vector< Real > inCcyLegBPS_
 
std::vector< DiscountFactor > startDiscounts_
 
std::vector< DiscountFactor > endDiscounts_
 
DiscountFactor npvDateDiscount_
 
bool isExpired () const override
 
void setupArguments (PricingEngine::arguments *) const override
 
void fetchResults (const PricingEngine::results *) const override
 
void setupExpired () const override
 

Constructors

 CurrencySwap (const std::vector< Leg > &legs, const std::vector< bool > &payer, const std::vector< Currency > &currency, const bool isPhysicallySettled=true, const bool isResettable=false)
 
 CurrencySwap (Size legs)
 

Detailed Description

Currency Interest Rate Swap

This instrument generalizes the QuantLib Swap instrument in that it allows multiple legs with different currencies (one per leg)

Definition at line 47 of file currencyswap.hpp.

Constructor & Destructor Documentation

◆ CurrencySwap() [1/2]

CurrencySwap ( const std::vector< Leg > &  legs,
const std::vector< bool > &  payer,
const std::vector< Currency > &  currency,
const bool  isPhysicallySettled = true,
const bool  isResettable = false 
)

Multi leg constructor.

Definition at line 44 of file currencyswap.cpp.

47 : legs_(legs), payer_(legs.size(), 1.0), currency_(currency), isPhysicallySettled_(isPhysicallySettled),
48 isResettable_(isResettable), legNPV_(legs.size(), 0.0), inCcyLegNPV_(legs.size(), 0.0), legBPS_(legs.size(), 0.0),
49 inCcyLegBPS_(legs.size(), 0.0), startDiscounts_(legs.size(), 0.0), endDiscounts_(legs.size(), 0.0),
50 npvDateDiscount_(0.0) {
51 QL_REQUIRE(payer.size() == legs_.size(),
52 "size mismatch between payer (" << payer.size() << ") and legs (" << legs_.size() << ")");
53 QL_REQUIRE(currency.size() == legs_.size(),
54 "size mismatch between currency (" << currency.size() << ") and legs (" << legs_.size() << ")");
55 for (Size j = 0; j < legs_.size(); ++j) {
56 if (payer[j])
57 payer_[j] = -1.0;
58 for (Leg::iterator i = legs_[j].begin(); i != legs_[j].end(); ++i)
59 registerWith(*i);
60 }
61}
DiscountFactor npvDateDiscount_
std::vector< Real > inCcyLegNPV_
std::vector< Currency > currency_
std::vector< Leg > legs_
std::vector< Real > inCcyLegBPS_
std::vector< Real > legNPV_
std::vector< Real > legBPS_
std::vector< DiscountFactor > startDiscounts_
std::vector< Leg > legs()
std::vector< DiscountFactor > endDiscounts_
std::vector< Real > payer_

◆ CurrencySwap() [2/2]

CurrencySwap ( Size  legs)
protected

This constructor can be used by derived classes that will build their legs themselves.

Definition at line 32 of file currencyswap.cpp.

32 {
33 legs_.resize(nLegs);
34 payer_.resize(nLegs);
35 currency_.resize(nLegs);
36 legNPV_.resize(nLegs);
37 inCcyLegNPV_.resize(nLegs);
38 legBPS_.resize(nLegs);
39 inCcyLegBPS_.resize(nLegs);
40 startDiscounts_.resize(nLegs);
41 endDiscounts_.resize(nLegs);
42}

Member Function Documentation

◆ alwaysForwardNotifications()

void alwaysForwardNotifications ( )
override

Definition at line 193 of file currencyswap.cpp.

193 {
194 for (auto& leg : legs_) {
195 for (auto& k : leg) {
196 if (auto lazy = ext::dynamic_pointer_cast<LazyObject>(k))
197 lazy->alwaysForwardNotifications();
198 }
199 }
200 LazyObject::alwaysForwardNotifications();
201}
const Leg & leg(Size j) const
+ Here is the call graph for this function:

◆ deepUpdate()

void deepUpdate ( )
override

Definition at line 183 of file currencyswap.cpp.

183 {
184 for (auto& leg : legs_) {
185 for (auto& k : leg) {
186 if (auto lazy = ext::dynamic_pointer_cast<LazyObject>(k))
187 lazy->deepUpdate();
188 }
189 }
190 update();
191}
+ Here is the call graph for this function:

◆ isExpired()

bool isExpired ( ) const
override

Definition at line 63 of file currencyswap.cpp.

63 {
64 for (Size j = 0; j < legs_.size(); ++j) {
65 Leg::const_iterator i;
66 for (i = legs_[j].begin(); i != legs_[j].end(); ++i)
67 if (!(*i)->hasOccurred())
68 return false;
69 }
70 return true;
71}

◆ setupArguments()

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

Definition at line 84 of file currencyswap.cpp.

84 {
85 CurrencySwap::arguments* arguments = dynamic_cast<CurrencySwap::arguments*>(args);
86 QL_REQUIRE(arguments != 0, "wrong argument type");
87
88 arguments->legs = legs_;
89 arguments->payer = payer_;
90 arguments->currency = currency_;
91 arguments->isPhysicallySettled = isPhysicallySettled_;
92 arguments->isResettable = isResettable_;
93}

◆ fetchResults()

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

Definition at line 95 of file currencyswap.cpp.

95 {
96 Instrument::fetchResults(r);
97
98 const CurrencySwap::results* results = dynamic_cast<const CurrencySwap::results*>(r);
99 QL_REQUIRE(results != 0, "wrong result type");
100
101 if (!results->legNPV.empty()) {
102 QL_REQUIRE(results->legNPV.size() == legNPV_.size(), "wrong number of leg NPV returned");
103 legNPV_ = results->legNPV;
104 } else {
105 std::fill(legNPV_.begin(), legNPV_.end(), Null<Real>());
106 }
107
108 if (!results->legBPS.empty()) {
109 QL_REQUIRE(results->legBPS.size() == legBPS_.size(), "wrong number of leg BPS returned");
110 legBPS_ = results->legBPS;
111 } else {
112 std::fill(legBPS_.begin(), legBPS_.end(), Null<Real>());
113 }
114
115 if (!results->inCcyLegNPV.empty()) {
116 QL_REQUIRE(results->inCcyLegNPV.size() == inCcyLegNPV_.size(), "wrong number of leg NPV returned");
117 inCcyLegNPV_ = results->inCcyLegNPV;
118 } else {
119 std::fill(inCcyLegNPV_.begin(), inCcyLegNPV_.end(), Null<Real>());
120 }
121
122 if (!results->inCcyLegBPS.empty()) {
123 QL_REQUIRE(results->inCcyLegBPS.size() == inCcyLegBPS_.size(), "wrong number of leg BPS returned");
124 inCcyLegBPS_ = results->inCcyLegBPS;
125 } else {
126 std::fill(inCcyLegBPS_.begin(), inCcyLegBPS_.end(), Null<Real>());
127 }
128
129 if (!results->startDiscounts.empty()) {
130 QL_REQUIRE(results->startDiscounts.size() == startDiscounts_.size(),
131 "wrong number of leg start discounts returned");
132 startDiscounts_ = results->startDiscounts;
133 } else {
134 std::fill(startDiscounts_.begin(), startDiscounts_.end(), Null<DiscountFactor>());
135 }
136
137 if (!results->endDiscounts.empty()) {
138 QL_REQUIRE(results->endDiscounts.size() == endDiscounts_.size(), "wrong number of leg end discounts returned");
139 endDiscounts_ = results->endDiscounts;
140 } else {
141 std::fill(endDiscounts_.begin(), endDiscounts_.end(), Null<DiscountFactor>());
142 }
143
144 if (results->npvDateDiscount != Null<DiscountFactor>()) {
145 npvDateDiscount_ = results->npvDateDiscount;
146 } else {
147 npvDateDiscount_ = Null<DiscountFactor>();
148 }
149}

◆ startDate()

Date startDate ( ) const

Definition at line 151 of file currencyswap.cpp.

151 {
152 QL_REQUIRE(!legs_.empty(), "no legs given");
153 Date d = CashFlows::startDate(legs_[0]);
154 for (Size j = 1; j < legs_.size(); ++j)
155 d = std::min(d, CashFlows::startDate(legs_[j]));
156 return d;
157}

◆ maturityDate()

Date maturityDate ( ) const

Definition at line 159 of file currencyswap.cpp.

159 {
160 QL_REQUIRE(!legs_.empty(), "no legs given");
161 Date d = CashFlows::maturityDate(legs_[0]);
162 for (Size j = 1; j < legs_.size(); ++j)
163 d = std::max(d, CashFlows::maturityDate(legs_[j]));
164 return d;
165}

◆ legBPS()

Real legBPS ( Size  j) const

Definition at line 76 of file currencyswap.hpp.

76 {
77 QL_REQUIRE(j < legs_.size(), "leg# " << j << " doesn't exist!");
78 calculate();
79 return legBPS_[j];
80 }
+ Here is the caller graph for this function:

◆ legNPV()

Real legNPV ( Size  j) const

Definition at line 81 of file currencyswap.hpp.

81 {
82 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
83 calculate();
84 return legNPV_[j];
85 }
+ Here is the caller graph for this function:

◆ inCcyLegBPS()

Real inCcyLegBPS ( Size  j) const

Definition at line 86 of file currencyswap.hpp.

86 {
87 QL_REQUIRE(j < legs_.size(), "leg# " << j << " doesn't exist!");
88 calculate();
89 return inCcyLegBPS_[j];
90 }
+ Here is the caller graph for this function:

◆ inCcyLegNPV()

Real inCcyLegNPV ( Size  j) const

Definition at line 91 of file currencyswap.hpp.

91 {
92 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
93 calculate();
94 return inCcyLegNPV_[j];
95 }
+ Here is the caller graph for this function:

◆ startDiscounts()

DiscountFactor startDiscounts ( Size  j) const

Definition at line 96 of file currencyswap.hpp.

96 {
97 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
98 calculate();
99 return startDiscounts_[j];
100 }
+ Here is the caller graph for this function:

◆ endDiscounts()

DiscountFactor endDiscounts ( Size  j) const

Definition at line 101 of file currencyswap.hpp.

101 {
102 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
103 calculate();
104 return endDiscounts_[j];
105 }
+ Here is the caller graph for this function:

◆ npvDateDiscount()

DiscountFactor npvDateDiscount ( ) const

Definition at line 106 of file currencyswap.hpp.

106 {
107 calculate();
108 return npvDateDiscount_;
109 }
+ Here is the caller graph for this function:

◆ leg()

const Leg & leg ( Size  j) const

Definition at line 110 of file currencyswap.hpp.

110 {
111 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
112 return legs_[j];
113 }
+ Here is the caller graph for this function:

◆ legCurrency()

const Currency & legCurrency ( Size  j) const

Definition at line 114 of file currencyswap.hpp.

114 {
115 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
116 return currency_[j];
117 }

◆ legs()

std::vector< Leg > legs ( )

Definition at line 118 of file currencyswap.hpp.

118{ return legs_; }

◆ currencies()

std::vector< Currency > currencies ( )

Definition at line 119 of file currencyswap.hpp.

119{ return currency_; }

◆ setupExpired()

void setupExpired ( ) const
overrideprotected

Definition at line 73 of file currencyswap.cpp.

73 {
74 Instrument::setupExpired();
75 std::fill(legBPS_.begin(), legBPS_.end(), 0.0);
76 std::fill(legNPV_.begin(), legNPV_.end(), 0.0);
77 std::fill(inCcyLegBPS_.begin(), inCcyLegBPS_.end(), 0.0);
78 std::fill(inCcyLegNPV_.begin(), inCcyLegNPV_.end(), 0.0);
79 std::fill(startDiscounts_.begin(), startDiscounts_.end(), 0.0);
80 std::fill(endDiscounts_.begin(), endDiscounts_.end(), 0.0);
81 npvDateDiscount_ = 0.0;
82}

Member Data Documentation

◆ legs_

std::vector<Leg> legs_
protected

Definition at line 133 of file currencyswap.hpp.

◆ payer_

std::vector<Real> payer_
protected

Definition at line 134 of file currencyswap.hpp.

◆ currency_

std::vector<Currency> currency_
protected

Definition at line 135 of file currencyswap.hpp.

◆ isPhysicallySettled_

bool isPhysicallySettled_
protected

Definition at line 136 of file currencyswap.hpp.

◆ isResettable_

bool isResettable_
protected

Definition at line 136 of file currencyswap.hpp.

◆ legNPV_

std::vector<Real> legNPV_
mutableprotected

Definition at line 137 of file currencyswap.hpp.

◆ inCcyLegNPV_

std::vector<Real> inCcyLegNPV_
protected

Definition at line 137 of file currencyswap.hpp.

◆ legBPS_

std::vector<Real> legBPS_
mutableprotected

Definition at line 138 of file currencyswap.hpp.

◆ inCcyLegBPS_

std::vector<Real> inCcyLegBPS_
protected

Definition at line 138 of file currencyswap.hpp.

◆ startDiscounts_

std::vector<DiscountFactor> startDiscounts_
mutableprotected

Definition at line 139 of file currencyswap.hpp.

◆ endDiscounts_

std::vector<DiscountFactor> endDiscounts_
protected

Definition at line 139 of file currencyswap.hpp.

◆ npvDateDiscount_

DiscountFactor npvDateDiscount_
mutableprotected

Definition at line 140 of file currencyswap.hpp.