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

#include <orea/app/marketdataloader.hpp>

+ Inheritance diagram for MarketDataLoader:
+ Collaboration diagram for MarketDataLoader:

Public Member Functions

 MarketDataLoader (const QuantLib::ext::shared_ptr< InputParameters > &inputs, QuantLib::ext::shared_ptr< MarketDataLoaderImpl > impl)
 
virtual ~MarketDataLoader ()
 
void populateLoader (const std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > &todaysMarketParameters, const std::set< QuantLib::Date > &loaderDates)
 
virtual void populateFixings (const std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > &todaysMarketParameters, const std::set< QuantLib::Date > &loaderDates={})
 
virtual void addRelevantFixings (const std::pair< std::string, RequiredFixings::FixingDates > &fixing, std::map< std::pair< std::string, QuantLib::Date >, std::set< QuantLib::Date > > &lastAvailableFixingLookupMap)
 
void resetLoader ()
 clear the loader More...
 
const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > & loader () const
 getters More...
 
QuoteMap quotes ()
 

Protected Member Functions

const QuantLib::ext::shared_ptr< MarketDataLoaderImpl > & impl () const
 

Protected Attributes

QuantLib::ext::shared_ptr< InputParametersinputs_
 
QuantLib::ext::shared_ptr< ore::data::InMemoryLoaderloader_
 
QuoteMap quotes_
 
FixingMap fixings_
 

Private Attributes

QuantLib::ext::shared_ptr< MarketDataLoaderImplimpl_
 

Detailed Description

Definition at line 65 of file marketdataloader.hpp.

Constructor & Destructor Documentation

◆ MarketDataLoader()

MarketDataLoader ( const QuantLib::ext::shared_ptr< InputParameters > &  inputs,
QuantLib::ext::shared_ptr< MarketDataLoaderImpl impl 
)

Definition at line 67 of file marketdataloader.hpp.

68 : inputs_(inputs), impl_(impl) {
69 loader_ = QuantLib::ext::make_shared<ore::data::InMemoryLoader>();
70 }
QuantLib::ext::shared_ptr< MarketDataLoaderImpl > impl_
QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > loader_
QuantLib::ext::shared_ptr< InputParameters > inputs_
const QuantLib::ext::shared_ptr< MarketDataLoaderImpl > & impl() const

◆ ~MarketDataLoader()

virtual ~MarketDataLoader ( )
virtual

Definition at line 71 of file marketdataloader.hpp.

71{}

Member Function Documentation

◆ populateLoader()

void populateLoader ( const std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > &  todaysMarketParameters,
const std::set< QuantLib::Date > &  loaderDates 
)

Populate a market data loader. Gathers all the quotes needed based on the configs provided and calls the marketdata and fixing services

Definition at line 223 of file marketdataloader.cpp.

