Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Loader Class Referenceabstract

Market data loader base class. More...

#include <ored/marketdata/loader.hpp>

+ Inheritance diagram for Loader:
+ Collaboration diagram for Loader:

Public Member Functions

virtual ~Loader ()
 

Interface

class boost::serialization::access
 Serialization. More...
 
Date actualDate_ = Date()
 
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 More...
 
virtual QuantLib::ext::shared_ptr< MarketDatumget (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 More...
 
virtual std::set< QuantLib::ext::shared_ptr< MarketDatum > > get (const std::set< std::string > &names, const QuantLib::Date &asof) const
 get quotes matching a set of names, this should be overridden in derived classes for performance More...
 
virtual std::set< QuantLib::ext::shared_ptr< MarketDatum > > get (const Wildcard &wildcard, const QuantLib::Date &asof) const
 get quotes matching a wildcard, this should be overriden in derived classes for performance More...
 
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 bool hasQuotes (const QuantLib::Date &d) const
 check if there are quotes for a date More...
 
virtual QuantLib::ext::shared_ptr< MarketDatumget (const std::pair< std::string, bool > &name, const QuantLib::Date &d) const
 
virtual std::set< FixingloadFixings () const =0
 
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...
 
virtual std::set< QuantExt::DividendloadDividends () const
 Optional load dividends method. More...
 
void setActualDate (const QuantLib::Date &d)
 
const Date & actualDate () const
 
std::pair< bool, string > checkFxDuplicate (const ext::shared_ptr< MarketDatum >, const QuantLib::Date &)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Detailed Description

Market data loader base class.

Definition at line 47 of file loader.hpp.

Constructor & Destructor Documentation

◆ ~Loader()

virtual ~Loader ( )
virtual

Definition at line 49 of file loader.hpp.

49{}

Member Function Documentation

◆ loadQuotes()

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

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

Implemented in CSVLoader, CompositeLoader, and InMemoryLoader.

+ Here is the caller graph for this function:

◆ get() [1/4]

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

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

Reimplemented in CompositeLoader, CSVLoader, and InMemoryLoader.

Definition at line 24 of file loader.cpp.

24 {
25 for (const auto& md : loadQuotes(d)) {
26 if (md->name() == name)
27 return md;
28 }
29 QL_FAIL("No MarketDatum for name " << name << " and date " << d);
30}
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
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [2/4]

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

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

Reimplemented in CompositeLoader, CSVLoader, and InMemoryLoader.

Definition at line 32 of file loader.cpp.

33 {
34 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
35 for (auto const& md : loadQuotes(asof)) {
36 if (names.find(md->name()) != names.end()) {
37 result.insert(md);
38 }
39 }
40 return result;
41}
+ Here is the call graph for this function:

◆ get() [3/4]

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

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

Reimplemented in CompositeLoader, CSVLoader, and InMemoryLoader.

Definition at line 43 of file loader.cpp.

43 {
44 std::set<QuantLib::ext::shared_ptr<MarketDatum>> result;
45 for (auto const& md : loadQuotes(asof)) {
46 if (wildcard.matches(md->name())) {
47 result.insert(md);
48 }
49 }
50 return result;
51}
+ Here is the call graph for this function:

◆ has()

bool has ( const std::string &  name,
const QuantLib::Date &  d 
) const
virtual

Default implementation, returns false if get throws or returns a null pointer.

Reimplemented in CompositeLoader.

Definition at line 53 of file loader.cpp.

53 {
54 try {
55 return get(name, d) != nullptr;
56 } catch (...) {
57 return false;
58 }
59}
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasQuotes()

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

check if there are quotes for a date

Reimplemented in InMemoryLoader.

Definition at line 61 of file loader.cpp.

61 {
62 try {
63 return !loadQuotes(d).empty();
64 } catch (...) {
65 return false;
66 }
67}
+ Here is the call graph for this function:

◆ get() [4/4]

QuantLib::ext::shared_ptr< MarketDatum > get ( const std::pair< std::string, bool > &  name,
const QuantLib::Date &  d 
) const
virtual

Default implementation for get that allows for the market data item to be optional. The first element of the name pair is the name of the market point being sought and the second element of the name pair is a flag to indicate if the market data point is optional, true, or not, false.

  • if the quote is in the loader for date d, it is returned
  • if the quote is not in the loader for date d and it is optional, a warning is logged and a QuantLib::ext::shared_ptr<MarketDatum>() is returned
  • if the quote is not in the loader for date d and it is not optional, an exception is thrown

Definition at line 69 of file loader.cpp.

69 {
70 if (has(name.first, d)) {
71 return get(name.first, d);
72 } else {
73 const Date& originalDate = actualDate() == Null<Date>() ? d : actualDate();
74 if (name.second) {
75 DLOG("Could not find quote for ID " << name.first << " with as of date " << QuantLib::io::iso_date(originalDate)
76 << ".");
77 return QuantLib::ext::shared_ptr<MarketDatum>();
78 } else {
79 QL_FAIL("Could not find quote for Mandatory ID " << name.first << " with as of date "
80 << QuantLib::io::iso_date(originalDate));
81 }
82 }
83}
const Date & actualDate() const
Definition: loader.hpp:95
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
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:

◆ loadFixings()

virtual std::set< Fixing > loadFixings ( ) const
pure virtual

Implemented in CompositeLoader, CSVLoader, and InMemoryLoader.

+ Here is the caller graph for this function:

◆ hasFixing()

bool hasFixing ( const string &  name,
const QuantLib::Date &  d 
) const
virtual

Definition at line 100 of file loader.cpp.

100 {
101 try {
102 return !getFixing(name, d).empty();
103 } catch (...) {
104 return false;
105 }
106}
virtual Fixing getFixing(const string &name, const QuantLib::Date &d) const
Default implementation for getFixing.
Definition: loader.cpp:108
+ Here is the call graph for this function:

◆ getFixing()

Fixing getFixing ( const string &  name,
const QuantLib::Date &  d 
) const
virtual

Default implementation for getFixing.

Definition at line 108 of file loader.cpp.

108 {
109 Fixing fixing;
110 for (auto const& f : loadFixings()) {
111 if (f.name == name && f.date == d) {
112 fixing = f;
113 }
114 }
115 return fixing;
116}
virtual std::set< Fixing > loadFixings() const =0
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadDividends()

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

Optional load dividends method.

Reimplemented in CompositeLoader, CSVLoader, and InMemoryLoader.

Definition at line 118 of file loader.cpp.

118{ return {}; }

◆ setActualDate()

void setActualDate ( const QuantLib::Date &  d)

Definition at line 94 of file loader.hpp.

94{ actualDate_ = d; }

◆ actualDate()

const Date & actualDate ( ) const

Definition at line 95 of file loader.hpp.

95{ return actualDate_; }
+ Here is the caller graph for this function:

◆ checkFxDuplicate()

std::pair< bool, string > checkFxDuplicate ( const ext::shared_ptr< MarketDatum md,
const QuantLib::Date &  d 
)

Definition at line 85 of file loader.cpp.

85 {
86 string cc1 = ext::dynamic_pointer_cast<FXSpotQuote>(md)->unitCcy();
87 string cc2 = ext::dynamic_pointer_cast<FXSpotQuote>(md)->ccy();
88 string tmp = "FX/RATE/" + cc2 + "/" + cc1;
89 if (Loader::has(tmp, d)) {
90 string dom = fxDominance(cc1, cc2);
91 if (dom == (cc1 + cc2)) {
92 return {true, tmp};
93 } else {
94 return {false, ""};
95 }
96 }
97 return {true, ""};
98}
string fxDominance(const string &s1, const string &s2)
Convert FX pair to market standard dominance.
Definition: parsers.cpp:1296
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

void serialize ( Archive &  ar,
const unsigned int  version 
)
private

Definition at line 102 of file loader.hpp.

102{}

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Serialization.

Definition at line 101 of file loader.hpp.

Member Data Documentation

◆ actualDate_

Date actualDate_ = Date()
protected

For lagged market data, where we need to take data from a different date but want to treat it as belonging to the valuation date.

Definition at line 108 of file loader.hpp.