1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2009 Roland Lichters
5  Copyright (C) 2009 Ferdinando Ametrano
6  Copyright (C) 2014 Peter Caspers
7  Copyright (C) 2017 Joseph Jeisman
8  Copyright (C) 2017 Fabrice Lecuyer
9 
10  This file is part of QuantLib, a free-software/open-source library
11  for financial quantitative analysts and developers - http://quantlib.org/
12 
13  QuantLib is free software: you can redistribute it and/or modify it
14  under the terms of the QuantLib license.  You should have received a
15  copy of the license along with this program; if not, please email
16  <quantlib-dev@lists.sf.net>. The license is also available online at
17  <http://quantlib.org/license.shtml>.
18 
19  This program is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  FOR A PARTICULAR PURPOSE.  See the license for more details.
22 */
23 
24 /*! \file overnightindexedcoupon.hpp
25     \brief coupon paying the compounded daily overnight rate
26 */
27 
28 #ifndef quantlib_overnight_indexed_coupon_hpp
29 #define quantlib_overnight_indexed_coupon_hpp
30 
31 #include <ql/cashflows/floatingratecoupon.hpp>
32 #include <ql/indexes/iborindex.hpp>
33 #include <ql/time/schedule.hpp>
34 
35 namespace QuantLib {
36 
37     //! overnight coupon
38     /*! %Coupon paying the compounded interest due to daily overnight fixings.
39 
40         \warning telescopicValueDates optimizes the schedule for calculation speed,
41         but might fail to produce correct results if the coupon ages by more than
42         a grace period of 7 days. It is therefore recommended not to set this flag
43         to true unless you know exactly what you are doing. The intended use is
44         rather by the OISRateHelper which is safe, since it reinitialises the
45         instrument each time the evaluation date changes.
46     */
47     class OvernightIndexedCoupon : public FloatingRateCoupon {
48       public:
49         OvernightIndexedCoupon(
50                     const Date& paymentDate,
51                     Real nominal,
52                     const Date& startDate,
53                     const Date& endDate,
54                     const ext::shared_ptr<OvernightIndex>& overnightIndex,
55                     Real gearing = 1.0,
56                     Spread spread = 0.0,
57                     const Date& refPeriodStart = Date(),
58                     const Date& refPeriodEnd = Date(),
59                     const DayCounter& dayCounter = DayCounter(),
60                     bool telescopicValueDates = false);
61         //! \name Inspectors
62         //@{
63         //! fixing dates for the rates to be compounded
fixingDates() const64         const std::vector<Date>& fixingDates() const { return fixingDates_; }
65         //! accrual (compounding) periods
dt() const66         const std::vector<Time>& dt() const { return dt_; }
67         //! fixings to be compounded
68         const std::vector<Rate>& indexFixings() const;
69         //! value dates for the rates to be compounded
valueDates() const70         const std::vector<Date>& valueDates() const { return valueDates_; }
71         //@}
72         //! \name FloatingRateCoupon interface
73         //@{
74         //! the date when the coupon is fully determined
fixingDate() const75         Date fixingDate() const { return fixingDates_.back(); }
76         //@}
77         //! \name Visitability
78         //@{
79         void accept(AcyclicVisitor&);
80         //@}
81       private:
82         std::vector<Date> valueDates_, fixingDates_;
83         mutable std::vector<Rate> fixings_;
84         Size n_;
85         std::vector<Time> dt_;
86     };
87 
88 
89     //! helper class building a sequence of overnight coupons
90     class OvernightLeg {
91       public:
92         OvernightLeg(const Schedule& schedule,
93                      const ext::shared_ptr<OvernightIndex>& overnightIndex);
94         OvernightLeg& withNotionals(Real notional);
95         OvernightLeg& withNotionals(const std::vector<Real>& notionals);
96         OvernightLeg& withPaymentDayCounter(const DayCounter&);
97         OvernightLeg& withPaymentAdjustment(BusinessDayConvention);
98         OvernightLeg& withPaymentCalendar(const Calendar&);
99         OvernightLeg& withPaymentLag(Natural lag);
100         OvernightLeg& withGearings(Real gearing);
101         OvernightLeg& withGearings(const std::vector<Real>& gearings);
102         OvernightLeg& withSpreads(Spread spread);
103         OvernightLeg& withSpreads(const std::vector<Spread>& spreads);
104         OvernightLeg& withTelescopicValueDates(bool telescopicValueDates);
105         operator Leg() const;
106       private:
107         Schedule schedule_;
108         ext::shared_ptr<OvernightIndex> overnightIndex_;
109         std::vector<Real> notionals_;
110         DayCounter paymentDayCounter_;
111         Calendar paymentCalendar_;
112         BusinessDayConvention paymentAdjustment_;
113         Natural paymentLag_;
114         std::vector<Real> gearings_;
115         std::vector<Spread> spreads_;
116         bool telescopicValueDates_;
117     };
118 
119 }
120 
121 #endif
122