Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
InMemoryLoader Class Reference

#include <ored/marketdata/inmemoryloader.hpp>

+ Inheritance diagram for InMemoryLoader:
+ Collaboration diagram for InMemoryLoader:

Public Member Functions

 InMemoryLoader ()
 
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 More...
 
QuantLib::ext::shared_ptr< MarketDatumget (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 More...
 
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 More...
 
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 More...
 
std::set< FixingloadFixings () const override
 
std::set< QuantExt::DividendloadDividends () const override
 Optional load dividends method. More...
 
bool hasQuotes (const QuantLib::Date &d) const override
 check if there are quotes for a date More...
 
virtual void add (QuantLib::Date date, const string &name, QuantLib::Real value)
 
virtual void addFixing (QuantLib::Date date, const string &name, QuantLib::Real value)
 
virtual void addDividend (const QuantExt::Dividend &dividend)
 
void reset ()
 
- Public Member Functions inherited from Loader
virtual ~Loader ()
 
virtual bool has (const std::string &name, const QuantLib::Date &d) const
 Default implementation, returns false if get throws or returns a null pointer. More...
 
virtual QuantLib::ext::shared_ptr< MarketDatumget (const std::pair< std::string, bool > &name, const QuantLib::Date &d) const
 
virtual bool hasFixing (const string &name, const QuantLib::Date &d) const
 
virtual Fixing getFixing (const string &name, const QuantLib::Date &d) const
 Default implementation for getFixing. More...
 
void setActualDate (const QuantLib::Date &d)
 
const Date & actualDate () const
 
std::pair< bool, string > checkFxDuplicate (const ext::shared_ptr< MarketDatum >, const QuantLib::Date &)
 

Protected Attributes

std::map< QuantLib::Date, std::set< QuantLib::ext::shared_ptr< MarketDatum >, SharedPtrMarketDatumComparator > > data_
 
std::set< Fixingfixings_
 
std::set< QuantExt::Dividenddividends_
 
- Protected Attributes inherited from Loader
Date actualDate_ = Date()
 

Detailed Description

Definition at line 28 of file inmemoryloader.hpp.

Constructor & Destructor Documentation

◆ InMemoryLoader()

Definition at line 30 of file inmemoryloader.hpp.

30{}

Member Function Documentation

◆ loadQuotes()

std::vector< QuantLib::ext::shared_ptr< MarketDatum > > loadQuotes ( const QuantLib::Date &  ) const
overridevirtual

get all quotes, TODO change the return value to std::set

Implements Loader.

Definition at line 38 of file inmemoryloader.cpp.

38 {
39 auto it = data_.find(d);
40 if(it == data_.end())
41 return {};
42 return std::vector<QuantLib::ext::shared_ptr<MarketDatum>>(it->second.begin(), it->second.end());
43}
std::map< QuantLib::Date, std::set< QuantLib::ext::shared_ptr< MarketDatum >, SharedPtrMarketDatumComparator > > data_

◆ get() [1/3]

QuantLib::ext::shared_ptr< MarketDatum > get ( const string &  name,
const QuantLib::Date &  d 
) const
overridevirtual

get quote by its unique name, throws if not existent, override in derived classes for performance

Reimplemented from Loader.

Definition at line 45 of file inmemoryloader.cpp.

45 {
46 auto it = data_.find(d);
47 QL_REQUIRE(it != data_.end(), "No datum for " << name << " on date " << d);
48 auto it2 = it->second.find(makeDummyMarketDatum(d, name));
49 QL_REQUIRE(it2 != it->second.end(), "No datum for " << name << " on date " << d);
50 return *it2;
51}
QuantLib::ext::shared_ptr< MarketDatum > makeDummyMarketDatum(const Date &d, const std::string &name)
Definition: csvloader.cpp:95
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [2/3]

std::set< QuantLib::ext::shared_ptr< MarketDatum > > get ( const std::set< std::string > &  names,
const QuantLib::Date &  asof 
) const
overridevirtual

get quotes matching a set of names, this should be overridden in derived classes for performance

Reimplemented from Loader.

Definition at line 53 of file inmemoryloader.cpp.

54 {
55 auto it = data_.find(asof);
56 if(it == data_.end())
57 return {};
58 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
59 for (auto const& n : names) {
60 auto it2 = it->second.find(makeDummyMarketDatum(asof, n));
61 if (it2 != it->second.end())
62 result.insert(*it2);
63 }
64 return result;
65}
+ Here is the call graph for this function:

◆ get() [3/3]

std::set< QuantLib::ext::shared_ptr< MarketDatum > > get ( const Wildcard wildcard,
const QuantLib::Date &  asof 
) const
overridevirtual

get quotes matching a wildcard, this should be overriden in derived classes for performance

Reimplemented from Loader.

Definition at line 67 of file inmemoryloader.cpp.

68 {
69 if (!wildcard.hasWildcard()) {
70 // no wildcard => use get by name function
71 try {
72 return {get(wildcard.pattern(), asof)};
73 } catch (...) {
74 }
75 return {};
76 }
77 auto it = data_.find(asof);
78 if (it == data_.end())
79 return {};
80 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
81 std::set<QuantLib::ext::shared_ptr<MarketDatum>>::iterator it1, it2;
82 if (wildcard.wildcardPos() == 0) {
83 // wildcard at first position => we have to search all of the data
84 it1 = it->second.begin();
85 it2 = it->second.end();
86 } else {
87 // search the range matching the substring of the pattern until the wildcard
88 std::string prefix = wildcard.pattern().substr(0, wildcard.wildcardPos());
89 it1 = it->second.lower_bound(makeDummyMarketDatum(asof, prefix));
90 it2 = it->second.upper_bound(makeDummyMarketDatum(asof, prefix + "\xFF"));
91 }
92 for (auto it = it1; it != it2; ++it) {
93 if (wildcard.isPrefix() || wildcard.matches((*it)->name()))
94 result.insert(*it);
95 }
96 return result;
97}
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
+ Here is the call graph for this function:

◆ loadFixings()

std::set< Fixing > loadFixings ( ) const
overridevirtual

Implements Loader.

Definition at line 37 of file inmemoryloader.hpp.

37{ return fixings_; }
std::set< Fixing > fixings_

◆ loadDividends()

std::set< QuantExt::Dividend > loadDividends ( ) const
overridevirtual

Optional load dividends method.

Reimplemented from Loader.

Definition at line 38 of file inmemoryloader.hpp.

38{ return dividends_; }
std::set< QuantExt::Dividend > dividends_

◆ hasQuotes()

bool hasQuotes ( const QuantLib::Date &  d) const
overridevirtual

check if there are quotes for a date

Reimplemented from Loader.

Definition at line 99 of file inmemoryloader.cpp.

99 {
100 auto it = data_.find(d);
101 return it != data_.end();
102}

◆ add()

void add ( QuantLib::Date  date,
const string &  name,
QuantLib::Real  value 
)
virtual

Reimplemented in AdjustedInMemoryLoader.

Definition at line 104 of file inmemoryloader.cpp.

104 {
105 QuantLib::ext::shared_ptr<MarketDatum> md;
106 try {
107 md = parseMarketDatum(date, name, value);
108 } catch (std::exception& e) {
109 WLOG("Failed to parse MarketDatum " << name << ": " << e.what());
110 }
111 if (md != nullptr) {
112 std::pair<bool, string> addFX = {true, ""};
113 if (md->instrumentType() == MarketDatum::InstrumentType::FX_SPOT &&
114 md->quoteType() == MarketDatum::QuoteType::RATE) {
115 addFX = checkFxDuplicate(md, date);
116 if (!addFX.second.empty()) {
117 auto it = data_[date].find(makeDummyMarketDatum(date, addFX.second));
118 TLOG("Replacing MarketDatum " << addFX.second << " with " << name << " due to FX Dominance.");
119 if (it != data_[date].end())
120 data_[date].erase(it);
121 }
122 }
123 if (addFX.first && data_[date].insert(md).second) {
124 TLOG("Added MarketDatum " << name);
125 } else if (!addFX.first) {
126 WLOG("Skipped MarketDatum " << name << " - dominant FX already present.")
127 } else {
128 WLOG("Skipped MarketDatum " << name << " - this is already present.");
129 }
130 }
131}
std::pair< bool, string > checkFxDuplicate(const ext::shared_ptr< MarketDatum >, const QuantLib::Date &)
Definition: loader.cpp:85
SafeStack< ValueType > value
QuantLib::ext::shared_ptr< MarketDatum > parseMarketDatum(const Date &asof, const string &datumName, const Real &value)
Function to parse a market datum.
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
#define TLOG(text)
Logging Macro (Level = Data)
Definition: log.hpp:556
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFixing()

void addFixing ( QuantLib::Date  date,
const string &  name,
QuantLib::Real  value 
)
virtual

Reimplemented in AdjustedInMemoryLoader.

Definition at line 133 of file inmemoryloader.cpp.

133 {
134 if (!fixings_.insert(Fixing(date, name, value)).second) {
135 WLOG("Skipped Fixing " << name << "@" << QuantLib::io::iso_date(date) << " - this is already present.");
136 }
137}
+ Here is the caller graph for this function:

◆ addDividend()

void addDividend ( const QuantExt::Dividend dividend)
virtual

Definition at line 139 of file inmemoryloader.cpp.

139 {
140 if (!dividends_.insert(dividend).second) {
141 WLOG("Skipped Dividend " << dividend.name << "@" << QuantLib::io::iso_date(dividend.exDate) << " - this is already present.");
142 }
143}
std::string name
QuantLib::Date exDate

◆ reset()

void reset ( )

Definition at line 145 of file inmemoryloader.cpp.

145 {
146 data_.clear();
147 fixings_.clear();
148 dividends_.clear();
149 actualDate_ = Date();
150}

Member Data Documentation

◆ data_

std::map<QuantLib::Date, std::set<QuantLib::ext::shared_ptr<MarketDatum>, SharedPtrMarketDatumComparator> > data_
protected

Definition at line 54 of file inmemoryloader.hpp.

◆ fixings_

std::set<Fixing> fixings_
protected

Definition at line 55 of file inmemoryloader.hpp.

◆ dividends_

std::set<QuantExt::Dividend> dividends_
protected

Definition at line 56 of file inmemoryloader.hpp.