| 1 | /* |
| 2 | Copyright (C) 2006 Giorgio Facchinetti |
| 3 | Copyright (C) 2006 Mario Pucci |
| 4 | Copyright (C) 2006, 2007 StatPro Italia srl |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, but |
| 17 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. |
| 19 | */ |
| 20 | |
| 21 | #include <ql/cashflows/capflooredcoupon.hpp> |
| 22 | #include <ql/cashflows/cashflowvectors.hpp> |
| 23 | #include <ql/cashflows/cmscoupon.hpp> |
| 24 | #include <ql/indexes/swapindex.hpp> |
| 25 | #include <utility> |
| 26 | |
| 27 | namespace QuantLib { |
| 28 | |
| 29 | CmsCoupon::CmsCoupon(const Date& paymentDate, |
| 30 | Real nominal, |
| 31 | const Date& startDate, |
| 32 | const Date& endDate, |
| 33 | Natural fixingDays, |
| 34 | const ext::shared_ptr<SwapIndex>& swapIndex, |
| 35 | Real gearing, |
| 36 | Spread spread, |
| 37 | const Date& refPeriodStart, |
| 38 | const Date& refPeriodEnd, |
| 39 | const DayCounter& dayCounter, |
| 40 | bool isInArrears, |
| 41 | const Date& exCouponDate) |
| 42 | : FloatingRateCoupon(paymentDate, nominal, startDate, endDate, |
| 43 | fixingDays, swapIndex, gearing, spread, |
| 44 | refPeriodStart, refPeriodEnd, |
| 45 | dayCounter, isInArrears, exCouponDate), |
| 46 | swapIndex_(swapIndex) {} |
| 47 | |
| 48 | void CmsCoupon::accept(AcyclicVisitor& v) { |
| 49 | auto* v1 = dynamic_cast<Visitor<CmsCoupon>*>(&v); |
| 50 | if (v1 != nullptr) |
| 51 | v1->visit(*this); |
| 52 | else |
| 53 | FloatingRateCoupon::accept(v); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | CmsLeg::CmsLeg(Schedule schedule, ext::shared_ptr<SwapIndex> swapIndex) |
| 58 | : schedule_(std::move(schedule)), swapIndex_(std::move(swapIndex)) { |
| 59 | QL_REQUIRE(swapIndex_, "no index provided" ); |
| 60 | } |
| 61 | |
| 62 | CmsLeg& CmsLeg::withNotionals(Real notional) { |
| 63 | notionals_ = std::vector<Real>(1, notional); |
| 64 | return *this; |
| 65 | } |
| 66 | |
| 67 | CmsLeg& CmsLeg::withNotionals(const std::vector<Real>& notionals) { |
| 68 | notionals_ = notionals; |
| 69 | return *this; |
| 70 | } |
| 71 | |
| 72 | CmsLeg& CmsLeg::withPaymentDayCounter(const DayCounter& dayCounter) { |
| 73 | paymentDayCounter_ = dayCounter; |
| 74 | return *this; |
| 75 | } |
| 76 | |
| 77 | CmsLeg& CmsLeg::withPaymentAdjustment(BusinessDayConvention convention) { |
| 78 | paymentAdjustment_ = convention; |
| 79 | return *this; |
| 80 | } |
| 81 | |
| 82 | CmsLeg& CmsLeg::withFixingDays(Natural fixingDays) { |
| 83 | fixingDays_ = std::vector<Natural>(1, fixingDays); |
| 84 | return *this; |
| 85 | } |
| 86 | |
| 87 | CmsLeg& CmsLeg::withFixingDays(const std::vector<Natural>& fixingDays) { |
| 88 | fixingDays_ = fixingDays; |
| 89 | return *this; |
| 90 | } |
| 91 | |
| 92 | CmsLeg& CmsLeg::withGearings(Real gearing) { |
| 93 | gearings_ = std::vector<Real>(1, gearing); |
| 94 | return *this; |
| 95 | } |
| 96 | |
| 97 | CmsLeg& CmsLeg::withGearings(const std::vector<Real>& gearings) { |
| 98 | gearings_ = gearings; |
| 99 | return *this; |
| 100 | } |
| 101 | |
| 102 | CmsLeg& CmsLeg::withSpreads(Spread spread) { |
| 103 | spreads_ = std::vector<Spread>(1, spread); |
| 104 | return *this; |
| 105 | } |
| 106 | |
| 107 | CmsLeg& CmsLeg::withSpreads(const std::vector<Spread>& spreads) { |
| 108 | spreads_ = spreads; |
| 109 | return *this; |
| 110 | } |
| 111 | |
| 112 | CmsLeg& CmsLeg::withCaps(Rate cap) { |
| 113 | caps_ = std::vector<Rate>(1, cap); |
| 114 | return *this; |
| 115 | } |
| 116 | |
| 117 | CmsLeg& CmsLeg::withCaps(const std::vector<Rate>& caps) { |
| 118 | caps_ = caps; |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | CmsLeg& CmsLeg::withFloors(Rate floor) { |
| 123 | floors_ = std::vector<Rate>(1, floor); |
| 124 | return *this; |
| 125 | } |
| 126 | |
| 127 | CmsLeg& CmsLeg::withFloors(const std::vector<Rate>& floors) { |
| 128 | floors_ = floors; |
| 129 | return *this; |
| 130 | } |
| 131 | |
| 132 | CmsLeg& CmsLeg::inArrears(bool flag) { |
| 133 | inArrears_ = flag; |
| 134 | return *this; |
| 135 | } |
| 136 | |
| 137 | CmsLeg& CmsLeg::withZeroPayments(bool flag) { |
| 138 | zeroPayments_ = flag; |
| 139 | return *this; |
| 140 | } |
| 141 | |
| 142 | CmsLeg& CmsLeg::withExCouponPeriod( |
| 143 | const Period& period, |
| 144 | const Calendar& cal, |
| 145 | BusinessDayConvention convention, |
| 146 | bool endOfMonth) { |
| 147 | exCouponPeriod_ = period; |
| 148 | exCouponCalendar_ = cal; |
| 149 | exCouponAdjustment_ = convention; |
| 150 | exCouponEndOfMonth_ = endOfMonth; |
| 151 | return *this; |
| 152 | } |
| 153 | |
| 154 | CmsLeg::operator Leg() const { |
| 155 | return FloatingLeg<SwapIndex, CmsCoupon, CappedFlooredCmsCoupon>( |
| 156 | schedule: schedule_, nominals: notionals_, index: swapIndex_, paymentDayCounter: paymentDayCounter_, |
| 157 | paymentAdj: paymentAdjustment_, fixingDays: fixingDays_, gearings: gearings_, spreads: spreads_, |
| 158 | caps: caps_, floors: floors_, isInArrears: inArrears_, isZero: zeroPayments_, |
| 159 | paymentLag: 0, paymentCalendar: Calendar(), |
| 160 | exCouponPeriod: exCouponPeriod_, exCouponCalendar: exCouponCalendar_, |
| 161 | exCouponAdjustment: exCouponAdjustment_, exCouponEndOfMonth: exCouponEndOfMonth_); |
| 162 | } |
| 163 | |
| 164 | } |
| 165 | |