QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
indexmanager.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 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 indexmanager.hpp
21 \brief global repository for past index fixings
22*/
23
24#ifndef quantlib_index_manager_hpp
25#define quantlib_index_manager_hpp
26
28#include <ql/timeseries.hpp>
30#include <algorithm>
31#include <cctype>
32
33namespace QuantLib {
34
35 //! global repository for past index fixings
36 /*! \note index names are case insensitive */
37 class IndexManager : public Singleton<IndexManager> {
38 friend class Singleton<IndexManager>;
39
40 private:
41 IndexManager() = default;
42
43 public:
44 //! returns whether historical fixings were stored for the index
45 bool hasHistory(const std::string& name) const;
46 //! returns the (possibly empty) history of the index fixings
47 const TimeSeries<Real>& getHistory(const std::string& name) const;
48 //! stores the historical fixings of the index
49 void setHistory(const std::string& name, TimeSeries<Real> history);
50 //! observer notifying of changes in the index fixings
51 ext::shared_ptr<Observable> notifier(const std::string& name) const;
52 //! returns all names of the indexes for which fixings were stored
53 std::vector<std::string> histories() const;
54 //! clears the historical fixings of the index
55 void clearHistory(const std::string& name);
56 //! clears all stored fixings
57 void clearHistories();
58 //! returns whether a specific historical fixing was stored for the index and date
59 bool hasHistoricalFixing(const std::string& name, const Date& fixingDate) const;
60
61 private:
63 bool operator()(const std::string& s1, const std::string& s2) const {
64 return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), [](const auto& c1, const auto& c2) {
65 return std::toupper(static_cast<unsigned char>(c1)) < std::toupper(static_cast<unsigned char>(c2));
66 });
67 }
68 };
69
70 mutable std::map<std::string, ObservableValue<TimeSeries<Real>>, CaseInsensitiveCompare> data_;
71 };
72
73}
74
75
76#endif
Concrete date class.
Definition: date.hpp:125
global repository for past index fixings
const TimeSeries< Real > & getHistory(const std::string &name) const
returns the (possibly empty) history of the index fixings
bool hasHistoricalFixing(const std::string &name, const Date &fixingDate) const
returns whether a specific historical fixing was stored for the index and date
void setHistory(const std::string &name, TimeSeries< Real > history)
stores the historical fixings of the index
void clearHistories()
clears all stored fixings
std::map< std::string, ObservableValue< TimeSeries< Real > >, CaseInsensitiveCompare > data_
ext::shared_ptr< Observable > notifier(const std::string &name) const
observer notifying of changes in the index fixings
std::vector< std::string > histories() const
returns all names of the indexes for which fixings were stored
void clearHistory(const std::string &name)
clears the historical fixings of the index
bool hasHistory(const std::string &name) const
returns whether historical fixings were stored for the index
Basic support for the singleton pattern.
Definition: singleton.hpp:58
Container for historical data.
Definition: timeseries.hpp:51
Definition: any.hpp:35
observable and assignable proxy to concrete value
basic support for the singleton pattern
bool operator()(const std::string &s1, const std::string &s2) const
Container for historical data.