Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
compositeloader.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 ored/marketdata/compositeloader.hpp
20 \brief Loader that is a composite of two loaders
21 \ingroup marketdata
22*/
23
24#pragma once
25
26#include <ql/shared_ptr.hpp>
28
29namespace ore {
30namespace data {
31
32class CompositeLoader : public Loader {
33public:
34 CompositeLoader(const QuantLib::ext::shared_ptr<Loader>& a, const QuantLib::ext::shared_ptr<Loader>& b) : a_(a), b_(b) {
35 QL_REQUIRE(a_ || b_, "CompositeLoader(): at least one loader must be not null");
36 }
37
38 std::vector<QuantLib::ext::shared_ptr<MarketDatum>> loadQuotes(const QuantLib::Date& d) const override {
39 if (!b_)
40 return a_->loadQuotes(d);
41 if (!a_)
42 return b_->loadQuotes(d);
43 std::vector<QuantLib::ext::shared_ptr<MarketDatum>> data;
44 auto tmp1 = a_->loadQuotes(d);
45 data.insert(data.end(), tmp1.begin(), tmp1.end());
46 auto tmp2 = b_->loadQuotes(d);
47 data.insert(data.end(), tmp2.begin(), tmp2.end());
48 return data;
49 }
50
51 QuantLib::ext::shared_ptr<MarketDatum> get(const std::string& name, const QuantLib::Date& d) const override {
52 if (a_ && a_->has(name, d))
53 return a_->get(name, d);
54 if (b_ && b_->has(name, d))
55 return b_->get(name, d);
56 QL_FAIL("No MarketDatum for name " << name << " and date " << d);
57 }
58
59 std::set<QuantLib::ext::shared_ptr<MarketDatum>> get(const std::set<std::string>& names,
60 const QuantLib::Date& asof) const override {
61 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
62 if (a_) {
63 auto tmp = a_->get(names, asof);
64 result.insert(tmp.begin(), tmp.end());
65 }
66 if (b_) {
67 auto tmp = b_->get(names, asof);
68 result.insert(tmp.begin(), tmp.end());
69 }
70 return result;
71 }
72
73 std::set<QuantLib::ext::shared_ptr<MarketDatum>> get(const Wildcard& wildcard, const QuantLib::Date& asof) const override {
74 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
75 if (a_) {
76 auto tmp = a_->get(wildcard, asof);
77 result.insert(tmp.begin(), tmp.end());
78 }
79 if (b_) {
80 auto tmp = b_->get(wildcard, asof);
81 result.insert(tmp.begin(), tmp.end());
82 }
83 return result;
84 }
85
86 bool has(const std::string& name, const QuantLib::Date& d) const override {
87 return (a_ && a_->has(name, d)) || (b_ && b_->has(name, d));
88 }
89
90 std::set<Fixing> loadFixings() const override {
91 if (!b_)
92 return a_->loadFixings();
93 if (!a_)
94 return b_->loadFixings();
95 std::set<Fixing> fixings;
96 auto tmp1 = a_->loadFixings();
97 auto tmp2 = b_->loadFixings();
98 fixings.insert(tmp1.begin(), tmp1.end());
99 fixings.insert(tmp2.begin(), tmp2.end());
100 return fixings;
101 }
102
103 std::set<QuantExt::Dividend> loadDividends() const override {
104 if (!b_)
105 return a_->loadDividends();
106 if (!a_)
107 return b_->loadDividends();
108 std::set<QuantExt::Dividend> dividends;
109 auto tmp1 = a_->loadDividends();
110 auto tmp2 = b_->loadDividends();
111 dividends.insert(tmp1.begin(), tmp1.end());
112 dividends.insert(tmp2.begin(), tmp2.end());
113 return dividends;
114 }
115
116private:
117 const QuantLib::ext::shared_ptr<Loader> a_, b_;
118};
119
120} // namespace data
121} // namespace ore
std::set< QuantExt::Dividend > loadDividends() const override
Optional load dividends method.
bool has(const std::string &name, const QuantLib::Date &d) const override
Default implementation, returns false if get throws or returns a null pointer.
std::set< QuantLib::ext::shared_ptr< MarketDatum > > get(const std::set< std::string > &names, const QuantLib::Date &asof) const override
get quotes matching a set of names, this should be overridden in derived classes for performance
std::vector< QuantLib::ext::shared_ptr< MarketDatum > > loadQuotes(const QuantLib::Date &d) const override
get all quotes, TODO change the return value to std::set
std::set< Fixing > loadFixings() const override
const QuantLib::ext::shared_ptr< Loader > b_
CompositeLoader(const QuantLib::ext::shared_ptr< Loader > &a, const QuantLib::ext::shared_ptr< Loader > &b)
QuantLib::ext::shared_ptr< MarketDatum > get(const std::string &name, const QuantLib::Date &d) const override
get quote by its unique name, throws if not existent, override in derived classes for performance
std::set< QuantLib::ext::shared_ptr< MarketDatum > > get(const Wildcard &wildcard, const QuantLib::Date &asof) const override
get quotes matching a wildcard, this should be overriden in derived classes for performance
const QuantLib::ext::shared_ptr< Loader > a_
Market data loader base class.
Definition: loader.hpp:47
Market Datum Loader Interface.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string name