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

Engine/ Leg Builder Factory - notice that both engine and leg builders are allowed to maintain a state. More...

#include <ored/portfolio/enginefactory.hpp>

+ Inheritance diagram for EngineBuilderFactory:
+ Collaboration diagram for EngineBuilderFactory:

Public Member Functions

void addEngineBuilder (const std::function< QuantLib::ext::shared_ptr< EngineBuilder >()> &builder, const bool allowOverwrite=false)
 
void addAmcEngineBuilder (const std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &cam, const std::vector< Date > &grid)> &builder, const bool allowOverwrite=false)
 
void addAmcCgEngineBuilder (const std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< ore::data::ModelCG > &model, const std::vector< Date > &grid)> &builder, const bool allowOverwrite=false)
 
void addLegBuilder (const std::function< QuantLib::ext::shared_ptr< LegBuilder >()> &builder, const bool allowOverwrite=false)
 
std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > generateEngineBuilders () const
 
std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > generateAmcEngineBuilders (const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &cam, const std::vector< Date > &grid) const
 
std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > generateAmcCgEngineBuilders (const QuantLib::ext::shared_ptr< ore::data::ModelCG > &model, const std::vector< Date > &grid) const
 
std::vector< QuantLib::ext::shared_ptr< LegBuilder > > generateLegBuilders () const
 

Private Attributes

std::vector< std::function< QuantLib::ext::shared_ptr< EngineBuilder >()> > engineBuilderBuilders_
 
std::vector< std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &cam, const std::vector< Date > &grid)> > amcEngineBuilderBuilders_
 
std::vector< std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< ore::data::ModelCG > &model, const std::vector< Date > &grid)> > amcCgEngineBuilderBuilders_
 
std::vector< std::function< QuantLib::ext::shared_ptr< LegBuilder >()> > legBuilderBuilders_
 
boost::shared_mutex mutex_
 

Detailed Description

Engine/ Leg Builder Factory - notice that both engine and leg builders are allowed to maintain a state.

Definition at line 174 of file enginefactory.hpp.

Member Function Documentation

◆ addEngineBuilder()

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

Definition at line 65 of file enginefactory.cpp.

66 {
67 boost::unique_lock<boost::shared_mutex> lock(mutex_);
68 auto tmp = builder();
69 auto key = make_tuple(tmp->model(), tmp->engine(), tmp->tradeTypes());
70 auto it = std::remove_if(engineBuilderBuilders_.begin(), engineBuilderBuilders_.end(),
71 [&key](std::function<QuantLib::ext::shared_ptr<EngineBuilder>()>& b) {
72 auto tmp = b();
73 return key == std::make_tuple(tmp->model(), tmp->engine(), tmp->tradeTypes());
74 });
75 QL_REQUIRE(it == engineBuilderBuilders_.end() || allowOverwrite,
76 "EngineBuilderFactory::addEngineBuilder(" << tmp->model() << "/" << tmp->engine() << "/"
77 << boost::algorithm::join(tmp->tradeTypes(), ",")
78 << "): builder for given key already exists.");
80 engineBuilderBuilders_.push_back(builder);
81}
std::vector< std::function< QuantLib::ext::shared_ptr< EngineBuilder >()> > engineBuilderBuilders_

◆ addAmcEngineBuilder()

void addAmcEngineBuilder ( const std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &cam, const std::vector< Date > &grid)> &  builder,
const bool  allowOverwrite = false 
)

Definition at line 83 of file enginefactory.cpp.

86 {
87 boost::unique_lock<boost::shared_mutex> lock(mutex_);
88 auto tmp = builder(nullptr, {});
89 auto key = make_tuple(tmp->model(), tmp->engine(), tmp->tradeTypes());
90 auto it = std::remove_if(
92 [&key](std::function<QuantLib::ext::shared_ptr<EngineBuilder>(const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel>& cam,
93 const std::vector<Date>& grid)>& b) {
94 auto tmp = b(nullptr, {});
95 return key == std::make_tuple(tmp->model(), tmp->engine(), tmp->tradeTypes());
96 });
97 QL_REQUIRE(it == amcEngineBuilderBuilders_.end() || allowOverwrite,
98 "EngineBuilderFactory::addAmcEngineBuilder(" << tmp->model() << "/" << tmp->engine() << "/"
99 << boost::algorithm::join(tmp->tradeTypes(), ",")
100 << "): builder for given key already exists.");
102 amcEngineBuilderBuilders_.push_back(builder);
103}
std::vector< std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &cam, const std::vector< Date > &grid)> > amcEngineBuilderBuilders_

◆ addAmcCgEngineBuilder()

void addAmcCgEngineBuilder ( const std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< ore::data::ModelCG > &model, const std::vector< Date > &grid)> &  builder,
const bool  allowOverwrite = false 
)

Definition at line 105 of file enginefactory.cpp.

