QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
yieldtermstructure.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004, 2009 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
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 <http://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 yieldtermstructure.hpp
23 \brief Interest-rate term structure
24*/
25
26#ifndef quantlib_yield_term_structure_hpp
27#define quantlib_yield_term_structure_hpp
28
29#include <ql/termstructure.hpp>
30#include <ql/interestrate.hpp>
31#include <ql/quote.hpp>
32#include <vector>
33
34namespace QuantLib {
35
36 //! Interest-rate term structure
37 /*! This abstract class defines the interface of concrete
38 interest rate structures which will be derived from this one.
39
40 \ingroup yieldtermstructures
41
42 \test observability against evaluation date changes is checked.
43 */
45 public:
46 /*! \name Constructors
47 See the TermStructure documentation for issues regarding
48 constructors.
49 */
50 //@{
51 explicit YieldTermStructure(const DayCounter& dc = DayCounter());
53 const Calendar& cal = Calendar(),
54 const DayCounter& dc = DayCounter(),
55 std::vector<Handle<Quote> > jumps = {},
56 const std::vector<Date>& jumpDates = {});
58 const Calendar& cal,
59 const DayCounter& dc = DayCounter(),
60 std::vector<Handle<Quote> > jumps = {},
61 const std::vector<Date>& jumpDates = {});
62 //@}
63
64 /*! \name Discount factors
65
66 These methods return the discount factor from a given date or time
67 to the reference date. In the latter case, the time is calculated
68 as a fraction of year from the reference date.
69 */
70 //@{
72 bool extrapolate = false) const;
73 /*! The same day-counting rule used by the term structure
74 should be used for calculating the passed time t.
75 */
77 bool extrapolate = false) const;
78 //@}
79
80 /*! \name Zero-yield rates
81
82 These methods return the implied zero-yield rate for a
83 given date or time. In the former case, the time is
84 calculated as a fraction of year from the reference date.
85 */
86 //@{
87 /*! The resulting interest rate has the required daycounting
88 rule.
89 */
91 const DayCounter& resultDayCounter,
92 Compounding comp,
93 Frequency freq = Annual,
94 bool extrapolate = false) const;
95
96 /*! The resulting interest rate has the same day-counting rule
97 used by the term structure. The same rule should be used
98 for calculating the passed time t.
99 */
101 Compounding comp,
102 Frequency freq = Annual,
103 bool extrapolate = false) const;
104 //@}
105
106 /*! \name Forward rates
107
108 These methods returns the forward interest rate between two dates
109 or times. In the former case, times are calculated as fractions
110 of year from the reference date.
111
112 If both dates (times) are equal the instantaneous forward rate is
113 returned.
114 */
115 //@{
116 /*! The resulting interest rate has the required day-counting
117 rule.
118 */
119 InterestRate forwardRate(const Date& d1,
120 const Date& d2,
121 const DayCounter& resultDayCounter,
122 Compounding comp,
123 Frequency freq = Annual,
124 bool extrapolate = false) const;
125 /*! The resulting interest rate has the required day-counting
126 rule.
127 \warning dates are not adjusted for holidays
128 */
130 const Period& p,
131 const DayCounter& resultDayCounter,
132 Compounding comp,
133 Frequency freq = Annual,
134 bool extrapolate = false) const;
135
136 /*! The resulting interest rate has the same day-counting rule
137 used by the term structure. The same rule should be used
138 for calculating the passed times t1 and t2.
139 */
141 Time t2,
142 Compounding comp,
143 Frequency freq = Annual,
144 bool extrapolate = false) const;
145 //@}
146
147 //! \name Jump inspectors
148 //@{
149 const std::vector<Date>& jumpDates() const;
150 const std::vector<Time>& jumpTimes() const;
151 //@}
152
153 //! \name Observer interface
154 //@{
155 void update() override;
156 //@}
157 protected:
158 /*! \name Calculations
159
160 This method must be implemented in derived classes to
161 perform the actual calculations. When it is called,
162 range check has already been performed; therefore, it
163 must assume that extrapolation is required.
164 */
165 //@{
166 //! discount factor calculation
167 virtual DiscountFactor discountImpl(Time) const = 0;
168 //@}
169 private:
170 // methods
171 void setJumps(const Date& referenceDate);
172 // data members
173 std::vector<Handle<Quote> > jumps_;
174 std::vector<Date> jumpDates_;
175 std::vector<Time> jumpTimes_;
178 };
179
180 // inline definitions
181
182 inline
184 bool extrapolate) const {
185 return discount(timeFromReference(d), extrapolate);
186 }
187
188 inline
190 const Period& p,
191 const DayCounter& dayCounter,
192 Compounding comp,
193 Frequency freq,
194 bool extrapolate) const {
195 return forwardRate(d, d+p, dayCounter, comp, freq, extrapolate);
196 }
197
198 inline const std::vector<Date>& YieldTermStructure::jumpDates() const {
199 return this->jumpDates_;
200 }
201
202 inline const std::vector<Time>& YieldTermStructure::jumpTimes() const {
203 return this->jumpTimes_;
204 }
205
206}
207
208#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
Concrete interest rate class.
Basic term-structure functionality.
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
Time timeFromReference(const Date &date) const
date/time conversion
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
Interest-rate term structure.
DiscountFactor discount(const Date &d, bool extrapolate=false) const
const std::vector< Time > & jumpTimes() const
InterestRate zeroRate(const Date &d, const DayCounter &resultDayCounter, Compounding comp, Frequency freq=Annual, bool extrapolate=false) const
const std::vector< Date > & jumpDates() const
std::vector< Handle< Quote > > jumps_
void setJumps(const Date &referenceDate)
InterestRate forwardRate(const Date &d1, const Date &d2, const DayCounter &resultDayCounter, Compounding comp, Frequency freq=Annual, bool extrapolate=false) const
virtual DiscountFactor discountImpl(Time) const =0
discount factor calculation
const DefaultType & t
Date d
Frequency
Frequency of events.
Definition: frequency.hpp:37
@ Annual
once a year
Definition: frequency.hpp:39
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
std::size_t Size
size of a container
Definition: types.hpp:58
Instrument rate class.
Definition: any.hpp:35
Compounding
Interest rate coumpounding rule.
Definition: compounding.hpp:32
purely virtual base class for market observables
base class for term structures