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

#include <orea/app/analytic.hpp>

+ Inheritance diagram for Analytic:
+ Collaboration diagram for Analytic:

Classes

struct  Configurations
 
class  Impl
 

Public Types

typedef std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< ore::data::InMemoryReport > > > analytic_reports
 
typedef std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< NPVCube > > > analytic_npvcubes
 
typedef std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< AggregationScenarioData > > > analytic_mktcubes
 
typedef std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< StressTestScenarioData > > > analytic_stresstests
 

Public Member Functions

 Analytic ()
 Constructors. More...
 
 Analytic (std::unique_ptr< Impl > impl, const std::set< std::string > &analyticTypes, const QuantLib::ext::shared_ptr< InputParameters > &inputs, bool simulationConfig=false, bool sensitivityConfig=false, bool scenarioGeneratorConfig=false, bool crossAssetModelConfig=false)
 
virtual ~Analytic ()
 
virtual void runAnalytic (const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={})
 Run only those analytic types that are inclcuded in the runTypes vector, run all if the runType vector is empty. More...
 
virtual void buildConfigurations (const bool=false)
 
virtual void setUpConfigurations ()
 
virtual void buildMarket (const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
 
virtual void buildPortfolio ()
 
virtual void marketCalibration (const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &mcr=nullptr)
 
virtual void modifyPortfolio ()
 
virtual void replaceTrades ()
 
const std::string label () const
 Inspectors. More...
 
const std::set< std::string > & analyticTypes () const
 
const QuantLib::ext::shared_ptr< InputParameters > & inputs () const
 
const QuantLib::ext::shared_ptr< ore::data::Market > & market () const
 
QuantLib::ext::shared_ptr< MarketImplgetMarket () const
 
const QuantLib::ext::shared_ptr< ore::data::Portfolio > & portfolio () const
 
void setInputs (const QuantLib::ext::shared_ptr< InputParameters > &inputs)
 
void setMarket (const QuantLib::ext::shared_ptr< ore::data::Market > &market)
 
void setPortfolio (const QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio)
 
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams ()
 
const QuantLib::ext::shared_ptr< ore::data::Loader > & loader () const
 
Configurationsconfigurations ()
 
analytic_reportsreports ()
 Result reports. More...
 
analytic_npvcubesnpvCubes ()
 
analytic_mktcubesmktCubes ()
 
analytic_stresstestsstressTests ()
 
const bool getWriteIntermediateReports () const
 
void setWriteIntermediateReports (const bool flag)
 
bool match (const std::set< std::string > &runTypes)
 Check whether any of the requested run types is covered by this analytic. More...
 
const std::unique_ptr< Impl > & impl ()
 
std::set< QuantLib::Date > marketDates () const
 
std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics () const
 

Protected Attributes

std::unique_ptr< Implimpl_
 
std::set< std::string > types_
 list of analytic types run by this analytic More...
 
QuantLib::ext::shared_ptr< InputParametersinputs_
 contains all the input parameters for the run More...
 
Configurations configurations_
 
QuantLib::ext::shared_ptr< ore::data::Marketmarket_
 
QuantLib::ext::shared_ptr< ore::data::Loaderloader_
 
QuantLib::ext::shared_ptr< ore::data::Portfolioportfolio_
 
analytic_reports reports_
 
analytic_npvcubes npvCubes_
 
analytic_mktcubes mktCubes_
 
analytic_stresstests stressTests_
 
bool writeIntermediateReports_ = true
 

Detailed Description

Definition at line 46 of file analytic.hpp.

Member Typedef Documentation

◆ analytic_reports

typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<ore::data::InMemoryReport> > > analytic_reports

Definition at line 51 of file analytic.hpp.

◆ analytic_npvcubes

typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<NPVCube> > > analytic_npvcubes

Definition at line 54 of file analytic.hpp.

◆ analytic_mktcubes

typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<AggregationScenarioData> > > analytic_mktcubes

Definition at line 57 of file analytic.hpp.

◆ analytic_stresstests

typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<StressTestScenarioData> > > analytic_stresstests

Definition at line 60 of file analytic.hpp.

Constructor & Destructor Documentation

◆ Analytic() [1/2]

Analytic ( )

Constructors.

Definition at line 79 of file analytic.hpp.

79{};

◆ Analytic() [2/2]

Analytic ( std::unique_ptr< Impl impl,
const std::set< std::string > &  analyticTypes,
const QuantLib::ext::shared_ptr< InputParameters > &  inputs,
bool  simulationConfig = false,
bool  sensitivityConfig = false,
bool  scenarioGeneratorConfig = false,
bool  crossAssetModelConfig = false 
)
Parameters
implConcrete implementation of the analytic
analyticTypesThe types of all (sub) analytics covered by this Analytic object e.g. NPV, CASHFLOW, CASHFLOWNPV, etc., covered by the PricingAnalytic
inputsAny inputs required by this Analytic
simulationConfigFlag to indicate whether a simulation config file is required for this analytic
sensitivityConfigFlag to indicate whether a sensitivity config file is required for this analytic
scenarioGeneratorConfigFlag to indicate whether a scenario generator config file is required for this analytic
crossAssetModelConfigFlag to indicate whether a cross asset model config file is required for this analytic

Definition at line 53 of file analytic.cpp.

60 : impl_(std::move(impl)), types_(analyticTypes), inputs_(inputs) {
61
62 configurations().asofDate = inputs->asof();
63
64 // set these here, can be overwritten in setUpConfigurations
65 if (inputs->curveConfigs().has())
66 configurations().curveConfig = inputs->curveConfigs().get();
67 if (inputs->pricingEngine())
68 configurations().engineData = inputs->pricingEngine();
69
70 configurations().simulationConfigRequired = simulationConfig;
71 configurations().sensitivityConfigRequired = sensitivityConfig;
72 configurations().scenarioGeneratorConfigRequired = scenarioGeneratorConfig;
73 configurations().crossAssetModelConfigRequired = crossAssetModelConfig;
74
75 if (impl_) {
76 impl_->setAnalytic(this);
77 impl_->setGenerateAdditionalResults(inputs_->outputAdditionalResults());
78 }
79
81}
Configurations & configurations()
Definition: analytic.hpp:128
const std::unique_ptr< Impl > & impl()
Definition: analytic.hpp:142
const QuantLib::ext::shared_ptr< InputParameters > & inputs() const
Definition: analytic.hpp:116
std::unique_ptr< Impl > impl_
Definition: analytic.hpp:151
std::set< std::string > types_
list of analytic types run by this analytic
Definition: analytic.hpp:154
virtual void setUpConfigurations()
Definition: analytic.cpp:92
const std::set< std::string > & analyticTypes() const
Definition: analytic.hpp:115
QuantLib::ext::shared_ptr< InputParameters > inputs_
contains all the input parameters for the run
Definition: analytic.hpp:156
QuantLib::ext::shared_ptr< ore::data::EngineData > engineData
Definition: analytic.hpp:74
QuantLib::ext::shared_ptr< CurveConfigurations > curveConfig
Definition: analytic.hpp:73
bool simulationConfigRequired
Booleans to determine if these configs are needed.
Definition: analytic.hpp:64
+ Here is the call graph for this function:

◆ ~Analytic()

virtual ~Analytic ( )
virtual

Definition at line 96 of file analytic.hpp.

96{}

Member Function Documentation

◆ runAnalytic()

void runAnalytic ( const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &  loader,
const std::set< std::string > &  runTypes = {} 
)
virtual

Run only those analytic types that are inclcuded in the runTypes vector, run all if the runType vector is empty.

Definition at line 83 of file analytic.cpp.

84 {
85 MEM_LOG_USING_LEVEL(ORE_WARNING)
86 if (impl_) {
87 impl_->runAnalytic(loader, runTypes);
88 MEM_LOG_USING_LEVEL(ORE_WARNING)
89 }
90}
const QuantLib::ext::shared_ptr< ore::data::Loader > & loader() const
Definition: analytic.hpp:127
#define MEM_LOG_USING_LEVEL(LEVEL)
+ Here is the call graph for this function:

◆ buildConfigurations()

virtual void buildConfigurations ( const bool  = false)
virtual

Definition at line 103 of file analytic.hpp.

103{};
+ Here is the caller graph for this function:

◆ setUpConfigurations()

void setUpConfigurations ( )
virtual

Definition at line 92 of file analytic.cpp.

92 {
93 if (impl_)
94 impl_->setUpConfigurations();
95}
+ Here is the caller graph for this function:

◆ buildMarket()

void buildMarket ( const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &  loader,
const bool  marketRequired = true 
)
virtual

Definition at line 178 of file analytic.cpp.

179 {
180 LOG("Analytic::buildMarket called");
181 cpu_timer mtimer;
182
183 QL_REQUIRE(loader, "market data loader not set");
184 QL_REQUIRE(configurations().curveConfig, "curve configurations not set");
185
186 // first build the market if we have a todaysMarketParams
188 try {
189 // imply bond spreads (no exclusion of securities in ore, just in ore+) and add results to loader
191 loader, configurations_.curveConfig, std::string());
192
193 // Join the loaders
194 loader_ = QuantLib::ext::make_shared<CompositeLoader>(loader, bondSpreads);
195
196 // Check that the loader has quotes
197 QL_REQUIRE(loader_->hasQuotes(configurations().asofDate),
198 "There are no quotes available for date " << configurations().asofDate);
199 // Build the market
200 market_ = QuantLib::ext::make_shared<TodaysMarket>(
202 inputs()->continueOnError(), true, inputs()->lazyMarketBuilding(), inputs()->refDataManager(), false,
203 *inputs()->iborFallbackConfig());
204 } catch (const std::exception& e) {
205 if (marketRequired)
206 QL_FAIL("Failed to build market: " << e.what());
207 else
208 WLOG("Failed to build market: " << e.what());
209 }
210 } else {
211 ALOG("Skip building the market due to missing today's market parameters in configurations");
212 }
213 mtimer.stop();
214 LOG("Market Build time " << setprecision(2) << mtimer.format(default_places, "%w") << " sec");
215}
QuantLib::ext::shared_ptr< ore::data::Market > market_
Definition: analytic.hpp:159
Configurations configurations_
Definition: analytic.hpp:158
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams()
Definition: analytic.cpp:147
QuantLib::ext::shared_ptr< ore::data::Loader > loader_
Definition: analytic.hpp:160
#define LOG(text)
#define ALOG(text)
#define WLOG(text)
QuantLib::ext::shared_ptr< Loader > implyBondSpreads(const Date &asof, const QuantLib::ext::shared_ptr< ore::analytics::InputParameters > &params, const QuantLib::ext::shared_ptr< TodaysMarketParameters > &todaysMarketParams, const QuantLib::ext::shared_ptr< Loader > &loader, const QuantLib::ext::shared_ptr< CurveConfigurations > &curveConfigs, const std::string &excludeRegex)
Definition: analytic.cpp:273
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
Definition: analytic.hpp:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildPortfolio()

