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

Pricing Engine Factory class. More...

#include <ored/portfolio/enginefactory.hpp>

+ Collaboration diagram for EngineFactory:

Public Member Functions

 EngineFactory (const QuantLib::ext::shared_ptr< EngineData > &data, const QuantLib::ext::shared_ptr< Market > &market, const map< MarketContext, string > &configurations=std::map< MarketContext, string >(), const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceData=nullptr, const IborFallbackConfig &iborFallbackConfig=IborFallbackConfig::defaultConfig(), const std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > extraEngineBuilders={}, const bool allowOverwrite=false)
 Create an engine factory. More...
 
const QuantLib::ext::shared_ptr< Market > & market () const
 Return the market used by this EngineFactory. More...
 
const map< MarketContext, string > & configurations () const
 Return the market configurations used by this EngineFactory. More...
 
const string & configuration (const MarketContext &key)
 Return a configuration (or the default one if key not found) More...
 
const QuantLib::ext::shared_ptr< EngineDataengineData () const
 Return the EngineData parameters. More...
 
void registerBuilder (const QuantLib::ext::shared_ptr< EngineBuilder > &builder, const bool allowOverwrite=false)
 Register a builder with the factory. More...
 
const QuantLib::ext::shared_ptr< ReferenceDataManager > & referenceData () const
 Return the reference data used by this EngineFactory. More...
 
const IborFallbackConfigiborFallbackConfig () const
 Return the ibor fallback config. More...
 
QuantLib::ext::shared_ptr< EngineBuilderbuilder (const string &tradeType)
 Get a builder by trade type. More...
 
void registerLegBuilder (const QuantLib::ext::shared_ptr< LegBuilder > &legBuilder, const bool allowOverwrite=false)
 Register a leg builder with the factory. More...
 
QuantLib::ext::shared_ptr< LegBuilderlegBuilder (const string &legType)
 Get a leg builder by leg type. More...
 
void addDefaultBuilders ()
 Add a set of default engine and leg builders. More...
 
void addExtraBuilders (const std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > extraEngineBuilders, const std::vector< QuantLib::ext::shared_ptr< LegBuilder > > extraLegBuilders, const bool allowOverwrite=false)
 Add a set of default engine and leg builders, overwrite existing builders with same key if specified. More...
 
void clear ()
 Clear all builders. More...
 
set< std::pair< string, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > modelBuilders () const
 return model builders More...
 

Private Attributes

QuantLib::ext::shared_ptr< Marketmarket_
 
QuantLib::ext::shared_ptr< EngineDataengineData_
 
map< MarketContext, string > configurations_
 
map< tuple< string, string, set< string > >, QuantLib::ext::shared_ptr< EngineBuilder > > builders_
 
map< string, QuantLib::ext::shared_ptr< LegBuilder > > legBuilders_
 
QuantLib::ext::shared_ptr< ReferenceDataManagerreferenceData_
 
IborFallbackConfig iborFallbackConfig_
 

Detailed Description

Pricing Engine Factory class.

A Pricing Engine Factory is used when building a portfolio, it provides QuantLib::PricingEngines to each of the Trade objects.

An Engine Factory is configured on two levels, both from EngineData. The first level is the type of builder (Model and Engine) to use for each trade type, so given a trade type one asks the factory for a builder and then the builder for a PricingEngine. Each builder must be registered with the factory and then the configuration defines which builder to use.

Secondly, the factory maintains builder specific parameters for each Model and Engine.

Definition at line 224 of file enginefactory.hpp.

Constructor & Destructor Documentation

◆ EngineFactory()

EngineFactory ( const QuantLib::ext::shared_ptr< EngineData > &  data,
const QuantLib::ext::shared_ptr< Market > &  market,
const map< MarketContext, string > &  configurations = std::map<MarketContext, string>(),
const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceData = nullptr,
const IborFallbackConfig iborFallbackConfig = IborFallbackConfig::defaultConfig(),
const std::vector< QuantLib::ext::shared_ptr< EngineBuilder > >  extraEngineBuilders = {},
const bool  allowOverwrite = false 
)

Create an engine factory.

Parameters
dataConfiguration data
marketThe market that is passed to each builder
configurationsThe market configurations that are passed to each builder
referenceDatareference data
iborFallbackConfigibor fallback config
extraEngineBuildersadditional engine builders
allowOverwriteadditional engine builders may overwrite existing builders with same key

Definition at line 176 of file enginefactory.cpp.

