/src/quantlib/ql/cashflows/inflationcoupon.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2009 Chris Kenyon |
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 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | /*! \file inflationcoupon.hpp |
21 | | \brief Coupon paying a variable index-based rate |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_inflation_coupon_hpp |
25 | | #define quantlib_inflation_coupon_hpp |
26 | | |
27 | | #include <ql/cashflows/coupon.hpp> |
28 | | #include <ql/patterns/visitor.hpp> |
29 | | #include <ql/time/daycounter.hpp> |
30 | | #include <ql/handle.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | class InflationIndex; |
35 | | class YieldTermStructure; |
36 | | class InflationCouponPricer; |
37 | | |
38 | | //! Base inflation-coupon class |
39 | | /*! The day counter is usually obtained from the inflation term |
40 | | structure that the inflation index uses for forecasting. |
41 | | There is no gearing or spread because these are relevant for |
42 | | YoY coupons but not zero inflation coupons. |
43 | | |
44 | | \note inflation indices do not contain day counters or calendars. |
45 | | */ |
46 | | class InflationCoupon : public Coupon { |
47 | | public: |
48 | | InflationCoupon(const Date& paymentDate, |
49 | | Real nominal, |
50 | | const Date& startDate, |
51 | | const Date& endDate, |
52 | | Natural fixingDays, |
53 | | ext::shared_ptr<InflationIndex> index, |
54 | | const Period& observationLag, |
55 | | DayCounter dayCounter, |
56 | | const Date& refPeriodStart = Date(), |
57 | | const Date& refPeriodEnd = Date(), |
58 | | const Date& exCouponDate = Date()); |
59 | | |
60 | | //! \name CashFlow interface |
61 | | //@{ |
62 | 0 | Real amount() const override { return rate() * accrualPeriod() * nominal(); } |
63 | | //@} |
64 | | |
65 | | //! \name Coupon interface |
66 | | //@{ |
67 | | Real price(const Handle<YieldTermStructure>& discountingCurve) const; |
68 | 0 | DayCounter dayCounter() const override { return dayCounter_; } |
69 | | Real accruedAmount(const Date&) const override; |
70 | | Rate rate() const override; |
71 | | //@} |
72 | | |
73 | | //! \name Inspectors |
74 | | //@{ |
75 | | //! yoy inflation index |
76 | 0 | const ext::shared_ptr<InflationIndex>& index() const { return index_; } |
77 | | //! how the coupon observes the index |
78 | 0 | Period observationLag() const { return observationLag_; } |
79 | | //! fixing days |
80 | 0 | Natural fixingDays() const { return fixingDays_; } |
81 | | //! fixing date |
82 | | virtual Date fixingDate() const; |
83 | | //! fixing of the underlying index, as observed by the coupon |
84 | | virtual Rate indexFixing() const; |
85 | | //@} |
86 | | |
87 | | //! \name LazyObject interface |
88 | | //@{ |
89 | | void performCalculations() const override; |
90 | | //@} |
91 | | |
92 | | //! \name Visitability |
93 | | //@{ |
94 | | void accept(AcyclicVisitor&) override; |
95 | | //@} |
96 | | void setPricer(const ext::shared_ptr<InflationCouponPricer>&); |
97 | | ext::shared_ptr<InflationCouponPricer> pricer() const; |
98 | | |
99 | | protected: |
100 | | ext::shared_ptr<InflationCouponPricer> pricer_; |
101 | | ext::shared_ptr<InflationIndex> index_; |
102 | | Period observationLag_; |
103 | | DayCounter dayCounter_; |
104 | | Natural fixingDays_; |
105 | | mutable Real rate_; |
106 | | |
107 | | //! makes sure you were given the correct type of pricer |
108 | | // this can also done in external pricer setter classes via |
109 | | // accept/visit mechanism |
110 | | virtual bool checkPricerImpl(const |
111 | | ext::shared_ptr<InflationCouponPricer>&) const = 0; |
112 | | }; |
113 | | |
114 | | // inline definitions |
115 | | |
116 | | |
117 | 0 | inline void InflationCoupon::accept(AcyclicVisitor& v) { |
118 | 0 | auto* v1 = dynamic_cast<Visitor<InflationCoupon>*>(&v); |
119 | 0 | if (v1 != nullptr) |
120 | 0 | v1->visit(*this); |
121 | 0 | else |
122 | 0 | Coupon::accept(v); |
123 | 0 | } |
124 | | |
125 | | inline ext::shared_ptr<InflationCouponPricer> |
126 | 0 | InflationCoupon::pricer() const { |
127 | 0 | return pricer_; |
128 | 0 | } |
129 | | |
130 | | } |
131 | | |
132 | | #endif |