Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inmemoryloader.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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#pragma once
20
23
24namespace ore {
25namespace data {
26using std::string;
27
28class InMemoryLoader : public Loader {
29public:
31
32 std::vector<QuantLib::ext::shared_ptr<MarketDatum>> loadQuotes(const QuantLib::Date& d) const override;
33 QuantLib::ext::shared_ptr<MarketDatum> get(const string& name, const QuantLib::Date& d) const override;
34 std::set<QuantLib::ext::shared_ptr<MarketDatum>> get(const std::set<std::string>& names,
35 const QuantLib::Date& asof) const override;
36 std::set<QuantLib::ext::shared_ptr<MarketDatum>> get(const Wildcard& wildcard, const QuantLib::Date& asof) const override;
37 std::set<Fixing> loadFixings() const override { return fixings_; }
38 std::set<QuantExt::Dividend> loadDividends() const override { return dividends_; }
39 bool hasQuotes(const QuantLib::Date& d) const override;
40
41 // add a market datum
42 virtual void add(QuantLib::Date date, const string& name, QuantLib::Real value);
43
44 // add a fixing
45 virtual void addFixing(QuantLib::Date date, const string& name, QuantLib::Real value);
46
47 // add a dividend
48 virtual void addDividend(const QuantExt::Dividend& dividend);
49
50 // clear data
51 void reset();
52
53protected:
54 std::map<QuantLib::Date, std::set<QuantLib::ext::shared_ptr<MarketDatum>, SharedPtrMarketDatumComparator>> data_;
55 std::set<Fixing> fixings_;
56 std::set<QuantExt::Dividend> dividends_;
57};
58
59//! Utility function for loading market quotes and fixings from an in memory csv buffer
60// This function throws on bad data
62 //! The loader that will be populated
63 InMemoryLoader& loader,
64 //! QuantLib::Date Key Value in a single std::string, separated by blanks, tabs, colons or commas
65 const std::vector<std::string>& marketData,
66 //! QuantLib::Date Index Fixing in a single std::string, separated by blanks, tabs, colons or commas
67 const std::vector<std::string>& fixingData,
68 //! Enable/disable implying today's fixings
69 bool implyTodaysFixings = false);
70
71} // namespace data
72} // namespace ore
bool hasQuotes(const QuantLib::Date &d) const override
check if there are quotes for a date
std::set< QuantExt::Dividend > loadDividends() const override
Optional load dividends method.
std::set< QuantExt::Dividend > dividends_
std::set< Fixing > fixings_
virtual void addFixing(QuantLib::Date date, const string &name, QuantLib::Real value)
QuantLib::ext::shared_ptr< MarketDatum > get(const 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::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
virtual void add(QuantLib::Date date, const string &name, QuantLib::Real value)
virtual void addDividend(const QuantExt::Dividend &dividend)
std::map< QuantLib::Date, std::set< QuantLib::ext::shared_ptr< MarketDatum >, SharedPtrMarketDatumComparator > > data_
Market data loader base class.
Definition: loader.hpp:47
SafeStack< ValueType > value
Market Datum Loader Interface.
@ data
Definition: log.hpp:77
Market Datum parser.
void loadDataFromBuffers(InMemoryLoader &loader, const std::vector< std::string > &marketData, const std::vector< std::string > &fixingData, bool implyTodaysFixings)
Utility function for loading market quotes and fixings from an in memory csv buffer.
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string name