QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
termstructure.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, 2005, 2006, 2007 StatPro Italia srl
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 termstructure.hpp
21 \brief base class for term structures
22*/
23
24#ifndef quantlib_term_structure_hpp
25#define quantlib_term_structure_hpp
26
27#include <ql/time/calendar.hpp>
29#include <ql/settings.hpp>
30#include <ql/handle.hpp>
32#include <ql/utilities/null.hpp>
33
34namespace QuantLib {
35
36 //! Basic term-structure functionality
37 class TermStructure : public virtual Observer,
38 public virtual Observable,
39 public Extrapolator {
40 public:
41 /*! \name Constructors
42
43 There are three ways in which a term structure can keep
44 track of its reference date. The first is that such date
45 is fixed; the second is that it is determined by advancing
46 the current date of a given number of business days; and
47 the third is that it is based on the reference date of
48 some other structure.
49
50 In the first case, the constructor taking a date is to be
51 used; the default implementation of referenceDate() will
52 then return such date. In the second case, the constructor
53 taking a number of days and a calendar is to be used;
54 referenceDate() will return a date calculated based on the
55 current evaluation date, and the term structure and its
56 observers will be notified when the evaluation date
57 changes. In the last case, the referenceDate() method must
58 be overridden in derived classes so that it fetches and
59 return the appropriate date.
60 */
61 //@{
62 //! default constructor
63 /*! \warning term structures initialized by means of this
64 constructor must manage their own reference date
65 by overriding the referenceDate() method.
66 */
67 explicit TermStructure(DayCounter dc = DayCounter());
68 //! initialize with a fixed reference date
69 explicit TermStructure(const Date& referenceDate,
71 DayCounter dc = DayCounter());
72 //! calculate the reference date based on the global evaluation date
74 //@}
75 ~TermStructure() override = default;
76 //! \name Dates and Time
77 //@{
78 //! the day counter used for date/time conversion
79 virtual DayCounter dayCounter() const;
80 //! date/time conversion
81 Time timeFromReference(const Date& date) const;
82 //! the latest date for which the curve can return values
83 virtual Date maxDate() const = 0;
84 //! the latest time for which the curve can return values
85 virtual Time maxTime() const;
86 //! the date at which discount = 1.0 and/or variance = 0.0
87 virtual const Date& referenceDate() const;
88 //! the calendar used for reference and/or option date calculation
89 virtual Calendar calendar() const;
90 //! the settlementDays used for reference date calculation
91 virtual Natural settlementDays() const;
92 //@}
93 //! \name Observer interface
94 //@{
95 void update() override;
96 //@}
97 protected:
98 //! date-range check
99 void checkRange(const Date& d,
100 bool extrapolate) const;
101 //! time-range check
102 void checkRange(Time t,
103 bool extrapolate) const;
104 bool moving_ = false;
105 mutable bool updated_ = true;
107 private:
111 };
112
113 // inline definitions
114
116 return dayCounter_;
117 }
118
120 return timeFromReference(maxDate());
121 }
122
124 return calendar_;
125 }
126
129 "settlement days not provided for this instance");
130 return settlementDays_;
131 }
132
135 }
136
137}
138
139#endif
calendar class
calendar class
Definition: calendar.hpp:61
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
base class for classes possibly allowing extrapolation
template class providing a null value for a given type.
Definition: null.hpp:76
Object that notifies its changes to a set of observers.
Definition: observable.hpp:62
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
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
virtual Calendar calendar() const
the calendar used for reference and/or option date calculation
void update() override
virtual Time maxTime() const
the latest time for which the curve can return values
~TermStructure() override=default
virtual Date maxDate() const =0
the latest date for which the curve can return values
Time timeFromReference(const Date &date) const
date/time conversion
void checkRange(const Date &d, bool extrapolate) const
date-range check
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
day counter class
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
class-wide extrapolation settings
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Globally accessible relinkable pointer.
Definition: any.hpp:35
null values
global repository for run-time library settings