184 LOG("Building EngineFactory");
185
187 addExtraBuilders(extraEngineBuilders, {}, allowOverwrite);
188}
const QuantLib::ext::shared_ptr< Market > & market() const
Return the market used by this EngineFactory.
QuantLib::ext::shared_ptr< Market > market_
const IborFallbackConfig & iborFallbackConfig() const
Return the ibor fallback config.
const map< MarketContext, string > & configurations() const
Return the market configurations used by this EngineFactory.
QuantLib::ext::shared_ptr< EngineData > engineData_
void addDefaultBuilders()
Add a set of default engine and leg builders.
map< MarketContext, string > configurations_
const QuantLib::ext::shared_ptr< EngineData > engineData() const
Return the EngineData parameters.
IborFallbackConfig iborFallbackConfig_
QuantLib::ext::shared_ptr< ReferenceDataManager > referenceData_
const QuantLib::ext::shared_ptr< ReferenceDataManager > & referenceData() const
Return the reference data used by this EngineFactory.
void addExtraBuilders(const std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > extraEngineBuilders, const std::vector< QuantLib::ext::shared_ptr< LegBuilder > > extraLegBuilders, const bool allowOverwrite=false)
Add a set of default engine and leg builders, overwrite existing builders with same key if specified.
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
+ Here is the call graph for this function:

Member Function Documentation

◆ market()

const QuantLib::ext::shared_ptr< Market > & market ( ) const

Return the market used by this EngineFactory.

Definition at line 243 of file enginefactory.hpp.

243{ return market_; };

◆ configurations()

const map< MarketContext, string > & configurations ( ) const

Return the market configurations used by this EngineFactory.

Definition at line 245 of file enginefactory.hpp.

245{ return configurations_; };

◆ configuration()

const string & configuration ( const MarketContext key)

Return a configuration (or the default one if key not found)

Definition at line 247 of file enginefactory.hpp.

247 {
248 if (configurations_.count(key) > 0) {
249 return configurations_.at(key);
250 } else {
252 }
253 }
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296

◆ engineData()

const QuantLib::ext::shared_ptr< EngineData > engineData ( ) const

Return the EngineData parameters.

Definition at line 255 of file enginefactory.hpp.

255{ return engineData_; };

◆ registerBuilder()

void registerBuilder ( const QuantLib::ext::shared_ptr< EngineBuilder > &  builder,
const bool  allowOverwrite = false 
)

Register a builder with the factory.

Definition at line 190 of file enginefactory.cpp.

190 {
191 const string& modelName = builder->model();
192 const string& engineName = builder->engine();
193 auto key = make_tuple(modelName, engineName, builder->tradeTypes());
194 if (allowOverwrite)
195 builders_.erase(key);
196 QL_REQUIRE(builders_.insert(make_pair(key, builder)).second,
197 "EngineFactory: duplicate engine builder for (" << modelName << "/" << engineName << "/"
198 << boost::algorithm::join(builder->tradeTypes(), ",")
199 << ") - this is an internal error.");
200}
QuantLib::ext::shared_ptr< EngineBuilder > builder(const string &tradeType)
Get a builder by trade type.
map< tuple< string, string, set< string > >, QuantLib::ext::shared_ptr< EngineBuilder > > builders_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ referenceData()

const QuantLib::ext::shared_ptr< ReferenceDataManager > & referenceData ( ) const

Return the reference data used by this EngineFactory.

Definition at line 259 of file enginefactory.hpp.

259{ return referenceData_; };

◆ iborFallbackConfig()

const IborFallbackConfig & iborFallbackConfig ( ) const

Return the ibor fallback config.

Definition at line 261 of file enginefactory.hpp.

261{ return iborFallbackConfig_; }

◆ builder()

QuantLib::ext::shared_ptr< EngineBuilder > builder ( const string &  tradeType)

Get a builder by trade type.

This will look up configured model/engine for that trade type the returned builder can be cast to the type required for the tradeType.

The factory will call EngineBuilder::init() before returning it.

Definition at line 202 of file enginefactory.cpp.

202 {
203 // Check that we have a model/engine for tradetype
204 QL_REQUIRE(engineData_->hasProduct(tradeType),
205 "No Pricing Engine configuration was provided for trade type " << tradeType);
206
207 // Find a builder for the model/engine/tradeType
208 const string& model = engineData_->model(tradeType);
209 const string& engine = engineData_->engine(tradeType);
210 typedef pair<tuple<string, string, set<string>>, QuantLib::ext::shared_ptr<EngineBuilder>> map_type;
211 auto pred = [&model, &engine, &tradeType](const map_type& v) -> bool {
212 const set<string>& types = std::get<2>(v.first);
213 return std::get<0>(v.first) == model && std::get<1>(v.first) == engine &&
214 std::find(types.begin(), types.end(), tradeType) != types.end();
215 };
216 auto it = std::find_if(builders_.begin(), builders_.end(), pred);
217 QL_REQUIRE(it != builders_.end(), "No EngineBuilder for " << model << "/" << engine << "/" << tradeType);
218 QL_REQUIRE(std::find_if(std::next(it, 1), builders_.end(), pred) == builders_.end(),
219 "Ambiguous EngineBuilder for " << model << "/" << engine << "/" << tradeType);
220
221 QuantLib::ext::shared_ptr<EngineBuilder> builder = it->second;
222 string effectiveTradeType = tradeType;
223 if(auto db = QuantLib::ext::dynamic_pointer_cast<DelegatingEngineBuilder>(builder))
224 effectiveTradeType = db->effectiveTradeType();
225
226 builder->init(market_, configurations_, engineData_->modelParameters(effectiveTradeType),
227 engineData_->engineParameters(effectiveTradeType), engineData_->globalParameters());
228
229 return builder;
230}
boost::bimap< std::string, TRS::FundingData::NotionalType > types
Definition: trs.cpp:783
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerLegBuilder()

