Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
loader.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 ored/marketdata/loader.hpp
20 \brief Market Datum Loader Interface
21 \ingroup marketdata
22 \invariant Concrete instantiations of this virtual base class guarantee
23 that all of the MarketDatum objects that they store are unique, e.g. by
24 discarding any duplicates during initialization.
25*/
26
27#pragma once
28
33
35#include <ql/time/date.hpp>
36
37#include <ql/shared_ptr.hpp>
38
39#include <vector>
40
41namespace ore {
42namespace data {
43
44//! Market data loader base class
45/*! \ingroup marketdata
46 */
47class Loader {
48public:
49 virtual ~Loader() {}
50
51 //! \name Interface
52 //@{
53
54 //! get all quotes, TODO change the return value to std::set
55 virtual std::vector<QuantLib::ext::shared_ptr<MarketDatum>> loadQuotes(const QuantLib::Date&) const = 0;
56
57 //! get quote by its unique name, throws if not existent, override in derived classes for performance
58 virtual QuantLib::ext::shared_ptr<MarketDatum> get(const std::string& name, const QuantLib::Date& d) const;
59
60 //! get quotes matching a set of names, this should be overridden in derived classes for performance
61 virtual std::set<QuantLib::ext::shared_ptr<MarketDatum>> get(const std::set<std::string>& names,
62 const QuantLib::Date& asof) const;
63
64 //! get quotes matching a wildcard, this should be overriden in derived classes for performance
65 virtual std::set<QuantLib::ext::shared_ptr<MarketDatum>> get(const Wildcard& wildcard, const QuantLib::Date& asof) const;
66
67 //! Default implementation, returns false if get throws or returns a null pointer
68 virtual bool has(const std::string& name, const QuantLib::Date& d) const;
69
70 //! check if there are quotes for a date
71 virtual bool hasQuotes(const QuantLib::Date& d) const;
72
73 /*! Default implementation for get that allows for the market data item to be optional. The first element of
74 the \p name pair is the name of the market point being sought and the second element of the \p name pair
75 is a flag to indicate if the market data point is optional, <code>true</code>, or not, <code>false</code>.
76 - if the quote is in the loader for date \p d, it is returned
77 - if the quote is not in the loader for date \p d and it is optional,
78 a warning is logged and a <code>QuantLib::ext::shared_ptr<MarketDatum>()</code> is returned
79 - if the quote is not in the loader for date \p d and it is not optional, an exception is thrown
80 */
81 virtual QuantLib::ext::shared_ptr<MarketDatum> get(const std::pair<std::string, bool>& name, const QuantLib::Date& d) const;
82
83 virtual std::set<Fixing> loadFixings() const = 0;
84
85 virtual bool hasFixing(const string& name, const QuantLib::Date& d) const;
86
87 //! Default implementation for getFixing
88 virtual Fixing getFixing(const string& name, const QuantLib::Date& d) const;
89 //@}
90
91 //! Optional load dividends method
92 virtual std::set<QuantExt::Dividend> loadDividends() const;
93
94 void setActualDate(const QuantLib::Date& d) { actualDate_ = d; }
95 const Date& actualDate() const { return actualDate_; }
96
97 std::pair<bool, string> checkFxDuplicate(const ext::shared_ptr<MarketDatum>, const QuantLib::Date&);
98
99private:
100 //! Serialization
102 template <class Archive> void serialize(Archive& ar, const unsigned int version) {}
103
104protected:
105 /*! For lagged market data, where we need to take data from a different date but want to treat it as belonging to
106 the valuation date.
107 */
108 Date actualDate_ = Date();
109};
110} // namespace data
111} // namespace ore
Market data loader base class.
Definition: loader.hpp:47
virtual std::vector< QuantLib::ext::shared_ptr< MarketDatum > > loadQuotes(const QuantLib::Date &) const =0
get all quotes, TODO change the return value to std::set
virtual Fixing getFixing(const string &name, const QuantLib::Date &d) const
Default implementation for getFixing.
Definition: loader.cpp:108
virtual QuantLib::ext::shared_ptr< MarketDatum > get(const std::string &name, const QuantLib::Date &d) const
get quote by its unique name, throws if not existent, override in derived classes for performance
Definition: loader.cpp:24
virtual bool hasQuotes(const QuantLib::Date &d) const
check if there are quotes for a date
Definition: loader.cpp:61
void setActualDate(const QuantLib::Date &d)
Definition: loader.hpp:94
virtual ~Loader()
Definition: loader.hpp:49
std::pair< bool, string > checkFxDuplicate(const ext::shared_ptr< MarketDatum >, const QuantLib::Date &)
Definition: loader.cpp:85
void serialize(Archive &ar, const unsigned int version)
Definition: loader.hpp:102
virtual std::set< Fixing > loadFixings() const =0
const Date & actualDate() const
Definition: loader.hpp:95
friend class boost::serialization::access
Serialization.
Definition: loader.hpp:101
virtual bool has(const std::string &name, const QuantLib::Date &d) const
Default implementation, returns false if get throws or returns a null pointer.
Definition: loader.cpp:53
virtual bool hasFixing(const string &name, const QuantLib::Date &d) const
Definition: loader.cpp:100
virtual std::set< QuantExt::Dividend > loadDividends() const
Optional load dividends method.
Definition: loader.cpp:118
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
Market data representation.
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Fixing data structure.
Definition: fixings.hpp:44
string name
utilities for wildcard handling