void buildPortfolio ( )
virtual

Definition at line 222 of file analytic.cpp.

222 {
223 QuantLib::ext::shared_ptr<Portfolio> tmp = portfolio_ ? portfolio_ : inputs()->portfolio();
224
225 // create a new empty portfolio
226 portfolio_ = QuantLib::ext::make_shared<Portfolio>(inputs()->buildFailedTrades());
227
228 tmp->reset();
229 // populate with trades
230 for (const auto& [tradeId, trade] : tmp->trades())
231 // If portfolio was already provided to the analytic, make sure to only process those given trades.
232 portfolio()->add(trade);
233
234 if (market_) {
236
237 LOG("Build the portfolio");
238 QuantLib::ext::shared_ptr<EngineFactory> factory = impl()->engineFactory();
239 portfolio()->build(factory, "analytic/" + label());
240
241 // remove dates that will have matured
242 Date maturityDate = inputs()->asof();
243 if (inputs()->portfolioFilterDate() != Null<Date>())
244 maturityDate = inputs()->portfolioFilterDate();
245
246 LOG("Filter trades that expire before " << maturityDate);
247 portfolio()->removeMatured(maturityDate);
248 } else {
249 ALOG("Skip building the portfolio, because market not set");
250 }
251}
const std::string label() const
Inspectors.
Definition: analytic.cpp:113
QuantLib::ext::shared_ptr< ore::data::Portfolio > portfolio_
Definition: analytic.hpp:161
const QuantLib::ext::shared_ptr< ore::data::Portfolio > & portfolio() const
Definition: analytic.hpp:122
virtual void replaceTrades()
Definition: analytic.hpp:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ marketCalibration()