225 {
226
227 // create a loader if doesn't already exist
228 if (!loader_)
229 loader_ = QuantLib::ext::make_shared<InMemoryLoader>();
230 else
231 loader_->reset(); // can only populate once to avoid duplicates
232
233 // check input data
234 QL_REQUIRE(!inputs_->curveConfigs().empty(), "Need at least one curve configuration to populate loader.");
235 QL_REQUIRE(todaysMarketParameters.size() > 0, "No todaysMarketParams provided to populate market data loader.");
236
237 // for equities check if we have corporate action data
238 std::map<std::string, std::string> equities;
239 for (const auto& tmp : todaysMarketParameters) {
240 if (tmp->hasMarketObject(MarketObject::EquityCurve)) {
241 auto eqMap = tmp->mapping(MarketObject::EquityCurve, Market::defaultConfiguration);
242 for (auto eq : eqMap) {
243 if (inputs_->refDataManager() && inputs_->refDataManager()->hasData("Equity", eq.first)) {
244 auto refData = QuantLib::ext::dynamic_pointer_cast<EquityReferenceDatum>(
245 inputs_->refDataManager()->getData("Equity", eq.first));
246 auto erData = refData->equityData();
247 equities[eq.first] = erData.equityId;
248 } else
249 equities[eq.first] = eq.first;
250 }
251 }
252 }
253 if (equities.size() > 0)
254 impl()->loadCorporateActionData(loader_, equities);
255
256 // apply dividends now
257 applyDividends(loader_->loadDividends());
258
259 populateFixings(todaysMarketParameters, loaderDates);
260
261 LOG("Adding the loaded fixings to the IndexManager");
262 applyFixings(loader_->loadFixings());
263
264 // Get set of quotes we need
265 LOG("Generating market datum set");
266 set<string> quotes;
267 for (const auto& tmp : todaysMarketParameters) {
268 // Find all configurations in this todaysMarket
269 std::set<std::string> configurations;
270 for (auto c : tmp->configurations())
271 configurations.insert(c.first);
272
273 for (const auto& [_,curveConfig] : inputs_->curveConfigs().curveConfigurations()) {
274 auto qs = curveConfig->quotes(tmp, configurations);
275 quotes.insert(qs.begin(), qs.end());
276 }
277 }
278
279 for (const auto& d : loaderDates) {
280 QuoteMap quoteMap;
281 quoteMap[d] = quotes;
282
283 LOG("CurveConfigs require " << quotes.size() << " quotes");
284
285 // Get the relevant market data loader for the pricing call
286 impl()->retrieveMarketData(loader_, quoteMap, d);
287
288 quotes_[d] = quotes;
289 }
290 LOG("Got market data");
291}
virtual void populateFixings(const std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > &todaysMarketParameters, const std::set< QuantLib::Date > &loaderDates={})
static const string defaultConfiguration
#define LOG(text)
void applyDividends(const std::set< Dividend > &dividends)
std::map< QuantLib::Date, std::set< std::string > > QuoteMap
void applyFixings(const std::set< Fixing > &fixings)
+ Here is the call graph for this function:

◆ populateFixings()

void populateFixings ( const std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > &  todaysMarketParameters,
const std::set< QuantLib::Date > &  loaderDates = {} 
)
virtual

Definition at line 162 of file marketdataloader.cpp.

164 {
165 if (inputs_->allFixings()) {
166 impl()->retrieveFixings(loader_);
167 } else {
168 LOG("Asking portfolio for its required fixings");
169 FixingMap portfolioFixings;
170 std::map<std::pair<std::string, QuantLib::Date>, std::set<QuantLib::Date>> lastAvailableFixingLookupMap;
171
172 // portfolio fixings will warn if missing
173 if (inputs_->portfolio()) {
174 portfolioFixings = inputs_->portfolio()->fixings();
175 LOG("The portfolio depends on fixings from " << portfolioFixings.size() << " indices");
176 for (const auto& it : portfolioFixings)
177 addRelevantFixings(it, lastAvailableFixingLookupMap);
178 }
179
180 LOG("Add fixings possibly required for bootstrapping TodaysMarket");
181 for (const auto& tmp : todaysMarketParameters) {
182 for (const auto d : loaderDates)
184 LOG("Add fixing possibly required for equity index delta risk decomposition")
185 additional_equity_fixings(fixings_, *tmp, inputs_->refDataManager(),
186 inputs_->curveConfigs().get());
187 }
188
189 if (inputs_->eomInflationFixings()) {
190 LOG("Adjust inflation fixing dates to the end of the month before the request");
192 }
193
194 if (fixings_.size() > 0)
195 impl()->retrieveFixings(loader_, fixings_, lastAvailableFixingLookupMap);
196
197 // apply all fixings now
198 applyFixings(loader_->loadFixings());
199
200 // check and warn any missing fixings - only warn for mandatory fixings
201 for (const auto& [indexName, fixingDates] : fixings_) {
202 for (const auto& [d, mandatory] :fixingDates) {
203 if (mandatory && !loader_->hasFixing(indexName, d)) {
204 string fixingErr = "";
205 if (isFxIndex(indexName)) {
206 auto fxInd = parseFxIndex(indexName);
207 try {
208 if(fxInd->fixingCalendar().isBusinessDay(d))
209 fxInd->fixing(d);
210 break;
211 } catch (const std::exception& e) {
212 fixingErr = ", error: " + ore::data::to_string(e.what());
213 }
214 }
215 StructuredFixingWarningMessage(indexName, d, "Missing fixing", "Could not find required fixing ID.")
216 .log();
217 }
218 }
219 }
220 }
221}
virtual void addRelevantFixings(const std::pair< std::string, RequiredFixings::FixingDates > &fixing, std::map< std::pair< std::string, QuantLib::Date >, std::set< QuantLib::Date > > &lastAvailableFixingLookupMap)
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot=Handle< Quote >(), const Handle< YieldTermStructure > &sourceYts=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &targetYts=Handle< YieldTermStructure >(), const bool useConventions=false)
std::map< std::string, RequiredFixings::FixingDates > FixingMap
void additional_equity_fixings(map< string, RequiredFixings::FixingDates > &fixings, const TodaysMarketParameters &mktParams, const QuantLib::ext::shared_ptr< ReferenceDataManager > refData, const QuantLib::ext::shared_ptr< CurveConfigurations > &curveConfigs)
bool isFxIndex(const std::string &indexName)
void amendInflationFixingDates(std::map< std::string, RequiredFixings::FixingDates > &fixings)
void addMarketFixingDates(const Date &asof, map< string, RequiredFixings::FixingDates > &fixings, const TodaysMarketParameters &mktParams, const Period &iborLookback, const Period &oisLookback, const Period &bmaLookback, const Period &inflationLookback)
std::string to_string(const LocationInfo &l)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addRelevantFixings()