void registerLegBuilder ( const QuantLib::ext::shared_ptr< LegBuilder > &  legBuilder,
const bool  allowOverwrite = false 
)

Register a leg builder with the factory.

Definition at line 232 of file enginefactory.cpp.

232 {
233 if (allowOverwrite)
234 legBuilders_.erase(legBuilder->legType());
235 QL_REQUIRE(legBuilders_.insert(make_pair(legBuilder->legType(), legBuilder)).second,
236 "EngineFactory duplicate leg builder for '" << legBuilder->legType()
237 << "' - this is an internal error.");
238}
map< string, QuantLib::ext::shared_ptr< LegBuilder > > legBuilders_
QuantLib::ext::shared_ptr< LegBuilder > legBuilder(const string &legType)
Get a leg builder by leg type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ legBuilder()

QuantLib::ext::shared_ptr< LegBuilder > legBuilder ( const string &  legType)

Get a leg builder by leg type.

Definition at line 240 of file enginefactory.cpp.

240 {
241 auto it = legBuilders_.find(legType);
242 QL_REQUIRE(it != legBuilders_.end(), "No LegBuilder for " << legType);
243 return it->second;
244}
+ Here is the caller graph for this function:

◆ addDefaultBuilders()

void addDefaultBuilders ( )

Add a set of default engine and leg builders.

Definition at line 254 of file enginefactory.cpp.

254 {
255 for(auto const& b: EngineBuilderFactory::instance().generateEngineBuilders())
257 for(auto const& b: EngineBuilderFactory::instance().generateLegBuilders())
259}
void registerBuilder(const QuantLib::ext::shared_ptr< EngineBuilder > &builder, const bool allowOverwrite=false)
Register a builder with the factory.
void registerLegBuilder(const QuantLib::ext::shared_ptr< LegBuilder > &legBuilder, const bool allowOverwrite=false)
Register a leg builder with the factory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addExtraBuilders()

void addExtraBuilders ( const std::vector< QuantLib::ext::shared_ptr< EngineBuilder > >  extraEngineBuilders,
const std::vector< QuantLib::ext::shared_ptr< LegBuilder > >  extraLegBuilders,
const bool  allowOverwrite = false 
)

Add a set of default engine and leg builders, overwrite existing builders with same key if specified.

Definition at line 261 of file enginefactory.cpp.

263 {
264
265 if (extraEngineBuilders.size() > 0) {
266 DLOG("adding " << extraEngineBuilders.size() << " extra engine builders");
267 for (auto eb : extraEngineBuilders)
268 registerBuilder(eb, allowOverwrite);
269 }
270 if (extraLegBuilders.size() > 0) {
271 DLOG("adding " << extraLegBuilders.size() << " extra leg builders");
272 for (auto elb : extraLegBuilders)
273 registerLegBuilder(elb, allowOverwrite);
274 }
275}
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

void clear ( )

Clear all builders.

Definition at line 285 of file enginefactory.hpp.

285 {
286 builders_.clear();
287 legBuilders_.clear();
288 }

◆ modelBuilders()

set< std::pair< string, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > modelBuilders ( ) const

return model builders

Definition at line 246 of file enginefactory.cpp.

246 {
247 set<std::pair<string, QuantLib::ext::shared_ptr<QuantExt::ModelBuilder>>> res;
248 for (auto const& b : builders_) {
249 res.insert(b.second->modelBuilders().begin(), b.second->modelBuilders().end());
250 }
251 return res;
252}

Member Data Documentation

◆ market_

QuantLib::ext::shared_ptr<Market> market_
private

Definition at line 294 of file enginefactory.hpp.

◆ engineData_

QuantLib::ext::shared_ptr<EngineData> engineData_
private

Definition at line 295 of file enginefactory.hpp.

◆ configurations_

map<MarketContext, string> configurations_
private

Definition at line 296 of file enginefactory.hpp.

◆ builders_

map<tuple<string, string, set<string> >, QuantLib::ext::shared_ptr<EngineBuilder> > builders_
private

Definition at line 297 of file enginefactory.hpp.

◆ legBuilders_

map<string, QuantLib::ext::shared_ptr<LegBuilder> > legBuilders_
private

Definition at line 298 of file enginefactory.hpp.

◆ referenceData_

QuantLib::ext::shared_ptr<ReferenceDataManager> referenceData_
private

Definition at line 299 of file enginefactory.hpp.

◆ iborFallbackConfig_

IborFallbackConfig iborFallbackConfig_
private

Definition at line 300 of file enginefactory.hpp.