void marketCalibration ( const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &  mcr = nullptr)
virtual

Definition at line 217 of file analytic.cpp.

217 {
218 if (mcr)
219 mcr->populateReport(market_, configurations().todaysMarketParams);
220}
+ Here is the call graph for this function:

◆ modifyPortfolio()

virtual void modifyPortfolio ( )
virtual

Definition at line 110 of file analytic.hpp.

110{}
+ Here is the caller graph for this function:

◆ replaceTrades()

virtual void replaceTrades ( )
virtual

Definition at line 111 of file analytic.hpp.

111{}
+ Here is the caller graph for this function:

◆ label()

const std::string label ( ) const

Inspectors.

Definition at line 113 of file analytic.cpp.

113 {
114 return impl_ ? impl_->label() : string();
115}
+ Here is the caller graph for this function:

◆ analyticTypes()

const std::set< std::string > & analyticTypes ( ) const

Definition at line 115 of file analytic.hpp.

115{ return types_; }

◆ inputs()

const QuantLib::ext::shared_ptr< InputParameters > & inputs ( ) const

Definition at line 116 of file analytic.hpp.

116{ return inputs_; }
+ Here is the caller graph for this function:

◆ market()

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

Definition at line 117 of file analytic.hpp.

117{ return market_; };
+ Here is the caller graph for this function:

