1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2007, 2011 Ferdinando Ametrano 5 Copyright (C) 2007 Giorgio Facchinetti 6 Copyright (C) 2007 Cristina Duminuco 7 Copyright (C) 2007 StatPro Italia srl 8 Copyright (C) 2017 Joseph Jeisman 9 Copyright (C) 2017 Fabrice Lecuyer 10 11 This file is part of QuantLib, a free-software/open-source library 12 for financial quantitative analysts and developers - http://quantlib.org/ 13 14 QuantLib is free software: you can redistribute it and/or modify it 15 under the terms of the QuantLib license. You should have received a 16 copy of the license along with this program; if not, please email 17 <quantlib-dev@lists.sf.net>. The license is also available online at 18 <http://quantlib.org/license.shtml>. 19 20 This program is distributed in the hope that it will be useful, but WITHOUT 21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 FOR A PARTICULAR PURPOSE. See the license for more details. 23 */ 24 25 /*! \file iborcoupon.hpp 26 \brief Coupon paying a Libor-type index 27 */ 28 29 #ifndef quantlib_ibor_coupon_hpp 30 #define quantlib_ibor_coupon_hpp 31 32 #include <ql/cashflows/floatingratecoupon.hpp> 33 #include <ql/indexes/iborindex.hpp> 34 #include <ql/time/schedule.hpp> 35 36 namespace QuantLib { 37 38 //! %Coupon paying a Libor-type index 39 class IborCoupon : public FloatingRateCoupon { 40 public: 41 IborCoupon(const Date& paymentDate, 42 Real nominal, 43 const Date& startDate, 44 const Date& endDate, 45 Natural fixingDays, 46 const ext::shared_ptr<IborIndex>& index, 47 Real gearing = 1.0, 48 Spread spread = 0.0, 49 const Date& refPeriodStart = Date(), 50 const Date& refPeriodEnd = Date(), 51 const DayCounter& dayCounter = DayCounter(), 52 bool isInArrears = false, 53 const Date& exCouponDate = Date()); 54 //! \name Inspectors 55 //@{ iborIndex() const56 const ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; } 57 //! this is dependent on usingAtParCoupons() fixingEndDate() const58 const Date& fixingEndDate() const { return fixingEndDate_; } 59 //@} 60 //! \name FloatingRateCoupon interface 61 //@{ 62 //! Implemented in order to manage the case of par coupon 63 Rate indexFixing() const; 64 //@} 65 //! \name Visitability 66 //@{ 67 virtual void accept(AcyclicVisitor&); 68 //@} 69 private: 70 ext::shared_ptr<IborIndex> iborIndex_; 71 Date fixingDate_, fixingValueDate_, fixingEndDate_; 72 Time spanningTime_; 73 74 public: 75 /*! When called, IborCoupons are created as indexed coupons instead of par coupons. This 76 * method must be called before any IborCoupon is created, otherwise an exception is thrown. 77 */ 78 static void createAtParCoupons(); 79 80 /*! When called, IborCoupons are created as par coupons instead of indexed coupons. This 81 * method must be called before any IborCoupon is created, otherwise an exception is thrown. 82 */ 83 static void createIndexedCoupons(); 84 85 /*! If true the IborCoupons are created as par coupons and vice versa. 86 * The default depends on the compiler flag QL_USE_INDEXED_COUPON and can be overwritten by 87 * createAtParCoupons() and createIndexedCoupons() 88 */ usingAtParCoupons()89 static bool usingAtParCoupons() { return usingAtParCoupons_; } 90 91 private: 92 static bool constructorWasNotCalled_; 93 static bool usingAtParCoupons_; 94 }; 95 96 97 //! helper class building a sequence of capped/floored ibor-rate coupons 98 class IborLeg { 99 public: 100 IborLeg(const Schedule& schedule, const ext::shared_ptr<IborIndex>& index); 101 IborLeg& withNotionals(Real notional); 102 IborLeg& withNotionals(const std::vector<Real>& notionals); 103 IborLeg& withPaymentDayCounter(const DayCounter&); 104 IborLeg& withPaymentAdjustment(BusinessDayConvention); 105 IborLeg& withPaymentLag(Natural lag); 106 IborLeg& withPaymentCalendar(const Calendar&); 107 IborLeg& withFixingDays(Natural fixingDays); 108 IborLeg& withFixingDays(const std::vector<Natural>& fixingDays); 109 IborLeg& withGearings(Real gearing); 110 IborLeg& withGearings(const std::vector<Real>& gearings); 111 IborLeg& withSpreads(Spread spread); 112 IborLeg& withSpreads(const std::vector<Spread>& spreads); 113 IborLeg& withCaps(Rate cap); 114 IborLeg& withCaps(const std::vector<Rate>& caps); 115 IborLeg& withFloors(Rate floor); 116 IborLeg& withFloors(const std::vector<Rate>& floors); 117 IborLeg& inArrears(bool flag = true); 118 IborLeg& withZeroPayments(bool flag = true); 119 IborLeg& withExCouponPeriod(const Period&, 120 const Calendar&, 121 BusinessDayConvention, 122 bool endOfMonth = false); 123 operator Leg() const; 124 125 private: 126 Schedule schedule_; 127 ext::shared_ptr<IborIndex> index_; 128 std::vector<Real> notionals_; 129 DayCounter paymentDayCounter_; 130 BusinessDayConvention paymentAdjustment_; 131 Natural paymentLag_; 132 Calendar paymentCalendar_; 133 std::vector<Natural> fixingDays_; 134 std::vector<Real> gearings_; 135 std::vector<Spread> spreads_; 136 std::vector<Rate> caps_, floors_; 137 bool inArrears_, zeroPayments_; 138 Period exCouponPeriod_; 139 Calendar exCouponCalendar_; 140 BusinessDayConvention exCouponAdjustment_; 141 bool exCouponEndOfMonth_; 142 }; 143 144 } 145 146 #endif 147