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

Flexi-Swap with global notional bounds. More...

#include <qle/instruments/flexiswap.hpp>

+ Inheritance diagram for FlexiSwap:
+ Collaboration diagram for FlexiSwap:

Classes

class  arguments
 Arguments for Flexi-Swap More...
 
class  engine
 Base class for Flexi-Swap engines. More...
 
class  results
 Results for Flexi-Swap More...
 

Public Member Functions

 FlexiSwap (const VanillaSwap::Type type, const std::vector< Real > &fixedNominal, const std::vector< Real > &floatingNominal, const Schedule &fixedSchedule, const std::vector< Real > &fixedRate, const DayCounter &fixedDayCount, const Schedule &floatingSchedule, const QuantLib::ext::shared_ptr< IborIndex > &iborIndex, const std::vector< Real > &gearing, const std::vector< Real > &spread, const std::vector< Real > &cappedRate, const std::vector< Real > &flooredRate, const DayCounter &floatingDayCount, const std::vector< Real > &lowerNotionalBound, const QuantLib::Position::Type optionPosition, const std::vector< bool > &notionalCanBeDecreased=std::vector< bool >(), boost::optional< BusinessDayConvention > paymentConvention=boost::none)
 

Inspectors

const VanillaSwap::Type type_
 
const std::vector< Real > fixedNominal_
 
const std::vector< Real > floatingNominal_
 
const Schedule fixedSchedule_
 
const std::vector< Real > fixedRate_
 
const DayCounter fixedDayCount_
 
const Schedule floatingSchedule_
 
const QuantLib::ext::shared_ptr< IborIndex > iborIndex_
 
const std::vector< Real > gearing_
 
const std::vector< Real > spread_
 
const std::vector< Real > cappedRate_
 
const std::vector< Real > flooredRate_
 
const DayCounter floatingDayCount_
 
const std::vector< Real > lowerNotionalBound_
 
const QuantLib::Position::Type optionPosition_
 
const std::vector< boolnotionalCanBeDecreased_
 
BusinessDayConvention paymentConvention_
 
Real underlyingValue_
 
VanillaSwap::Type type () const
 
const std::vector< Real > & fixedNominal () const
 
const std::vector< Real > & floatingNominal () const
 
const Schedule & fixedSchedule () const
 
const std::vector< Real > & fixedRate () const
 
const DayCounter & fixedDayCount () const
 
const Schedule & floatingSchedule () const
 
const QuantLib::ext::shared_ptr< IborIndex > & iborIndex () const
 
const std::vector< Real > & gearing () const
 
const std::vector< Real > & spread () const
 
const std::vector< Real > & cappedRate () const
 
const std::vector< Real > & flooredRate () const
 
const DayCounter & floatingDayCount () const
 
const std::vector< Real > & lowerNotionalBound () const
 
const QuantLib::Position::Type optionPosition () const
 
const std::vector< bool > & notionalCanBeDecreased () const
 
BusinessDayConvention paymentConvention () const
 
const Leg & fixedLeg () const
 
const Leg & floatingLeg () const
 
Real underlyingValue () const
 
void setupArguments (QuantLib::PricingEngine::arguments *) const override
 
void setupExpired () const override
 
void fetchResults (const QuantLib::PricingEngine::results *) const override
 

Detailed Description

Flexi-Swap with global notional bounds.

The given non-standard swap defines the upper bound for the notionals, which must be non-increasing and consistent across the legs. Furthermore it is assumed that that floating leg's frequency divides the fixed leg's frequency. The notional in the Flexi-Swap can be adjusted on each fixing date corresponding to a whole fixed leg period to any value between the given lower bound and the original amount. The vector of lower bounds must therefore have the same size as the fixed leg vector in the non-standard swap. For periods with a fixing date on or before the evaluation date, is is assumed that the non-standard swap's notional is the relevant one, i.e. the lower bound is ignored for such periods.

notionalCanBeDecreased marks fixed rate periods in which the notional can actually be decreased; defaults to true,true,...,true if not given, i.e. the notional can be decreased in each period.

Definition at line 57 of file flexiswap.hpp.

Constructor & Destructor Documentation

◆ FlexiSwap()

