Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
marketobserver.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/models/marketobserver.hpp
20 \brief helper class for model builders that observes market ts
21 \ingroup models
22*/
23
24#pragma once
25
26#include <ql/patterns/observable.hpp>
27
28namespace QuantExt {
29using namespace QuantLib;
30
31//! Observer class for Model Builders
32/*!
33 This class holds all observables of a builder, except special ones like vol surfaces
34 that should be handled separately in the builders to determine whether
35 a recalibration of the model is required.
36
37 \ingroup models
38*/
39class MarketObserver : public Observer, public Observable {
40public:
42
43 //! Add an observable
44 void addObservable(QuantLib::ext::shared_ptr<Observable> observable);
45 //! Observer interface
46 void update() override;
47 //! Returns true if has been updated, reset updated flag if required
48 bool hasUpdated(const bool reset);
49
50private:
51 //! Flag to indicate if updated
53};
54
55// implementation
56
57inline void MarketObserver::addObservable(QuantLib::ext::shared_ptr<Observable> observable) {
58 registerWith(observable);
59 updated_ = true;
60}
61
63 updated_ = true;
64 notifyObservers();
65};
66
67inline bool MarketObserver::hasUpdated(const bool reset) {
68 if (!reset)
69 return updated_;
70 else {
71 bool upd = updated_;
72 updated_ = false;
73 return upd;
74 }
75}
76
77} // namespace QuantExt
Observer class for Model Builders.
void update() override
Observer interface.
bool hasUpdated(const bool reset)
Returns true if has been updated, reset updated flag if required.
bool updated_
Flag to indicate if updated.
void addObservable(QuantLib::ext::shared_ptr< Observable > observable)
Add an observable.