/src/quantlib/ql/cashflows/fixedratecoupon.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, 2007 StatPro Italia srl |
6 | | Copyright (C) 2007 Piter Dias |
7 | | Copyright (C) 2010 Ferdinando Ametrano |
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 | | <https://www.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 fixedratecoupon.hpp |
26 | | \brief Coupon paying a fixed annual rate |
27 | | */ |
28 | | |
29 | | #ifndef quantlib_fixed_rate_coupon_hpp |
30 | | #define quantlib_fixed_rate_coupon_hpp |
31 | | |
32 | | #include <ql/cashflows/coupon.hpp> |
33 | | #include <ql/patterns/visitor.hpp> |
34 | | #include <ql/interestrate.hpp> |
35 | | #include <ql/time/daycounter.hpp> |
36 | | #include <ql/time/schedule.hpp> |
37 | | |
38 | | namespace QuantLib { |
39 | | |
40 | | //! %Coupon paying a fixed interest rate |
41 | | class FixedRateCoupon : public Coupon { |
42 | | public: |
43 | | //! \name constructors |
44 | | //@{ |
45 | | FixedRateCoupon(const Date& paymentDate, |
46 | | Real nominal, |
47 | | Rate rate, |
48 | | const DayCounter& dayCounter, |
49 | | const Date& accrualStartDate, |
50 | | const Date& accrualEndDate, |
51 | | const Date& refPeriodStart = Date(), |
52 | | const Date& refPeriodEnd = Date(), |
53 | | const Date& exCouponDate = Date()); |
54 | | FixedRateCoupon(const Date& paymentDate, |
55 | | Real nominal, |
56 | | InterestRate interestRate, |
57 | | const Date& accrualStartDate, |
58 | | const Date& accrualEndDate, |
59 | | const Date& refPeriodStart = Date(), |
60 | | const Date& refPeriodEnd = Date(), |
61 | | const Date& exCouponDate = Date()); |
62 | | //@} |
63 | | //! \name LazyObject interface |
64 | | //@{ |
65 | | void performCalculations() const override; |
66 | | //@} |
67 | | //! \name CashFlow interface |
68 | | //@{ |
69 | | Real amount() const override; |
70 | | //@} |
71 | | //! \name Coupon interface |
72 | | //@{ |
73 | 0 | Rate rate() const override { return rate_; } |
74 | 0 | InterestRate interestRate() const { return rate_; } |
75 | 0 | DayCounter dayCounter() const override { return rate_.dayCounter(); } |
76 | | Real accruedAmount(const Date&) const override; |
77 | | //@} |
78 | | //! \name Visitability |
79 | | //@{ |
80 | | void accept(AcyclicVisitor&) override; |
81 | | //@} |
82 | | private: |
83 | | InterestRate rate_; |
84 | | mutable Real amount_; |
85 | | }; |
86 | | |
87 | | |
88 | | |
89 | | //! helper class building a sequence of fixed rate coupons |
90 | | class FixedRateLeg { |
91 | | public: |
92 | | FixedRateLeg(Schedule schedule); |
93 | | FixedRateLeg& withNotionals(Real); |
94 | | FixedRateLeg& withNotionals(const std::vector<Real>&); |
95 | | FixedRateLeg& withCouponRates(Rate, |
96 | | const DayCounter& paymentDayCounter, |
97 | | Compounding comp = Simple, |
98 | | Frequency freq = Annual); |
99 | | FixedRateLeg& withCouponRates(const std::vector<Rate>&, |
100 | | const DayCounter& paymentDayCounter, |
101 | | Compounding comp = Simple, |
102 | | Frequency freq = Annual); |
103 | | FixedRateLeg& withCouponRates(const InterestRate&); |
104 | | FixedRateLeg& withCouponRates(const std::vector<InterestRate>&); |
105 | | FixedRateLeg& withPaymentAdjustment(BusinessDayConvention); |
106 | | FixedRateLeg& withFirstPeriodDayCounter(const DayCounter&); |
107 | | FixedRateLeg& withLastPeriodDayCounter(const DayCounter&); |
108 | | FixedRateLeg& withPaymentCalendar(const Calendar&); |
109 | | FixedRateLeg& withPaymentLag(Integer lag); |
110 | | FixedRateLeg& withExCouponPeriod(const Period&, |
111 | | const Calendar&, |
112 | | BusinessDayConvention, |
113 | | bool endOfMonth = false); |
114 | | operator Leg() const; |
115 | | private: |
116 | | Schedule schedule_; |
117 | | std::vector<Real> notionals_; |
118 | | std::vector<InterestRate> couponRates_; |
119 | | DayCounter firstPeriodDC_ , lastPeriodDC_; |
120 | | Calendar paymentCalendar_; |
121 | | BusinessDayConvention paymentAdjustment_ = Following; |
122 | | Integer paymentLag_ = 0; |
123 | | Period exCouponPeriod_; |
124 | | Calendar exCouponCalendar_; |
125 | | BusinessDayConvention exCouponAdjustment_ = Following; |
126 | | bool exCouponEndOfMonth_ = false; |
127 | | }; |
128 | | |
129 | 0 | inline void FixedRateCoupon::accept(AcyclicVisitor& v) { |
130 | 0 | auto* v1 = dynamic_cast<Visitor<FixedRateCoupon>*>(&v); |
131 | 0 | if (v1 != nullptr) |
132 | 0 | v1->visit(*this); |
133 | 0 | else |
134 | 0 | Coupon::accept(v); |
135 | 0 | } |
136 | | |
137 | | } |
138 | | |
139 | | |
140 | | #endif |