Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/indexes/indexmanager.cpp
Line
Count
Source (jump to first uncovered line)
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
#include <ql/indexes/indexmanager.hpp>
21
22
namespace QuantLib {
23
24
0
    bool IndexManager::hasHistory(const std::string& name) const {
25
0
        return data_.find(name) != data_.end();
26
0
    }
27
28
0
    const TimeSeries<Real>& IndexManager::getHistory(const std::string& name) const {
29
0
        return data_[name];
30
0
    }
31
32
0
    void IndexManager::setHistory(const std::string& name, TimeSeries<Real> history) {
33
0
        QL_DEPRECATED_DISABLE_WARNING
34
0
        notifier(name)->notifyObservers();
35
0
        QL_DEPRECATED_ENABLE_WARNING
36
0
        data_[name] = std::move(history);
37
0
    }
38
39
    void IndexManager::addFixing(const std::string& name,
40
                                 const Date& fixingDate,
41
                                 Real fixing,
42
0
                                 bool forceOverwrite) {
43
0
        addFixings(name, &fixingDate, (&fixingDate) + 1, &fixing, forceOverwrite);
44
0
    }
45
46
0
    ext::shared_ptr<Observable> IndexManager::notifier(const std::string& name) const {
47
0
        auto n = notifiers_.find(name);
48
0
        if(n != notifiers_.end())
49
0
            return n->second;
50
0
        auto o = ext::make_shared<Observable>();
51
0
        notifiers_[name] = o;
52
0
        return o;
53
0
    }
54
55
0
    std::vector<std::string> IndexManager::histories() const {
56
0
        std::vector<std::string> temp;
57
0
        temp.reserve(data_.size());
58
0
        for (const auto& i : data_)
59
0
            temp.push_back(i.first);
60
0
        return temp;
61
0
    }
62
63
0
    void IndexManager::clearHistory(const std::string& name) {
64
0
        QL_DEPRECATED_DISABLE_WARNING
65
0
        notifier(name)->notifyObservers();
66
0
        QL_DEPRECATED_ENABLE_WARNING
67
0
        data_.erase(name);
68
0
    }
69
70
0
    void IndexManager::clearHistories() {
71
0
        QL_DEPRECATED_DISABLE_WARNING
72
0
        for (auto const& d : data_)
73
0
            notifier(d.first)->notifyObservers();
74
0
        QL_DEPRECATED_ENABLE_WARNING
75
0
        data_.clear();
76
0
    }
77
78
0
    bool IndexManager::hasHistoricalFixing(const std::string& name, const Date& fixingDate) const {
79
0
        auto const& indexIter = data_.find(name);
80
0
        return (indexIter != data_.end()) &&
81
0
               ((*indexIter).second[fixingDate] != Null<Real>());
82
0
    }
83
84
}