/src/quantlib/ql/indexes/iborindex.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
5 | | Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 StatPro Italia srl |
6 | | Copyright (C) 2009 Ferdinando Ametrano |
7 | | |
8 | | This file is part of QuantLib, a free-software/open-source library |
9 | | for financial quantitative analysts and developers - http://quantlib.org/ |
10 | | |
11 | | QuantLib is free software: you can redistribute it and/or modify it |
12 | | under the terms of the QuantLib license. You should have received a |
13 | | copy of the license along with this program; if not, please email |
14 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
15 | | <https://www.quantlib.org/license.shtml>. |
16 | | |
17 | | This program is distributed in the hope that it will be useful, but WITHOUT |
18 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
20 | | */ |
21 | | |
22 | | /*! \file iborindex.hpp |
23 | | \brief base class for Inter-Bank-Offered-Rate indexes |
24 | | */ |
25 | | |
26 | | #ifndef quantlib_ibor_index_hpp |
27 | | #define quantlib_ibor_index_hpp |
28 | | |
29 | | #include <ql/indexes/interestrateindex.hpp> |
30 | | #include <ql/termstructures/yieldtermstructure.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | //! base class for Inter-Bank-Offered-Rate indexes (e.g. %Libor, etc.) |
35 | | class IborIndex : public InterestRateIndex { |
36 | | public: |
37 | | IborIndex(const std::string& familyName, |
38 | | const Period& tenor, |
39 | | Natural settlementDays, |
40 | | const Currency& currency, |
41 | | const Calendar& fixingCalendar, |
42 | | BusinessDayConvention convention, |
43 | | bool endOfMonth, |
44 | | const DayCounter& dayCounter, |
45 | | Handle<YieldTermStructure> h = {}); |
46 | | //! \name InterestRateIndex interface |
47 | | //@{ |
48 | | Date maturityDate(const Date& valueDate) const override; |
49 | | Rate forecastFixing(const Date& fixingDate) const override; |
50 | | // @} |
51 | | //! \name Inspectors |
52 | | //@{ |
53 | | BusinessDayConvention businessDayConvention() const; |
54 | 0 | bool endOfMonth() const { return endOfMonth_; } |
55 | | //! the curve used to forecast fixings |
56 | | Handle<YieldTermStructure> forwardingTermStructure() const; |
57 | | //@} |
58 | | //! \name Other methods |
59 | | //@{ |
60 | | //! returns a copy of itself linked to a different forwarding curve |
61 | | virtual ext::shared_ptr<IborIndex> clone( |
62 | | const Handle<YieldTermStructure>& forwarding) const; |
63 | | // @} |
64 | | protected: |
65 | | BusinessDayConvention convention_; |
66 | | Handle<YieldTermStructure> termStructure_; |
67 | | bool endOfMonth_; |
68 | | private: |
69 | | // overload to avoid date/time (re)calculation |
70 | | /* This can be called with cached coupon dates (and it does |
71 | | give quite a performance boost to coupon calculations) but |
72 | | is potentially misleading: by passing the wrong dates, one |
73 | | can ask a 6-months index for a 1-year fixing. |
74 | | |
75 | | For that reason, we're leaving this method private and |
76 | | we're declaring the IborCoupon class (which uses it) as a |
77 | | friend. Should the need arise, we might promote it to |
78 | | public, but before doing that I'd think hard whether we |
79 | | have any other way to get the same results. |
80 | | */ |
81 | | Rate forecastFixing(const Date& valueDate, |
82 | | const Date& endDate, |
83 | | Time t) const; |
84 | | friend class IborCoupon; |
85 | | }; |
86 | | |
87 | | |
88 | | class OvernightIndex : public IborIndex { |
89 | | public: |
90 | | OvernightIndex(const std::string& familyName, |
91 | | Natural settlementDays, |
92 | | const Currency& currency, |
93 | | const Calendar& fixingCalendar, |
94 | | const DayCounter& dayCounter, |
95 | | const Handle<YieldTermStructure>& h = {}); |
96 | | //! returns a copy of itself linked to a different forwarding curve |
97 | | ext::shared_ptr<IborIndex> clone(const Handle<YieldTermStructure>& h) const override; |
98 | | }; |
99 | | |
100 | | |
101 | | // inline |
102 | | |
103 | 0 | inline BusinessDayConvention IborIndex::businessDayConvention() const { |
104 | 0 | return convention_; |
105 | 0 | } |
106 | | |
107 | | inline Handle<YieldTermStructure> |
108 | 0 | IborIndex::forwardingTermStructure() const { |
109 | 0 | return termStructure_; |
110 | 0 | } |
111 | | |
112 | | inline Rate IborIndex::forecastFixing(const Date& d1, |
113 | | const Date& d2, |
114 | 0 | Time t) const { |
115 | 0 | QL_REQUIRE(!termStructure_.empty(), |
116 | 0 | "null term structure set to this instance of " << name()); |
117 | 0 | DiscountFactor disc1 = termStructure_->discount(d1); |
118 | 0 | DiscountFactor disc2 = termStructure_->discount(d2); |
119 | 0 | return (disc1/disc2 - 1.0) / t; |
120 | 0 | } Unexecuted instantiation: QuantLib::IborIndex::forecastFixing(QuantLib::Date const&, QuantLib::Date const&, double) const Unexecuted instantiation: QuantLib::IborIndex::forecastFixing(QuantLib::Date const&, QuantLib::Date const&, double) const |
121 | | |
122 | | } |
123 | | |
124 | | #endif |