108 {
109 boost::unique_lock<boost::shared_mutex> lock(mutex_);
110 auto tmp = builder(nullptr, {});
111 auto key = make_tuple(tmp->model(), tmp->engine(), tmp->tradeTypes());
112 auto it = std::remove_if(
114 [&key](std::function<QuantLib::ext::shared_ptr<EngineBuilder>(const QuantLib::ext::shared_ptr<ore::data::ModelCG>& model,
115 const std::vector<Date>& grid)>& b) {
116 auto tmp = b(nullptr, {});
117 return key == std::make_tuple(tmp->model(), tmp->engine(), tmp->tradeTypes());
118 });
119 QL_REQUIRE(it == amcCgEngineBuilderBuilders_.end() || allowOverwrite,
120 "EngineBuilderFactory::addAmcCgEngineBuilder(" << tmp->model() << "/" << tmp->engine() << "/"
121 << boost::algorithm::join(tmp->tradeTypes(), ",")
122 << "): builder for given key already exists.");
124 amcCgEngineBuilderBuilders_.push_back(builder);
125}
std::vector< std::function< QuantLib::ext::shared_ptr< EngineBuilder >(const QuantLib::ext::shared_ptr< ore::data::ModelCG > &model, const std::vector< Date > &grid)> > amcCgEngineBuilderBuilders_

◆ addLegBuilder()

void addLegBuilder ( const std::function< QuantLib::ext::shared_ptr< LegBuilder >()> &  builder,
const bool  allowOverwrite = false 
)

Definition at line 127 of file enginefactory.cpp.

128 {
129 boost::unique_lock<boost::shared_mutex> lock(mutex_);
130 auto key = builder()->legType();
131 auto it =
132 std::remove_if(legBuilderBuilders_.begin(), legBuilderBuilders_.end(),
133 [&key](std::function<QuantLib::ext::shared_ptr<LegBuilder>()>& b) { return key == b()->legType(); });
134 QL_REQUIRE(it == legBuilderBuilders_.end() || allowOverwrite,
135 "EngineBuilderFactory::addLegBuilder(" << key << "): builder for given key already exists.");
137 legBuilderBuilders_.push_back(builder);
138}
std::vector< std::function< QuantLib::ext::shared_ptr< LegBuilder >()> > legBuilderBuilders_

◆ generateEngineBuilders()

std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > generateEngineBuilders ( ) const

Definition at line 140 of file enginefactory.cpp.

140 {
141 boost::shared_lock<boost::shared_mutex> lock(mutex_);
142 std::vector<QuantLib::ext::shared_ptr<EngineBuilder>> result;
143 for (auto const& b : engineBuilderBuilders_)
144 result.push_back(b());
145 return result;
146}

◆ generateAmcEngineBuilders()

std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > generateAmcEngineBuilders ( const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &  cam,
const std::vector< Date > &  grid 
) const

Definition at line 149 of file enginefactory.cpp.

150 {
151 boost::shared_lock<boost::shared_mutex> lock(mutex_);
152 std::vector<QuantLib::ext::shared_ptr<EngineBuilder>> result;
153 for (auto const& b : amcEngineBuilderBuilders_)
154 result.push_back(b(cam, grid));
155 return result;
156}

◆ generateAmcCgEngineBuilders()

std::vector< QuantLib::ext::shared_ptr< EngineBuilder > > generateAmcCgEngineBuilders ( const QuantLib::ext::shared_ptr< ore::data::ModelCG > &  model,
const std::vector< Date > &  grid 
) const

Definition at line 159 of file enginefactory.cpp.

160 {
161 boost::shared_lock<boost::shared_mutex> lock(mutex_);
162 std::vector<QuantLib::ext::shared_ptr<EngineBuilder>> result;
163 for (auto const& b : amcCgEngineBuilderBuilders_)
164 result.push_back(b(model, grid));
165 return result;
166}

◆ generateLegBuilders()

std::vector< QuantLib::ext::shared_ptr< LegBuilder > > generateLegBuilders ( ) const

Definition at line 168 of file enginefactory.cpp.

168 {
169 boost::shared_lock<boost::shared_mutex> lock(mutex_);
170 std::vector<QuantLib::ext::shared_ptr<LegBuilder>> result;
171 for (auto const& b : legBuilderBuilders_)
172 result.push_back(b());
173 return result;
174}

Member Data Documentation

◆ engineBuilderBuilders_

std::vector<std::function<QuantLib::ext::shared_ptr<EngineBuilder>()> > engineBuilderBuilders_
private

Definition at line 175 of file enginefactory.hpp.

◆ amcEngineBuilderBuilders_

std::vector<std::function<QuantLib::ext::shared_ptr<EngineBuilder>(const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel>& cam, const std::vector<Date>& grid)> > amcEngineBuilderBuilders_
private

Definition at line 178 of file enginefactory.hpp.

◆ amcCgEngineBuilderBuilders_

std::vector<std::function<QuantLib::ext::shared_ptr<EngineBuilder>(const QuantLib::ext::shared_ptr<ore::data::ModelCG>& model, const std::vector<Date>& grid)> > amcCgEngineBuilderBuilders_
private

Definition at line 181 of file enginefactory.hpp.

◆ legBuilderBuilders_

std::vector<std::function<QuantLib::ext::shared_ptr<LegBuilder>()> > legBuilderBuilders_
private

Definition at line 182 of file enginefactory.hpp.

◆ mutex_

boost::shared_mutex mutex_
mutableprivate

Definition at line 183 of file enginefactory.hpp.