◆ getMarket()

QuantLib::ext::shared_ptr< MarketImpl > getMarket ( ) const

Definition at line 119 of file analytic.hpp.

119 {
120 return QuantLib::ext::dynamic_pointer_cast<MarketImpl>(market_);
121 }

◆ portfolio()

const QuantLib::ext::shared_ptr< ore::data::Portfolio > & portfolio ( ) const

Definition at line 122 of file analytic.hpp.

122{ return portfolio_; };
+ Here is the caller graph for this function:

◆ setInputs()

void setInputs ( const QuantLib::ext::shared_ptr< InputParameters > &  inputs)

Definition at line 123 of file analytic.hpp.

123{ inputs_ = inputs; }
+ Here is the call graph for this function:

◆ setMarket()

void setMarket ( const QuantLib::ext::shared_ptr< ore::data::Market > &  market)

Definition at line 124 of file analytic.hpp.

124{ market_ = market; };
const QuantLib::ext::shared_ptr< ore::data::Market > & market() const
Definition: analytic.hpp:117
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPortfolio()

void setPortfolio ( const QuantLib::ext::shared_ptr< ore::data::Portfolio > &  portfolio)

Definition at line 125 of file analytic.hpp.

125{ portfolio_ = portfolio; };
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ todaysMarketParams()

std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams ( )

Definition at line 147 of file analytic.cpp.

147 {
149 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> tmps;
151 tmps.push_back(configurations().todaysMarketParams);
152
153 for (const auto& a : impl_->dependentAnalytics()) {
154 auto ctmps = a.second->todaysMarketParams();
155 tmps.insert(end(tmps), begin(ctmps), end(ctmps));
156 }
157
158 return tmps;
159}
virtual void buildConfigurations(const bool=false)
Definition: analytic.hpp:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loader()

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

Definition at line 127 of file analytic.hpp.

127{ return loader_; };
+ Here is the caller graph for this function:

◆ configurations()

Configurations & configurations ( )

Definition at line 128 of file analytic.hpp.

128{ return configurations_; }
+ Here is the caller graph for this function:

◆ reports()

analytic_reports & reports ( )

Result reports.

Definition at line 131 of file analytic.hpp.

131{ return reports_; };
analytic_reports reports_
Definition: analytic.hpp:163
+ Here is the caller graph for this function:

