QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
indexmanager.cpp
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
21
22namespace QuantLib {
23
24 bool IndexManager::hasHistory(const std::string& name) const {
25 return data_.find(name) != data_.end();
26 }
27
28 const TimeSeries<Real>& IndexManager::getHistory(const std::string& name) const {
29 return data_[name];
30 }
31
32 void IndexManager::setHistory(const std::string& name, TimeSeries<Real> history) {
34 notifier(name)->notifyObservers();
36 data_[name] = std::move(history);
37 }
38
39 void IndexManager::addFixing(const std::string& name,
40 const Date& fixingDate,
41 Real fixing,
42 bool forceOverwrite) {
43 addFixings(name, &fixingDate, (&fixingDate) + 1, &fixing, forceOverwrite);
44 }
45
46 ext::shared_ptr<Observable> IndexManager::notifier(const std::string& name) const {
47 auto n = notifiers_.find(name);
48 if(n != notifiers_.end())
49 return n->second;
50 auto o = ext::make_shared<Observable>();
51 notifiers_[name] = o;
52 return o;
53 }
54
55 std::vector<std::string> IndexManager::histories() const {
56 std::vector<std::string> temp;
57 temp.reserve(data_.size());
58 for (const auto& i : data_)
59 temp.push_back(i.first);
60 return temp;
61 }
62
63 void IndexManager::clearHistory(const std::string& name) {
65 notifier(name)->notifyObservers();
67 data_.erase(name);
68 }
69
72 for (auto const& d : data_)
73 notifier(d.first)->notifyObservers();
75 data_.clear();
76 }
77
78 bool IndexManager::hasHistoricalFixing(const std::string& name, const Date& fixingDate) const {
79 auto const& indexIter = data_.find(name);
80 return (indexIter != data_.end()) &&
81 ((*indexIter).second[fixingDate] != Null<Real>());
82 }
83
84}
Concrete date class.
Definition: date.hpp:125
std::map< std::string, TimeSeries< Real >, CaseInsensitiveCompare > data_
std::map< std::string, ext::shared_ptr< Observable > > notifiers_
const TimeSeries< Real > & getHistory(const std::string &name) const
bool hasHistoricalFixing(const std::string &name, const Date &fixingDate) const
void setHistory(const std::string &name, TimeSeries< Real > history)
void clearHistories()
clears all stored fixings
void addFixing(const std::string &name, const Date &fixingDate, Real fixing, bool forceOverwrite=false)
add a fixing
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
std::vector< std::string > histories() const
returns all names of the indexes for which fixings were stored
void clearHistory(const std::string &name)
bool hasHistory(const std::string &name) const
template class providing a null value for a given type.
Definition: null.hpp:59
Container for historical data.
Definition: timeseries.hpp:51
Date d
QL_REAL Real
real number
Definition: types.hpp:50
global repository for past index fixings
Definition: any.hpp:37
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217