Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/quotes/simplequote.hpp
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) 2007 Ferdinando Ametrano
5
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6
7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9
10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <http://quantlib.org/license.shtml>.
15
16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20
21
/*! \file simplequote.hpp
22
    \brief simple quote class
23
*/
24
25
#ifndef quantlib_simple_quote_hpp
26
#define quantlib_simple_quote_hpp
27
28
#include <ql/quote.hpp>
29
30
namespace QuantLib {
31
32
    //! market element returning a stored value
33
    class SimpleQuote : public Quote {
34
      public:
35
        SimpleQuote(Real value = Null<Real>());
36
        //! \name Quote interface
37
        //@{
38
        Real value() const override;
39
        bool isValid() const override;
40
        //@}
41
        //! \name Modifiers
42
        //@{
43
        //! returns the difference between the new value and the old value
44
        Real setValue(Real value = Null<Real>());
45
        void reset();
46
        //@}
47
      private:
48
        Real value_;
49
    };
50
51
    RelinkableHandle<Quote> makeQuoteHandle(Real value);
52
53
54
    // inline definitions
55
56
0
    inline RelinkableHandle<Quote> makeQuoteHandle(Real value) {
57
0
        return RelinkableHandle<Quote>(ext::make_shared<SimpleQuote>(value));
58
0
    }
59
60
    inline SimpleQuote::SimpleQuote(Real value)
61
4.03k
    : value_(value) {}
62
63
0
    inline Real SimpleQuote::value() const {
64
0
        QL_ENSURE(isValid(), "invalid SimpleQuote");
65
0
        return value_;
66
0
    }
67
68
0
    inline bool SimpleQuote::isValid() const {
69
0
        return value_!=Null<Real>();
70
0
    }
71
72
2.07M
    inline Real SimpleQuote::setValue(Real value) {
73
2.07M
        Real diff = value-value_;
74
2.07M
        if (diff != 0.0) {
75
824k
            value_ = value;
76
824k
            notifyObservers();
77
824k
        }
78
2.07M
        return diff;
79
2.07M
    }
80
81
0
    inline void SimpleQuote::reset() {
82
0
        setValue(Null<Real>());
83
0
    }
84
85
}
86
87
#endif