QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
simplequote.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) 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
30namespace QuantLib {
31
32 //! market element returning a stored value
33 class SimpleQuote : public Quote {
34 public:
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
45 void reset();
46 //@}
47 private:
49 };
50
52
53
54 // inline definitions
55
57 return RelinkableHandle<Quote>(ext::make_shared<SimpleQuote>(value));
58 }
59
61 : value_(value) {}
62
63 inline Real SimpleQuote::value() const {
64 QL_ENSURE(isValid(), "invalid SimpleQuote");
65 return value_;
66 }
67
68 inline bool SimpleQuote::isValid() const {
69 return value_!=Null<Real>();
70 }
71
73 Real diff = value-value_;
74 if (diff != 0.0) {
75 value_ = value;
77 }
78 return diff;
79 }
80
81 inline void SimpleQuote::reset() {
83 }
84
85}
86
87#endif
template class providing a null value for a given type.
Definition: null.hpp:76
purely virtual base class for market observables
Definition: quote.hpp:37
Relinkable handle to an observable.
Definition: handle.hpp:117
market element returning a stored value
Definition: simplequote.hpp:33
Real setValue(Real value=Null< Real >())
returns the difference between the new value and the old value
Definition: simplequote.hpp:72
SimpleQuote(Real value=Null< Real >())
Definition: simplequote.hpp:60
Real value() const override
returns the current value
Definition: simplequote.hpp:63
bool isValid() const override
returns true if the Quote holds a valid value
Definition: simplequote.hpp:68
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
Definition: errors.hpp:130
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
RelinkableHandle< Quote > makeQuoteHandle(Real value)
Definition: simplequote.hpp:56
purely virtual base class for market observables