20#include <ql/cashflows/capflooredcoupon.hpp>
21#include <ql/cashflows/cashflows.hpp>
22#include <ql/cashflows/cashflowvectors.hpp>
23#include <ql/cashflows/cmscoupon.hpp>
24#include <ql/cashflows/couponpricer.hpp>
25#include <ql/cashflows/iborcoupon.hpp>
26#include <ql/cashflows/simplecashflow.hpp>
27#include <ql/experimental/coupons/cmsspreadcoupon.hpp>
28#include <ql/indexes/iborindex.hpp>
29#include <ql/indexes/swapindex.hpp>
30#include <ql/instruments/floatfloatswap.hpp>
31#include <ql/termstructures/yieldtermstructure.hpp>
32#include <ql/optional.hpp>
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)), schedule1_(schedule1),
60 schedule2_(schedule2), index1_(
std::move(index1)), index2_(
std::move(index2)),
61 gearing1_(
std::vector<
Real>(schedule1.size() - 1, gearing1)),
62 gearing2_(
std::vector<
Real>(schedule2.size() - 1, gearing2)),
63 spread1_(
std::vector<
Real>(schedule1.size() - 1, spread1)),
64 spread2_(
std::vector<
Real>(schedule2.size() - 1, spread2)),
65 cappedRate1_(
std::vector<
Real>(schedule1.size() - 1, cappedRate1)),
66 flooredRate1_(
std::vector<
Real>(schedule1.size() - 1, flooredRate1)),
67 cappedRate2_(
std::vector<
Real>(schedule2.size() - 1, cappedRate2)),
68 flooredRate2_(
std::vector<
Real>(schedule2.size() - 1, flooredRate2)),
69 dayCount1_(
std::move(dayCount1)), dayCount2_(
std::move(dayCount2)),
70 intermediateCapitalExchange_(intermediateCapitalExchange),
71 finalCapitalExchange_(finalCapitalExchange) {
77 std::vector<Real> nominal1,
78 std::vector<Real> nominal2,
80 ext::shared_ptr<InterestRateIndex> index1,
83 ext::shared_ptr<InterestRateIndex> index2,
85 const bool intermediateCapitalExchange,
86 const bool finalCapitalExchange,
87 std::vector<Real> gearing1,
88 std::vector<Real> spread1,
89 std::vector<Real> cappedRate1,
90 std::vector<Real> flooredRate1,
91 std::vector<Real> gearing2,
92 std::vector<Real> spread2,
93 std::vector<Real> cappedRate2,
94 std::vector<Real> flooredRate2,
95 const ext::optional<BusinessDayConvention>& paymentConvention1,
96 const ext::optional<BusinessDayConvention>& paymentConvention2)
97 :
Swap(2), type_(type), nominal1_(
std::move(nominal1)), nominal2_(
std::move(nominal2)),
98 schedule1_(
std::move(schedule1)), schedule2_(
std::move(schedule2)),
99 index1_(
std::move(index1)), index2_(
std::move(index2)), gearing1_(
std::move(gearing1)),
100 gearing2_(
std::move(gearing2)), spread1_(
std::move(spread1)), spread2_(
std::move(spread2)),
101 cappedRate1_(
std::move(cappedRate1)), flooredRate1_(
std::move(flooredRate1)),
102 cappedRate2_(
std::move(cappedRate2)), flooredRate2_(
std::move(flooredRate2)),
103 dayCount1_(
std::move(dayCount1)), dayCount2_(
std::move(dayCount2)),
104 intermediateCapitalExchange_(intermediateCapitalExchange),
105 finalCapitalExchange_(finalCapitalExchange) {
111 ext::optional<BusinessDayConvention> paymentConvention1,
112 ext::optional<BusinessDayConvention> paymentConvention2) {
116 <<
") does not match schedule1 size ("
120 <<
") does not match schedule2 size ("
123 "nominal1 size (" <<
nominal1_.size() <<
") does not match gearing1 size ("
126 "nominal2 size (" <<
nominal2_.size() <<
") does not match gearing2 size ("
129 "nominal1 size (" <<
nominal1_.size() <<
") does not match cappedRate1 size ("
132 "nominal2 size (" <<
nominal2_.size() <<
") does not match cappedRate2 size ("
135 "nominal1 size (" <<
nominal1_.size() <<
") does not match flooredRate1 size ("
138 "nominal2 size (" <<
nominal2_.size() <<
") does not match flooredRate2 size ("
173 "cappedRate1 must be null for all or none entry ("
178 "cappedRate 1 must be null for all or none entry ("
185 "cappedRate2 must be null for all or none entry ("
190 "cappedRate2 must be null for all or none entry ("
197 "flooredRate1 must be null for all or none entry ("
202 "flooredRate 1 must be null for all or none entry ("
209 "flooredRate2 must be null for all or none entry ("
214 "flooredRate2 must be null for all or none entry ("
228 ext::shared_ptr<IborIndex> ibor1 =
229 ext::dynamic_pointer_cast<IborIndex>(
index1_);
230 ext::shared_ptr<IborIndex> ibor2 =
231 ext::dynamic_pointer_cast<IborIndex>(
index2_);
232 ext::shared_ptr<SwapIndex> cms1 =
233 ext::dynamic_pointer_cast<SwapIndex>(
index1_);
234 ext::shared_ptr<SwapIndex> cms2 =
235 ext::dynamic_pointer_cast<SwapIndex>(
index2_);
236 ext::shared_ptr<SwapSpreadIndex> cmsspread1 =
237 ext::dynamic_pointer_cast<SwapSpreadIndex>(
index1_);
238 ext::shared_ptr<SwapSpreadIndex> cmsspread2 =
239 ext::dynamic_pointer_cast<SwapSpreadIndex>(
index2_);
241 QL_REQUIRE(ibor1 !=
nullptr || cms1 !=
nullptr || cmsspread1 !=
nullptr,
242 "index1 must be ibor or cms or cms spread");
243 QL_REQUIRE(ibor2 !=
nullptr || cms2 !=
nullptr || cmsspread2 !=
nullptr,
244 "index2 must be ibor or cms");
246 if (ibor1 !=
nullptr) {
260 if (ibor2 !=
nullptr) {
274 if (cms1 !=
nullptr) {
288 if (cms2 !=
nullptr) {
302 if (cmsspread1 !=
nullptr) {
316 if (cmsspread2 !=
nullptr) {
331 for (
Size i = 0; i <
legs_[0].size() - 1; i++) {
333 if (!
close(cap, 0.0)) {
334 auto it1 =
legs_[0].begin();
335 std::advance(it1, i + 1);
337 it1, ext::shared_ptr<CashFlow>(
340 std::advance(it2, i + 1);
345 for (
Size i = 0; i <
legs_[1].size() - 1; i++) {
347 if (!
close(cap, 0.0)) {
348 auto it1 =
legs_[1].begin();
349 std::advance(it1, i + 1);
351 it1, ext::shared_ptr<CashFlow>(
354 std::advance(it2, i + 1);
362 legs_[0].push_back(ext::shared_ptr<CashFlow>(
365 legs_[1].push_back(ext::shared_ptr<CashFlow>(
370 for (Leg::const_iterator i =
legs_[0].begin(); i <
legs_[0].end(); ++i)
373 for (Leg::const_iterator i =
legs_[1].begin(); i <
legs_[1].end(); ++i)
386 QL_FAIL(
"Unknown float float - swap type");
405 const Leg &leg1Coupons =
leg1();
406 const Leg &leg2Coupons =
leg2();
419 std::vector<Real>(leg1Coupons.size(),
Null<Real>());
421 std::vector<Real>(leg2Coupons.size(),
Null<Real>());
424 std::vector<bool>(leg1Coupons.size(),
false);
426 std::vector<bool>(leg2Coupons.size(),
false);
429 std::vector<Real>(leg1Coupons.size(),
Null<Real>());
431 std::vector<Real>(leg2Coupons.size(),
Null<Real>());
433 for (
Size i = 0; i < leg1Coupons.size(); ++i) {
434 ext::shared_ptr<FloatingRateCoupon> coupon =
435 ext::dynamic_pointer_cast<FloatingRateCoupon>(leg1Coupons[i]);
436 if (coupon !=
nullptr) {
449 ext::shared_ptr<CappedFlooredCoupon> cfcoupon =
450 ext::dynamic_pointer_cast<CappedFlooredCoupon>(
452 if (cfcoupon !=
nullptr) {
457 ext::shared_ptr<CashFlow> cashflow =
458 ext::dynamic_pointer_cast<CashFlow>(leg1Coupons[i]);
459 std::vector<Date>::const_iterator j =
463 "nominal redemption on "
465 <<
"has no corresponding coupon");
479 for (
Size i = 0; i < leg2Coupons.size(); ++i) {
480 ext::shared_ptr<FloatingRateCoupon> coupon =
481 ext::dynamic_pointer_cast<FloatingRateCoupon>(leg2Coupons[i]);
482 if (coupon !=
nullptr) {
495 ext::shared_ptr<CappedFlooredCoupon> cfcoupon =
496 ext::dynamic_pointer_cast<CappedFlooredCoupon>(
498 if (cfcoupon !=
nullptr) {
503 ext::shared_ptr<CashFlow> cashflow =
504 ext::dynamic_pointer_cast<CashFlow>(leg2Coupons[i]);
505 std::vector<Date>::const_iterator j =
509 "nominal redemption on "
511 <<
"has no corresponding coupon");
537 "nominal1 size is different from resetDates1 size");
539 "nominal1 size is different from fixingDates1 size");
541 "nominal1 size is different from payDates1 size");
543 "nominal1 size is different from spreads1 size");
545 "nominal1 size is different from gearings1 size");
547 "nominal1 size is different from cappedRates1 size");
549 "nominal1 size is different from flooredRates1 size");
551 "nominal1 size is different from coupons1 size");
553 "nominal1 size is different from accrualTimes1 size");
555 "nominal1 size is different from redemption1 size");
558 "nominal2 size is different from resetDates2 size");
560 "nominal2 size is different from fixingDates2 size");
562 "nominal2 size is different from payDates2 size");
564 "nominal2 size is different from spreads2 size");
566 "nominal2 size is different from gearings2 size");
568 "nominal2 size is different from cappedRates2 size");
570 "nominal2 size is different from flooredRates2 size");
572 "nominal2 size is different from coupons2 size");
574 "nominal2 size is different from accrualTimes2 size");
576 "nominal2 size is different from redemption2 size");
578 QL_REQUIRE(
index1 !=
nullptr,
"index1 is null");
579 QL_REQUIRE(
index2 !=
nullptr,
"index2 is null");
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_
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
FloatFloatSwap(Swap::Type type, Real nominal1, Real nominal2, const Schedule &schedule1, ext::shared_ptr< InterestRateIndex > index1, DayCounter dayCount1, const 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)
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_
std::size_t Size
size of a container
bool close(const Quantity &m1, const Quantity &m2, Size n)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.