QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
index.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) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
6 Copyright (C) 2007, 2008 Ferdinando Ametrano
7 Copyright (C) 2007 Chiara Fornarola
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23/*! \file index.hpp
24 \brief virtual base class for indexes
25*/
26
27#ifndef quantlib_index_hpp
28#define quantlib_index_hpp
29
33#include <ql/time/calendar.hpp>
34
35namespace QuantLib {
36
37 //! purely virtual base class for indexes
38 /*! \warning this class performs no check that the
39 provided/requested fixings are for dates in the past,
40 i.e. for dates less than or equal to the evaluation
41 date. It is up to the client code to take care of
42 possible inconsistencies due to "seeing in the
43 future"
44 */
45 class Index : public Observable, public Observer {
46 public:
47 ~Index() override = default;
48 //! Returns the name of the index.
49 /*! \warning This method is used for output and comparison
50 between indexes. It is <b>not</b> meant to be
51 used for writing switch-on-type code.
52 */
53 virtual std::string name() const = 0;
54 //! returns the calendar defining valid fixing dates
55 virtual Calendar fixingCalendar() const = 0;
56 //! returns TRUE if the fixing date is a valid one
57 virtual bool isValidFixingDate(const Date& fixingDate) const = 0;
58 //! returns whether a historical fixing was stored for the given date
59 bool hasHistoricalFixing(const Date& fixingDate) const;
60 //! returns the fixing at the given date
61 /*! the date passed as arguments must be the actual calendar
62 date of the fixing; no settlement days must be used.
63 */
64 virtual Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const = 0;
65 //! returns a past fixing at the given date
66 /*! the date passed as arguments must be the actual calendar
67 date of the fixing; no settlement days must be used.
68 */
69 virtual Real pastFixing(const Date& fixingDate) const;
70 //! returns the fixing TimeSeries
75 }
76 //! check if index allows for native fixings.
77 /*! If this returns false, calls to addFixing and similar
78 methods will raise an exception.
79 */
80 virtual bool allowsNativeFixings() { return true; }
81 //! stores the historical fixing at the given date
82 /*! the date passed as arguments must be the actual calendar
83 date of the fixing; no settlement days must be used.
84 */
85 //! \name Observer interface
86 //@{
87 void update() override;
88 //@}
89 virtual void addFixing(const Date& fixingDate, Real fixing, bool forceOverwrite = false);
90 //! stores historical fixings from a TimeSeries
91 /*! the dates in the TimeSeries must be the actual calendar
92 dates of the fixings; no settlement days must be used.
93 */
94 void addFixings(const TimeSeries<Real>& t, bool forceOverwrite = false);
95 //! stores historical fixings at the given dates
96 /*! the dates passed as arguments must be the actual calendar
97 dates of the fixings; no settlement days must be used.
98 */
99 template <class DateIterator, class ValueIterator>
100 void addFixings(DateIterator dBegin,
101 DateIterator dEnd,
102 ValueIterator vBegin,
103 bool forceOverwrite = false) {
106 name(), dBegin, dEnd, vBegin, forceOverwrite,
107 [this](const Date& d) { return isValidFixingDate(d); });
108 }
109 //! clears all stored historical fixings
110 void clearFixings();
111
112 protected:
113 ext::shared_ptr<Observable> notifier() const {
117 }
118
119 private:
120 //! check if index allows for native fixings
122
123 };
124
125 inline bool Index::hasHistoricalFixing(const Date& fixingDate) const {
127 return IndexManager::instance().hasHistoricalFixing(name(), fixingDate);
129 }
130
131 inline Real Index::pastFixing(const Date& fixingDate) const {
132 QL_REQUIRE(isValidFixingDate(fixingDate), fixingDate << " is not a valid fixing date");
133 return timeSeries()[fixingDate];
134 }
135
136 inline void Index::update() {
138 }
139
140}
141
142#endif
calendar class
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
purely virtual base class for indexes
Definition: index.hpp:45
virtual Calendar fixingCalendar() const =0
returns the calendar defining valid fixing dates
ext::shared_ptr< Observable > notifier() const
Definition: index.hpp:113
virtual Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const =0
returns the fixing at the given date
bool hasHistoricalFixing(const Date &fixingDate) const
returns whether a historical fixing was stored for the given date
Definition: index.hpp:125
void update() override
Definition: index.hpp:136
void clearFixings()
clears all stored historical fixings
Definition: index.cpp:43
virtual bool allowsNativeFixings()
check if index allows for native fixings.
Definition: index.hpp:80
const TimeSeries< Real > & timeSeries() const
returns the fixing TimeSeries
Definition: index.hpp:71
virtual void addFixing(const Date &fixingDate, Real fixing, bool forceOverwrite=false)
Definition: index.cpp:24
void addFixings(const TimeSeries< Real > &t, bool forceOverwrite=false)
stores historical fixings from a TimeSeries
Definition: index.cpp:31
virtual std::string name() const =0
Returns the name of the index.
virtual Real pastFixing(const Date &fixingDate) const
returns a past fixing at the given date
Definition: index.hpp:131
virtual bool isValidFixingDate(const Date &fixingDate) const =0
returns TRUE if the fixing date is a valid one
void addFixings(DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin, bool forceOverwrite=false)
stores historical fixings at the given dates
Definition: index.hpp:100
~Index() override=default
void checkNativeFixingsAllowed()
check if index allows for native fixings
Definition: index.cpp:50
const TimeSeries< Real > & getHistory(const std::string &name) const
bool hasHistoricalFixing(const std::string &name, const Date &fixingDate) const
ext::shared_ptr< Observable > notifier(const std::string &name) const
void addFixings(const std::string &name, DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin, bool forceOverwrite=false, const std::function< bool(const Date &d)> &isValidFixingDate={})
add fixings
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
static IndexManager & instance()
access to the unique instance
Definition: singleton.hpp:104
Container for historical data.
Definition: timeseries.hpp:51
floating-point comparisons
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
QL_REAL Real
real number
Definition: types.hpp:50
global repository for past index fixings
Definition: any.hpp:37
observer/observable pattern
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217