FlexiSwap ( const VanillaSwap::Type  type,
const std::vector< Real > &  fixedNominal,
const std::vector< Real > &  floatingNominal,
const Schedule &  fixedSchedule,
const std::vector< Real > &  fixedRate,
const DayCounter &  fixedDayCount,
const Schedule &  floatingSchedule,
const QuantLib::ext::shared_ptr< IborIndex > &  iborIndex,
const std::vector< Real > &  gearing,
const std::vector< Real > &  spread,
const std::vector< Real > &  cappedRate,
const std::vector< Real > &  flooredRate,
const DayCounter &  floatingDayCount,
const std::vector< Real > &  lowerNotionalBound,
const QuantLib::Position::Type  optionPosition,
const std::vector< bool > &  notionalCanBeDecreased = std::vector<bool>(),
boost::optional< BusinessDayConvention >  paymentConvention = boost::none 
)

Definition at line 31 of file flexiswap.cpp.

46
49 else
50 paymentConvention_ = floatingSchedule_.businessDayConvention();
51
52 QL_REQUIRE(floatingNominal.size() > 0, "FloatingNominal size is zero");
53 QL_REQUIRE(fixedNominal.size() > 0, "FixedNominal size is zero");
54 QL_REQUIRE(floatingNominal.size() % fixedNominal.size() == 0,
55 "Fixed nominal size (" << fixedNominal.size() << ") must divide floating nominal size ("
56 << floatingNominal.size() << ")");
57 QL_REQUIRE(fixedNominal_.size() == fixedRate_.size(), "Fixed nominal size (" << fixedNominal_.size()
58 << ") does not match fixed rate size ("
59 << fixedRate_.size() << ")");
60 QL_REQUIRE(fixedNominal_.size() == fixedSchedule_.size() - 1,
61 "Fixed nominal size (" << fixedNominal_.size() << ") does not match schedule size ("
62 << fixedSchedule_.size() << ") - 1");
63 QL_REQUIRE(fixedNominal_.size() == lowerNotionalBound_.size(),
64 "Fixed nominal size (" << fixedNominal_.size() << ") does not match lowerNotionalBound size ("
65 << lowerNotionalBound_.size() << ")");
66
67 QL_REQUIRE(floatingNominal_.size() == floatingSchedule_.size() - 1,
68 "Floating nominal size (" << floatingNominal_.size() << ") does not match schedule size ("
69 << floatingSchedule_.size() << ") - 1");
70
71 QL_REQUIRE(floatingNominal_.size() == gearing_.size(),
72 "Floating nominal size (" << floatingNominal_.size() << ") does not match gearing size ("
73 << gearing_.size() << ")");
74 QL_REQUIRE(floatingNominal_.size() == spread_.size(), "Floating nominal size (" << floatingNominal_.size()
75 << ") does not match spread size ("
76 << spread_.size() << ")");
77 QL_REQUIRE(floatingNominal_.size() == cappedRate_.size(),
78 "Floating nominal size (" << floatingNominal_.size() << ") does not match spread size ("
79 << cappedRate_.size() << ")");
80 QL_REQUIRE(floatingNominal_.size() == flooredRate_.size(),
81 "Floating nominal size (" << floatingNominal_.size() << ") does not match spread size ("
82 << flooredRate_.size() << ")");
83
84 QL_REQUIRE(notionalCanBeDecreased.empty() || notionalCanBeDecreased_.size() == fixedSchedule.size() - 1,
85 "notionalCanBeDecreased (" << notionalCanBeDecreased_.size() << ") must match number of fixed periods ("
86 << fixedSchedule.size() - 1 << ")");
87
88 // if the gearing is zero then the ibor leg will be set up with fixed
89 // coupons which makes trouble here in this context. We therefore use
90 // a dirty trick and enforce the gearing to be non zero.
91
92 // TODO do we need this?
93
94 std::vector<Real> gearingTmp(gearing_);
95 for (Size i = 0; i < gearingTmp.size(); ++i) {
96 if (close(gearingTmp[i], 0.0))
97 gearingTmp[i] = QL_EPSILON;
98 }
99
100 legs_[0] = FixedRateLeg(fixedSchedule_)
101 .withNotionals(fixedNominal_)
102 .withCouponRates(fixedRate_, fixedDayCount_)
103 .withPaymentAdjustment(paymentConvention_);
104
105 legs_[1] = IborLeg(floatingSchedule_, iborIndex_)
106 .withNotionals(floatingNominal_)
107 .withPaymentDayCounter(floatingDayCount_)
108 .withPaymentAdjustment(paymentConvention_)
109 .withSpreads(spread_)
110 .withGearings(gearingTmp)
111 .withCaps(cappedRate_)
112 .withFloors(flooredRate_);
113
114 for (Leg::const_iterator i = legs_[1].begin(); i < legs_[1].end(); ++i)
115 registerWith(*i);
116
117 auto cpnPricer = QuantLib::ext::make_shared<BlackIborCouponPricer>();
118 setCouponPricer(legs_[1], cpnPricer);
119
120 switch (type_) {
121 case VanillaSwap::Payer:
122 payer_[0] = -1.0;
123 payer_[1] = +1.0;
124 break;
125 case VanillaSwap::Receiver:
126 payer_[0] = +1.0;
127 payer_[1] = -1.0;
128 break;
129 default:
130 QL_FAIL("Unknown vanilla swap type");
131 }
132}
const std::vector< bool > & notionalCanBeDecreased() const
Definition: flexiswap.hpp:92
const std::vector< Real > & fixedNominal() const
Definition: flexiswap.hpp:75
const std::vector< Real > fixedRate_
Definition: flexiswap.hpp:106
const std::vector< Real > & flooredRate() const
Definition: flexiswap.hpp:87
const DayCounter & fixedDayCount() const
Definition: flexiswap.hpp:80
const std::vector< Real > & gearing() const
Definition: flexiswap.hpp:84
BusinessDayConvention paymentConvention() const
Definition: flexiswap.hpp:94
const Schedule & fixedSchedule() const
Definition: flexiswap.hpp:78
const Schedule fixedSchedule_
Definition: flexiswap.hpp:105
const std::vector< Real > lowerNotionalBound_
Definition: flexiswap.hpp:115
const std::vector< Real > & lowerNotionalBound() const
Definition: flexiswap.hpp:90
const std::vector< Real > cappedRate_
Definition: flexiswap.hpp:112
const std::vector< Real > fixedNominal_
Definition: flexiswap.hpp:104
const Schedule & floatingSchedule() const
Definition: flexiswap.hpp:82
VanillaSwap::Type type() const
Definition: flexiswap.hpp:74
const QuantLib::ext::shared_ptr< IborIndex > & iborIndex() const
Definition: flexiswap.hpp:83
const std::vector< Real > & fixedRate() const
Definition: flexiswap.hpp:79
const QuantLib::Position::Type optionPosition_
Definition: flexiswap.hpp:116
const DayCounter fixedDayCount_
Definition: flexiswap.hpp:107
const std::vector< bool > notionalCanBeDecreased_
Definition: flexiswap.hpp:117
const std::vector< Real > flooredRate_
Definition: flexiswap.hpp:113
const Schedule floatingSchedule_
Definition: flexiswap.hpp:108
const std::vector< Real > & spread() const
Definition: flexiswap.hpp:85
const DayCounter & floatingDayCount() const
Definition: flexiswap.hpp:88
BusinessDayConvention paymentConvention_
Definition: flexiswap.hpp:118
const VanillaSwap::Type type_
Definition: flexiswap.hpp:103
const std::vector< Real > gearing_
Definition: flexiswap.hpp:110
const DayCounter floatingDayCount_
Definition: flexiswap.hpp:114
const std::vector< Real > & cappedRate() const
Definition: flexiswap.hpp:86
const std::vector< Real > floatingNominal_
Definition: flexiswap.hpp:104
const QuantLib::Position::Type optionPosition() const
Definition: flexiswap.hpp:91
const QuantLib::ext::shared_ptr< IborIndex > iborIndex_
Definition: flexiswap.hpp:109
const std::vector< Real > spread_
Definition: flexiswap.hpp:111
const std::vector< Real > & floatingNominal() const
Definition: flexiswap.hpp:76
void setCouponPricer(const Leg &leg, const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Set Coupon Pricer.
+ Here is the call graph for this function:

Member Function Documentation

◆ type()

VanillaSwap::Type type ( ) const

Definition at line 74 of file flexiswap.hpp.

74{ return type_; }

◆ fixedNominal()

const std::vector< Real > & fixedNominal ( ) const

Definition at line 75 of file flexiswap.hpp.

75{ return fixedNominal_; }
+ Here is the caller graph for this function:

◆ floatingNominal()

const std::vector< Real > & floatingNominal ( ) const

Definition at line 76 of file flexiswap.hpp.

76{ return floatingNominal_; }
+ Here is the caller graph for this function:

◆ fixedSchedule()

const Schedule & fixedSchedule ( ) const

Definition at line 78 of file flexiswap.hpp.

78{ return fixedSchedule_; }
+ Here is the caller graph for this function:

◆ fixedRate()

const std::vector< Real > & fixedRate ( ) const

Definition at line 79 of file flexiswap.hpp.

79{ return fixedRate_; }

◆ fixedDayCount()

const DayCounter & fixedDayCount ( ) const

Definition at line 80 of file flexiswap.hpp.

80{ return fixedDayCount_; }

◆ floatingSchedule()

const Schedule & floatingSchedule ( ) const

Definition at line 82 of file flexiswap.hpp.

82{ return floatingSchedule_; }

◆ iborIndex()

const QuantLib::ext::shared_ptr< IborIndex > & iborIndex ( ) const

Definition at line 83 of file flexiswap.hpp.

83{ return iborIndex_; }
+ Here is the caller graph for this function:

◆ gearing()

const std::vector< Real > & gearing ( ) const

Definition at line 84 of file flexiswap.hpp.

84{ return gearing_; }

◆ spread()

const std::vector< Real > & spread ( ) const

Definition at line 85 of file flexiswap.hpp.

85{ return spread_; }

◆ cappedRate()

const std::vector< Real > & cappedRate ( ) const

Definition at line 86 of file flexiswap.hpp.

86{ return cappedRate_; }

◆ flooredRate()

const std::vector< Real > & flooredRate ( ) const

Definition at line 87 of file flexiswap.hpp.

87{ return flooredRate_; }

◆ floatingDayCount()

const DayCounter & floatingDayCount ( ) const

Definition at line 88 of file flexiswap.hpp.

88{ return floatingDayCount_; }

◆ lowerNotionalBound()

const std::vector< Real > & lowerNotionalBound ( ) const

Definition at line 90 of file flexiswap.hpp.

90{ return lowerNotionalBound_; }

◆ optionPosition()

const QuantLib::Position::Type optionPosition ( ) const

Definition at line 91 of file flexiswap.hpp.

91{ return optionPosition_; }

◆ notionalCanBeDecreased()

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

Definition at line 92 of file flexiswap.hpp.

+ Here is the caller graph for this function:

◆ paymentConvention()

BusinessDayConvention paymentConvention ( ) const

Definition at line 94 of file flexiswap.hpp.

94{ return paymentConvention_; }
+ Here is the caller graph for this function:

◆ fixedLeg()

const Leg & fixedLeg ( ) const

Definition at line 96 of file flexiswap.hpp.

96{ return legs_[0]; }
+ Here is the caller graph for this function:

◆ floatingLeg()

const Leg & floatingLeg ( ) const

Definition at line 97 of file flexiswap.hpp.

97{ return legs_[1]; }
+ Here is the caller graph for this function:

◆ underlyingValue()

Real underlyingValue ( ) const

Definition at line 195 of file flexiswap.cpp.

195 {
196 calculate();
197 QL_REQUIRE(underlyingValue_ != Null<Real>(), "FlexiSwap: underlying value not provided");
198 return underlyingValue_;
199}
+ Here is the caller graph for this function:

◆ setupArguments()

void setupArguments ( QuantLib::PricingEngine::arguments ) const
overrideprivate

Definition at line 134 of file flexiswap.cpp.

134 {
135 Swap::setupArguments(args);
136 auto arguments = dynamic_cast<FlexiSwap::arguments*>(args);
137
138 // QL_REQUIRE(arguments != nullptr, "FlexiSwap::setupArguments(): wrong argument type");
139
140 // allow for swap engine
141 if (arguments == nullptr)
142 return;
143
144 arguments->type = type_;
145 arguments->fixedNominal = fixedNominal_;
146 arguments->floatingNominal = floatingNominal_;
147 arguments->fixedRate = fixedRate_;
148 arguments->iborIndex = iborIndex();
149 arguments->cappedRate = cappedRate_;
150 arguments->flooredRate = flooredRate_;
151 arguments->lowerNotionalBound = lowerNotionalBound_;
152 arguments->optionPosition = optionPosition_;
153 arguments->notionalCanBeDecreased =
154 notionalCanBeDecreased_.empty() ? std::vector<bool>(fixedNominal_.size(), true) : notionalCanBeDecreased_;
155
156 const Leg& fixedCoupons = fixedLeg();
157
158 arguments->fixedResetDates = arguments->fixedPayDates = std::vector<Date>(fixedCoupons.size());
159 arguments->fixedCoupons = std::vector<Real>(fixedCoupons.size());
160
161 for (Size i = 0; i < fixedCoupons.size(); ++i) {
162 auto coupon = QuantLib::ext::dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);
163 QL_REQUIRE(coupon != nullptr, "FlexiSwap::setupArguments(): expected fixed rate coupon");
164 arguments->fixedPayDates[i] = coupon->date();
165 arguments->fixedResetDates[i] = coupon->accrualStartDate();
166 arguments->fixedCoupons[i] = coupon->amount();
167 }
168
169 const Leg& floatingCoupons = floatingLeg();
170
171 arguments->floatingResetDates = arguments->floatingPayDates = arguments->floatingFixingDates =
172 std::vector<Date>(floatingCoupons.size());
173 arguments->floatingAccrualTimes = std::vector<Time>(floatingCoupons.size());
174 arguments->floatingSpreads = std::vector<Spread>(floatingCoupons.size());
175 arguments->floatingGearings = std::vector<Real>(floatingCoupons.size());
176 arguments->floatingCoupons = std::vector<Real>(floatingCoupons.size());
177
178 for (Size i = 0; i < floatingCoupons.size(); ++i) {
179 auto coupon = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(floatingCoupons[i]);
180 QL_REQUIRE(coupon != nullptr, "FlexiSwap::setupArguments(): expected fixed rate coupon");
181 arguments->floatingResetDates[i] = coupon->accrualStartDate();
182 arguments->floatingPayDates[i] = coupon->date();
183 arguments->floatingFixingDates[i] = coupon->fixingDate();
184 arguments->floatingAccrualTimes[i] = coupon->accrualPeriod();
185 arguments->floatingSpreads[i] = coupon->spread();
186 arguments->floatingGearings[i] = coupon->gearing();
187 try {
188 arguments->floatingCoupons[i] = coupon->amount();
189 } catch (const std::exception&) {
190 arguments->floatingCoupons[i] = Null<Real>();
191 }
192 }
193}
const Leg & floatingLeg() const
Definition: flexiswap.hpp:97
const Leg & fixedLeg() const
Definition: flexiswap.hpp:96
+ Here is the call graph for this function:

◆ setupExpired()

void setupExpired ( ) const
overrideprivate

Definition at line 201 of file flexiswap.cpp.

201 {
202 Swap::setupExpired();
203 underlyingValue_ = 0.0;
204}

◆ fetchResults()

void fetchResults ( const QuantLib::PricingEngine::results *  ) const
overrideprivate

Definition at line 206 of file flexiswap.cpp.

206 {
207 Swap::fetchResults(r);
208 auto results = dynamic_cast<const FlexiSwap::results*>(r);
209
210 // QL_REQUIRE(results != nullptr, "FlexiSwap::fetchResult(): wrong result type");
211
212 // allow for swap engine
213 if (results == nullptr)
214 return;
215
216 underlyingValue_ = results->underlyingValue;
217}

Member Data Documentation

◆ type_

const VanillaSwap::Type type_
private

Definition at line 103 of file flexiswap.hpp.

◆ fixedNominal_

const std::vector<Real> fixedNominal_
private

Definition at line 104 of file flexiswap.hpp.

◆ floatingNominal_

const std::vector<Real> floatingNominal_
private

Definition at line 104 of file flexiswap.hpp.

◆ fixedSchedule_

const Schedule fixedSchedule_
private

Definition at line 105 of file flexiswap.hpp.

◆ fixedRate_