◆ npvCubes()

analytic_npvcubes & npvCubes ( )

Definition at line 132 of file analytic.hpp.

132{ return npvCubes_; };
analytic_npvcubes npvCubes_
Definition: analytic.hpp:164
+ Here is the caller graph for this function:

◆ mktCubes()

analytic_mktcubes & mktCubes ( )

Definition at line 133 of file analytic.hpp.

133{ return mktCubes_; };
analytic_mktcubes mktCubes_
Definition: analytic.hpp:165
+ Here is the caller graph for this function:

◆ stressTests()

analytic_stresstests & stressTests ( )

Definition at line 134 of file analytic.hpp.

134{ return stressTests_;}
analytic_stresstests stressTests_
Definition: analytic.hpp:166
+ Here is the caller graph for this function:

◆ getWriteIntermediateReports()

const bool getWriteIntermediateReports ( ) const

Definition at line 136 of file analytic.hpp.

◆ setWriteIntermediateReports()

void setWriteIntermediateReports ( const bool  flag)

Definition at line 137 of file analytic.hpp.

◆ match()

bool match ( const std::set< std::string > &  runTypes)

Check whether any of the requested run types is covered by this analytic.

Definition at line 118 of file analytic.cpp.

118 {
119 if (runTypes.size() == 0)
120 return true;
121
122 for (const auto& rt : runTypes) {
123 if (types_.find(rt) != types_.end()) {
124 LOG("Requested analytics " << to_string(runTypes) << " match analytic class " << label());
125 return true;
126 }
127 }
128 return false;
129}
std::string to_string(const LocationInfo &l)
+ Here is the call graph for this function:

◆ impl()

const std::unique_ptr< Impl > & impl ( )

Definition at line 142 of file analytic.hpp.

142 {
143 return impl_;
144 }
+ Here is the caller graph for this function:

◆ marketDates()

std::set< QuantLib::Date > marketDates ( ) const

Definition at line 135 of file analytic.cpp.

135 {
136 std::set<QuantLib::Date> mds = {inputs_->asof()};
137 auto addDates = impl_->additionalMarketDates();
138 mds.insert(addDates.begin(), addDates.end());
139
140 for (const auto& a : impl_->dependentAnalytics()) {
141 addDates = a.second->impl()->additionalMarketDates();
142 mds.insert(addDates.begin(), addDates.end());
143 }
144 return mds;
145}

◆ allDependentAnalytics()

std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics ( ) const

Definition at line 131 of file analytic.cpp.

131 {
132 return impl_->allDependentAnalytics();
133}

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> impl_
protected

Definition at line 151 of file analytic.hpp.

◆ types_

std::set<std::string> types_
protected

list of analytic types run by this analytic

Definition at line 154 of file analytic.hpp.

◆ inputs_

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

contains all the input parameters for the run

Definition at line 156 of file analytic.hpp.

◆ configurations_

Configurations configurations_
protected

Definition at line 158 of file analytic.hpp.

◆ market_

QuantLib::ext::shared_ptr<ore::data::Market> market_
protected

Definition at line 159 of file analytic.hpp.

◆ loader_

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

Definition at line 160 of file analytic.hpp.

◆ portfolio_

QuantLib::ext::shared_ptr<ore::data::Portfolio> portfolio_
protected

Definition at line 161 of file analytic.hpp.

◆ reports_

analytic_reports reports_
protected

Definition at line 163 of file analytic.hpp.

◆ npvCubes_

analytic_npvcubes npvCubes_
protected

Definition at line 164 of file analytic.hpp.

◆ mktCubes_

analytic_mktcubes mktCubes_
protected

Definition at line 165 of file analytic.hpp.

◆ stressTests_

analytic_stresstests stressTests_
protected

Definition at line 166 of file analytic.hpp.

◆ writeIntermediateReports_

bool writeIntermediateReports_ = true
protected

Whether to write intermediate reports or not. This would typically be used when the analytic is being called by another analytic and that parent/calling analytic will be writing its own set of intermediate reports

Definition at line 171 of file analytic.hpp.