41 ext::shared_ptr<InterestRateIndex> index1,
44 ext::shared_ptr<InterestRateIndex> index2,
46 const bool intermediateCapitalExchange,
47 const bool finalCapitalExchange,
50 const Real cappedRate1,
51 const Real flooredRate1,
54 const Real cappedRate2,
55 const Real flooredRate2,
56 const ext::optional<BusinessDayConvention>& paymentConvention1,
57 const ext::optional<BusinessDayConvention>& paymentConvention2)
58 :
Swap(2), type_(type), nominal1_(
std::vector<
Real>(schedule1.size() - 1, nominal1)),
59 nominal2_(
std::vector<
Real>(schedule2.size() - 1, nominal2)),
60 schedule1_(
std::move(schedule1)), schedule2_(
std::move(schedule2)),
61 index1_(
std::move(index1)), index2_(
std::move(index2)),
62 gearing1_(
std::vector<
Real>(schedule1_.size() - 1, gearing1)),
63 gearing2_(
std::vector<
Real>(schedule2_.size() - 1, gearing2)),
64 spread1_(
std::vector<
Real>(schedule1_.size() - 1, spread1)),
65 spread2_(
std::vector<
Real>(schedule2_.size() - 1, spread2)),
66 cappedRate1_(
std::vector<
Real>(schedule1_.size() - 1, cappedRate1)),
67 flooredRate1_(
std::vector<
Real>(schedule1_.size() - 1, flooredRate1)),
68 cappedRate2_(
std::vector<
Real>(schedule2_.size() - 1, cappedRate2)),
69 flooredRate2_(
std::vector<
Real>(schedule2_.size() - 1, flooredRate2)),
70 dayCount1_(
std::move(dayCount1)), dayCount2_(
std::move(dayCount2)),
71 intermediateCapitalExchange_(intermediateCapitalExchange),
72 finalCapitalExchange_(finalCapitalExchange) {
78 std::vector<Real> nominal1,
79 std::vector<Real> nominal2,
81 ext::shared_ptr<InterestRateIndex> index1,
84 ext::shared_ptr<InterestRateIndex> index2,
86 const bool intermediateCapitalExchange,
87 const bool finalCapitalExchange,
88 std::vector<Real> gearing1,
89 std::vector<Real> spread1,
90 std::vector<Real> cappedRate1,
91 std::vector<Real> flooredRate1,
92 std::vector<Real> gearing2,
93 std::vector<Real> spread2,
94 std::vector<Real> cappedRate2,
95 std::vector<Real> flooredRate2,
96 const ext::optional<BusinessDayConvention>& paymentConvention1,
97 const ext::optional<BusinessDayConvention>& paymentConvention2)
98 :
Swap(2), type_(type), nominal1_(
std::move(nominal1)), nominal2_(
std::move(nominal2)),
99 schedule1_(
std::move(schedule1)), schedule2_(
std::move(schedule2)),
100 index1_(
std::move(index1)), index2_(
std::move(index2)), gearing1_(
std::move(gearing1)),
101 gearing2_(
std::move(gearing2)), spread1_(
std::move(spread1)), spread2_(
std::move(spread2)),
102 cappedRate1_(
std::move(cappedRate1)), flooredRate1_(
std::move(flooredRate1)),
103 cappedRate2_(
std::move(cappedRate2)), flooredRate2_(
std::move(flooredRate2)),
104 dayCount1_(
std::move(dayCount1)), dayCount2_(
std::move(dayCount2)),
105 intermediateCapitalExchange_(intermediateCapitalExchange),
106 finalCapitalExchange_(finalCapitalExchange) {
112 ext::optional<BusinessDayConvention> paymentConvention1,
113 ext::optional<BusinessDayConvention> paymentConvention2) {
117 <<
") does not match schedule1 size ("
121 <<
") does not match schedule2 size ("
124 "nominal1 size (" <<
nominal1_.size() <<
") does not match gearing1 size ("
127 "nominal2 size (" <<
nominal2_.size() <<
") does not match gearing2 size ("
130 "nominal1 size (" <<
nominal1_.size() <<
") does not match cappedRate1 size ("
133 "nominal2 size (" <<
nominal2_.size() <<
") does not match cappedRate2 size ("
136 "nominal1 size (" <<
nominal1_.size() <<
") does not match flooredRate1 size ("
139 "nominal2 size (" <<
nominal2_.size() <<
") does not match flooredRate2 size ("
174 "cappedRate1 must be null for all or none entry ("
179 "cappedRate 1 must be null for all or none entry ("
186 "cappedRate2 must be null for all or none entry ("
191 "cappedRate2 must be null for all or none entry ("
198 "flooredRate1 must be null for all or none entry ("
203 "flooredRate 1 must be null for all or none entry ("
210 "flooredRate2 must be null for all or none entry ("
215 "flooredRate2 must be null for all or none entry ("
229 ext::shared_ptr<IborIndex> ibor1 =
230 ext::dynamic_pointer_cast<IborIndex>(
index1_);
231 ext::shared_ptr<IborIndex> ibor2 =
232 ext::dynamic_pointer_cast<IborIndex>(
index2_);
233 ext::shared_ptr<SwapIndex> cms1 =
234 ext::dynamic_pointer_cast<SwapIndex>(
index1_);
235 ext::shared_ptr<SwapIndex> cms2 =
236 ext::dynamic_pointer_cast<SwapIndex>(
index2_);
237 ext::shared_ptr<SwapSpreadIndex> cmsspread1 =
238 ext::dynamic_pointer_cast<SwapSpreadIndex>(
index1_);
239 ext::shared_ptr<SwapSpreadIndex> cmsspread2 =
240 ext::dynamic_pointer_cast<SwapSpreadIndex>(
index2_);
242 QL_REQUIRE(ibor1 !=
nullptr || cms1 !=
nullptr || cmsspread1 !=
nullptr,
243 "index1 must be ibor or cms or cms spread");
244 QL_REQUIRE(ibor2 !=
nullptr || cms2 !=
nullptr || cmsspread2 !=
nullptr,
245 "index2 must be ibor or cms");
247 if (ibor1 !=
nullptr) {
261 if (ibor2 !=
nullptr) {
275 if (cms1 !=
nullptr) {
289 if (cms2 !=
nullptr) {
303 if (cmsspread1 !=
nullptr) {
317 if (cmsspread2 !=
nullptr) {
332 for (
Size i = 0; i <
legs_[0].size() - 1; i++) {
334 if (!
close(cap, 0.0)) {
335 auto it1 =
legs_[0].begin();
336 std::advance(it1, i + 1);
338 it1, ext::shared_ptr<CashFlow>(
341 std::advance(it2, i + 1);
346 for (
Size i = 0; i <
legs_[1].size() - 1; i++) {
348 if (!
close(cap, 0.0)) {
349 auto it1 =
legs_[1].begin();
350 std::advance(it1, i + 1);
352 it1, ext::shared_ptr<CashFlow>(
355 std::advance(it2, i + 1);
363 legs_[0].push_back(ext::shared_ptr<CashFlow>(
366 legs_[1].push_back(ext::shared_ptr<CashFlow>(
371 for (Leg::const_iterator i =
legs_[0].begin(); i <
legs_[0].end(); ++i)
374 for (Leg::const_iterator i =
legs_[1].begin(); i <
legs_[1].end(); ++i)
387 QL_FAIL(
"Unknown float float - swap type");
406 const Leg &leg1Coupons =
leg1();
407 const Leg &leg2Coupons =
leg2();
420 std::vector<Real>(leg1Coupons.size(),
Null<Real>());
422 std::vector<Real>(leg2Coupons.size(),
Null<Real>());
425 std::vector<bool>(leg1Coupons.size(),
false);
427 std::vector<bool>(leg2Coupons.size(),
false);
430 std::vector<Real>(leg1Coupons.size(),
Null<Real>());
432 std::vector<Real>(leg2Coupons.size(),
Null<Real>());
434 for (
Size i = 0; i < leg1Coupons.size(); ++i) {
435 ext::shared_ptr<FloatingRateCoupon> coupon =
436 ext::dynamic_pointer_cast<FloatingRateCoupon>(leg1Coupons[i]);
437 if (coupon !=
nullptr) {
450 ext::shared_ptr<CappedFlooredCoupon> cfcoupon =
451 ext::dynamic_pointer_cast<CappedFlooredCoupon>(
453 if (cfcoupon !=
nullptr) {
458 ext::shared_ptr<CashFlow> cashflow =
459 ext::dynamic_pointer_cast<CashFlow>(leg1Coupons[i]);
460 std::vector<Date>::const_iterator j =
464 "nominal redemption on "
466 <<
"has no corresponding coupon");
480 for (
Size i = 0; i < leg2Coupons.size(); ++i) {
481 ext::shared_ptr<FloatingRateCoupon> coupon =
482 ext::dynamic_pointer_cast<FloatingRateCoupon>(leg2Coupons[i]);
483 if (coupon !=
nullptr) {
496 ext::shared_ptr<CappedFlooredCoupon> cfcoupon =
497 ext::dynamic_pointer_cast<CappedFlooredCoupon>(
499 if (cfcoupon !=
nullptr) {
504 ext::shared_ptr<CashFlow> cashflow =
505 ext::dynamic_pointer_cast<CashFlow>(leg2Coupons[i]);
506 std::vector<Date>::const_iterator j =
510 "nominal redemption on "
512 <<
"has no corresponding coupon");
538 "nominal1 size is different from resetDates1 size");
540 "nominal1 size is different from fixingDates1 size");
542 "nominal1 size is different from payDates1 size");
544 "nominal1 size is different from spreads1 size");
546 "nominal1 size is different from gearings1 size");
548 "nominal1 size is different from cappedRates1 size");
550 "nominal1 size is different from flooredRates1 size");
552 "nominal1 size is different from coupons1 size");
554 "nominal1 size is different from accrualTimes1 size");
556 "nominal1 size is different from redemption1 size");
559 "nominal2 size is different from resetDates2 size");
561 "nominal2 size is different from fixingDates2 size");
563 "nominal2 size is different from payDates2 size");
565 "nominal2 size is different from spreads2 size");
567 "nominal2 size is different from gearings2 size");
569 "nominal2 size is different from cappedRates2 size");
571 "nominal2 size is different from flooredRates2 size");
573 "nominal2 size is different from coupons2 size");
575 "nominal2 size is different from accrualTimes2 size");
577 "nominal2 size is different from redemption2 size");
Floating rate coupon with additional cap/floor.
Cash-flow analysis functions.
Cash flow vector builders.
helper class building a sequence of capped/floored cms-rate coupons
helper class building a sequence of capped/floored cms-spread-rate coupons
Arguments for float float swap calculation
std::vector< Real > leg2AccrualTimes
ext::shared_ptr< InterestRateIndex > index1
std::vector< bool > leg2IsRedemptionFlow
std::vector< Real > leg1AccrualTimes
std::vector< Real > leg2CappedRates
std::vector< Real > leg2Gearings
std::vector< bool > leg1IsRedemptionFlow
std::vector< Real > leg1FlooredRates
std::vector< Real > leg2Spreads
std::vector< Date > leg1PayDates
ext::shared_ptr< InterestRateIndex > index2
std::vector< Real > leg1Gearings
std::vector< Real > leg1CappedRates
std::vector< Real > leg1Coupons
std::vector< Real > nominal1
std::vector< Real > nominal2
std::vector< Date > leg2FixingDates
std::vector< Date > leg2PayDates
std::vector< Date > leg2ResetDates
std::vector< Date > leg1ResetDates
std::vector< Real > leg1Spreads
std::vector< Date > leg1FixingDates
std::vector< Real > leg2FlooredRates
void validate() const override
std::vector< Real > leg2Coupons
std::vector< Real > cappedRate2_
std::vector< Real > flooredRate2_
std::vector< Real > gearing2_
std::vector< Real > nominal1_
std::vector< Real > spread1_
std::vector< Real > cappedRate1_
const bool finalCapitalExchange_
BusinessDayConvention paymentConvention2() const
std::vector< Real > spread2_
const bool intermediateCapitalExchange_
std::vector< Real > nominal2_
std::vector< Real > gearing1_
BusinessDayConvention paymentConvention2_
FloatFloatSwap(Swap::Type type, Real nominal1, Real nominal2, Schedule schedule1, ext::shared_ptr< InterestRateIndex > index1, DayCounter dayCount1, Schedule schedule2, ext::shared_ptr< InterestRateIndex > index2, DayCounter dayCount2, bool intermediateCapitalExchange=false, bool finalCapitalExchange=false, Real gearing1=1.0, Real spread1=0.0, Real cappedRate1=Null< Real >(), Real flooredRate1=Null< Real >(), Real gearing2=1.0, Real spread2=0.0, Real cappedRate2=Null< Real >(), Real flooredRate2=Null< Real >(), const ext::optional< BusinessDayConvention > &paymentConvention1=ext::nullopt, const ext::optional< BusinessDayConvention > &paymentConvention2=ext::nullopt)
void setupArguments(PricingEngine::arguments *args) const override
BusinessDayConvention paymentConvention1_
std::vector< Real > flooredRate1_
ext::shared_ptr< InterestRateIndex > index1_
void init(ext::optional< BusinessDayConvention > paymentConvention1, ext::optional< BusinessDayConvention > paymentConvention2)
void setupExpired() const override
ext::shared_ptr< InterestRateIndex > index2_
void fetchResults(const PricingEngine::results *) const override
BusinessDayConvention paymentConvention1() const
helper class building a sequence of capped/floored ibor-rate coupons
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
BusinessDayConvention businessDayConvention() const
void validate() const override
void setupArguments(PricingEngine::arguments *) const override
const Leg & leg(Size j) const
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
std::vector< Real > payer_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
swap exchanging capped floored Libor or CMS coupons with quite general specification....
std::size_t Size
size of a container
Coupon paying a Libor-type index.
base class for Inter-Bank-Offered-Rate indexes
bool close(const Quantity &m1, const Quantity &m2, Size n)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Maps optional to either the boost or std implementation.
ext::shared_ptr< YieldTermStructure > r
Interest-rate term structure.