QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
interestrate.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 Ferdinando Ametrano
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
24#ifndef quantlib_interest_rate_hpp
25#define quantlib_interest_rate_hpp
26
27#include <ql/compounding.hpp>
28#include <ql/time/daycounters/actual365fixed.hpp>
29
30namespace QuantLib {
31
33
41 public:
43
44
49
51 operator Rate() const { return r_; }
53
55 Rate rate() const { return r_; }
56 const DayCounter& dayCounter() const { return dc_; }
57 Compounding compounding() const { return comp_; }
60 }
62
64
65
70 return 1.0/compoundFactor(t);
71 }
72
75 const Date& d2,
76 const Date& refStart = Date(),
77 const Date& refEnd = Date()) const {
78 QL_REQUIRE(d2>=d1,
79 "d1 (" << d1 << ") "
80 "later than d2 (" << d2 << ")");
81 Time t = dc_.yearFraction(d1, d2, refStart, refEnd);
82 return discountFactor(t);
83 }
84
86
92 Real compoundFactor(Time t) const;
93
95
99 const Date& d2,
100 const Date& refStart = Date(),
101 const Date& refEnd = Date()) const {
102 QL_REQUIRE(d2>=d1,
103 "d1 (" << d1 << ") "
104 "later than d2 (" << d2 << ")");
105 Time t = dc_.yearFraction(d1, d2, refStart, refEnd);
106 return compoundFactor(t);
107 }
109
111
112
114
119 static InterestRate impliedRate(Real compound,
120 const DayCounter& resultDC,
121 Compounding comp,
122 Frequency freq,
123 Time t);
124
126
130 const DayCounter& resultDC,
131 Compounding comp,
132 Frequency freq,
133 const Date& d1,
134 const Date& d2,
135 const Date& refStart = Date(),
136 const Date& refEnd = Date()) {
137 QL_REQUIRE(d2>=d1,
138 "d1 (" << d1 << ") "
139 "later than d2 (" << d2 << ")");
140 Time t = resultDC.yearFraction(d1, d2, refStart, refEnd);
141 return impliedRate(compound, resultDC, comp, freq, t);
142 }
144
146
147
149
156 Frequency freq,
157 Time t) const {
158 return impliedRate(compoundFactor(t), dc_, comp, freq, t);
159 }
160
162
166 Compounding comp,
167 Frequency freq,
168 Date d1,
169 Date d2,
170 const Date& refStart = Date(),
171 const Date& refEnd = Date()) const {
172 QL_REQUIRE(d2>=d1,
173 "d1 (" << d1 << ") "
174 "later than d2 (" << d2 << ")");
175 Time t1 = dc_.yearFraction(d1, d2, refStart, refEnd);
176 Time t2 = resultDC.yearFraction(d1, d2, refStart, refEnd);
177 return impliedRate(compoundFactor(t1), resultDC, comp, freq, t2);
178 }
180 private:
186 };
187
189 std::ostream& operator<<(std::ostream&,
190 const InterestRate&);
191
192}
193
194#endif
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
Concrete interest rate class.
const DayCounter & dayCounter() const
Compounding compounding() const
static InterestRate impliedRate(Real compound, const DayCounter &resultDC, Compounding comp, Frequency freq, Time t)
implied interest rate for a given compound factor at a given time.
InterestRate equivalentRate(const DayCounter &resultDC, Compounding comp, Frequency freq, Date d1, Date d2, const Date &refStart=Date(), const Date &refEnd=Date()) const
equivalent rate for a compounding period between two dates
static InterestRate impliedRate(Real compound, const DayCounter &resultDC, Compounding comp, Frequency freq, const Date &d1, const Date &d2, const Date &refStart=Date(), const Date &refEnd=Date())
implied rate for a given compound factor between two dates.
DiscountFactor discountFactor(Time t) const
discount factor implied by the rate compounded at time t.
InterestRate()
Default constructor returning a null interest rate.
Real compoundFactor(Time t) const
compound factor implied by the rate compounded at time t.
Real compoundFactor(const Date &d1, const Date &d2, const Date &refStart=Date(), const Date &refEnd=Date()) const
compound factor implied by the rate compounded between two dates
DiscountFactor discountFactor(const Date &d1, const Date &d2, const Date &refStart=Date(), const Date &refEnd=Date()) const
discount factor implied by the rate compounded between two dates
Frequency frequency() const
InterestRate equivalentRate(Compounding comp, Frequency freq, Time t) const
equivalent interest rate for a compounding period t.
Frequency
Frequency of events.
Definition: frequency.hpp:37
@ NoFrequency
null frequency
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
Compounding
Interest rate coumpounding rule.
Definition: compounding.hpp:32
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)