void addRelevantFixings ( const std::pair< std::string, RequiredFixings::FixingDates > &  fixing,
std::map< std::pair< std::string, QuantLib::Date >, std::set< QuantLib::Date > > &  lastAvailableFixingLookupMap 
)
virtual

Definition at line 148 of file marketdataloader.cpp.

150 {
151 if (isFxIndex(fixing.first)) {
152 // for FX fixings we want to add additional fixings to allow triangulation in case of missing
153 // fixings if we need EUR/GBP fixing but it is not available, we can imply from EUR/USD and GBP/USD
154 additional_fx_fixings(fixing.first, fixing.second, fixings_);
155 }
156 if (isCommodityIndex(fixing.first)) {
157 additional_commodity_fixings(fixing.first, fixing.second, fixings_, lastAvailableFixingLookupMap);
158 }
159 fixings_[fixing.first].addDates(fixing.second);
160}
bool isCommodityIndex(const std::string &indexName)
void additional_fx_fixings(const string &fixingId, const RequiredFixings::FixingDates &fixingDates, FixingMap &relevantFixings)
void additional_commodity_fixings(const string &fixingId, const RequiredFixings::FixingDates &fixingDates, FixingMap &fixings, map< pair< string, Date >, set< Date > > &commodityMap)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetLoader()

void resetLoader ( )

clear the loader

Definition at line 87 of file marketdataloader.hpp.

87{ loader_ = QuantLib::ext::make_shared<ore::data::InMemoryLoader>(); };

◆ loader()

const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > & loader ( ) const

getters

Definition at line 90 of file marketdataloader.hpp.

90{ return loader_; };

◆ quotes()

QuoteMap quotes ( )

Definition at line 91 of file marketdataloader.hpp.

91{ return quotes_; }
+ Here is the caller graph for this function:

◆ impl()

const QuantLib::ext::shared_ptr< MarketDataLoaderImpl > & impl ( ) const
protected

Definition at line 143 of file marketdataloader.cpp.

143 {
144 QL_REQUIRE(impl_, "No MarketDataLoader implementation of type MarketDataLoaderImpl set");
145 return impl_;
146}
+ Here is the caller graph for this function:

Member Data Documentation

◆ inputs_

QuantLib::ext::shared_ptr<InputParameters> inputs_
protected

Definition at line 94 of file marketdataloader.hpp.

◆ loader_

QuantLib::ext::shared_ptr<ore::data::InMemoryLoader> loader_
protected

Definition at line 95 of file marketdataloader.hpp.

◆ quotes_

QuoteMap quotes_
protected

Definition at line 96 of file marketdataloader.hpp.

◆ fixings_

FixingMap fixings_
protected

Definition at line 97 of file marketdataloader.hpp.

◆ impl_

QuantLib::ext::shared_ptr<MarketDataLoaderImpl> impl_
private

Definition at line 102 of file marketdataloader.hpp.