19#include <boost/algorithm/string.hpp>
39 auto it =
data_.find(d);
42 return std::vector<QuantLib::ext::shared_ptr<MarketDatum>>(it->second.begin(), it->second.end());
46 auto it =
data_.find(d);
47 QL_REQUIRE(it !=
data_.end(),
"No datum for " <<
name <<
" on date " << d);
49 QL_REQUIRE(it2 != it->second.end(),
"No datum for " <<
name <<
" on date " << d);
53std::set<QuantLib::ext::shared_ptr<MarketDatum>>
InMemoryLoader::get(
const std::set<std::string>& names,
54 const QuantLib::Date& asof)
const {
55 auto it =
data_.find(asof);
58 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
59 for (
auto const& n : names) {
61 if (it2 != it->second.end())
68 const QuantLib::Date& asof)
const {
77 auto it =
data_.find(asof);
78 if (it ==
data_.end())
80 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
81 std::set<QuantLib::ext::shared_ptr<MarketDatum>>::iterator it1, it2;
84 it1 = it->second.begin();
85 it2 = it->second.end();
92 for (
auto it = it1; it != it2; ++it) {
100 auto it =
data_.find(d);
101 return it !=
data_.end();
105 QuantLib::ext::shared_ptr<MarketDatum> md;
108 }
catch (std::exception& e) {
109 WLOG(
"Failed to parse MarketDatum " <<
name <<
": " << e.what());
112 std::pair<bool, string> addFX = {
true,
""};
116 if (!addFX.second.empty()) {
118 TLOG(
"Replacing MarketDatum " << addFX.second <<
" with " <<
name <<
" due to FX Dominance.");
119 if (it !=
data_[date].end())
120 data_[date].erase(it);
123 if (addFX.first &&
data_[date].insert(md).second) {
125 }
else if (!addFX.first) {
126 WLOG(
"Skipped MarketDatum " <<
name <<
" - dominant FX already present.")
128 WLOG(
"Skipped MarketDatum " <<
name <<
" - this is already present.");
135 WLOG(
"Skipped Fixing " <<
name <<
"@" << QuantLib::io::iso_date(date) <<
" - this is already present.");
141 WLOG(
"Skipped Dividend " << dividend.
name <<
"@" << QuantLib::io::iso_date(dividend.
exDate) <<
" - this is already present.");
152void load(
InMemoryLoader& loader,
const vector<string>& data,
bool isMarket,
bool implyTodaysFixings) {
153 LOG(
"MemoryLoader started");
155 Date today = QuantLib::Settings::instance().evaluationDate();
157 for (Size i = 0; i <
data.size(); ++i) {
158 string line =
data[i];
160 if (line.size() > 0 && line[0] !=
'#') {
161 vector<string> tokens;
163 boost::split(tokens, line, boost::is_any_of(
",;\t "), boost::token_compress_on);
166 QL_REQUIRE(tokens.size() == 3,
"Invalid MemoryLoader line, 3 tokens expected " << line);
168 const string& key = tokens[1];
176 TLOG(
"Added MarketDatum " << key);
177 }
catch (std::exception& e) {
178 WLOG(
"Failed to parse MarketDatum " << key <<
": " << e.what());
182 if (date < today || (date == today && !implyTodaysFixings))
187 LOG(
"MemoryLoader completed");
191 const std::vector<std::string>& fixingData,
bool implyTodaysFixings) {
192 load(loader, marketData,
true, implyTodaysFixings);
193 load(loader, fixingData,
false, implyTodaysFixings);
bool hasQuotes(const QuantLib::Date &d) const override
check if there are quotes for a date
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
virtual void add(QuantLib::Date date, const string &name, QuantLib::Real value)
virtual void addDividend(const QuantExt::Dividend ÷nd)
std::map< QuantLib::Date, std::set< QuantLib::ext::shared_ptr< MarketDatum >, SharedPtrMarketDatumComparator > > data_
std::pair< bool, string > checkFxDuplicate(const ext::shared_ptr< MarketDatum >, const QuantLib::Date &)
const std::string & pattern() const
bool matches(const std::string &s) const
std::size_t wildcardPos() const
SafeStack< ValueType > value
QuantLib::ext::shared_ptr< MarketDatum > parseMarketDatum(const Date &asof, const string &datumName, const Real &value)
Function to parse a market datum.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Real parseReal(const string &s)
Convert text to Real.
Classes and functions for log message handling.
#define LOG(text)
Logging Macro (Level = Notice)
#define WLOG(text)
Logging Macro (Level = Warning)
#define TLOG(text)
Logging Macro (Level = Data)
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.
void load(InMemoryLoader &loader, const vector< string > &data, bool isMarket, bool implyTodaysFixings)
QuantLib::ext::shared_ptr< MarketDatum > makeDummyMarketDatum(const Date &d, const std::string &name)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.