const std::vector<Real> fixedRate_
private

Definition at line 106 of file flexiswap.hpp.

◆ fixedDayCount_

const DayCounter fixedDayCount_
private

Definition at line 107 of file flexiswap.hpp.

◆ floatingSchedule_

const Schedule floatingSchedule_
private

Definition at line 108 of file flexiswap.hpp.

◆ iborIndex_

const QuantLib::ext::shared_ptr<IborIndex> iborIndex_
private

Definition at line 109 of file flexiswap.hpp.

◆ gearing_

const std::vector<Real> gearing_
private

Definition at line 110 of file flexiswap.hpp.

◆ spread_

const std::vector<Real> spread_
private

Definition at line 111 of file flexiswap.hpp.

◆ cappedRate_

const std::vector<Real> cappedRate_
private

Definition at line 112 of file flexiswap.hpp.

◆ flooredRate_

const std::vector<Real> flooredRate_
private

Definition at line 113 of file flexiswap.hpp.

◆ floatingDayCount_

const DayCounter floatingDayCount_
private

Definition at line 114 of file flexiswap.hpp.

◆ lowerNotionalBound_

const std::vector<Real> lowerNotionalBound_
private

Definition at line 115 of file flexiswap.hpp.

◆ optionPosition_

const QuantLib::Position::Type optionPosition_
private

Definition at line 116 of file flexiswap.hpp.

◆ notionalCanBeDecreased_

const std::vector<bool> notionalCanBeDecreased_
private

Definition at line 117 of file flexiswap.hpp.

◆ paymentConvention_

BusinessDayConvention paymentConvention_
private

Definition at line 118 of file flexiswap.hpp.

◆ underlyingValue_

Real underlyingValue_
mutableprivate

Definition at line 124 of file flexiswap.hpp.