41#include <boost/timer/timer.hpp>
46using namespace boost::filesystem;
47using boost::timer::cpu_timer;
48using boost::timer::default_places;
54 const std::set<std::string>& analyticTypes,
55 const QuantLib::ext::shared_ptr<InputParameters>& inputs,
56 bool simulationConfig,
57 bool sensitivityConfig,
58 bool scenarioGeneratorConfig,
59 bool crossAssetModelConfig)
60 : impl_(std::move(impl)), types_(analyticTypes), inputs_(inputs) {
65 if (
inputs->curveConfigs().has())
67 if (
inputs->pricingEngine())
76 impl_->setAnalytic(
this);
77 impl_->setGenerateAdditionalResults(
inputs_->outputAdditionalResults());
84 const std::set<std::string>& runTypes) {
94 impl_->setUpConfigurations();
98 std::vector<QuantLib::ext::shared_ptr<Analytic>> analytics;
100 analytics.push_back(a);
101 auto das = a->allDependentAnalytics();
102 analytics.insert(end(analytics), begin(das), end(das));
108 auto it = dependentAnalytics_.find(key);
109 QL_REQUIRE(it != dependentAnalytics_.end(),
"Could not find dependent Analytic " << key);
119 if (runTypes.size() == 0)
122 for (
const auto& rt : runTypes) {
124 LOG(
"Requested analytics " <<
to_string(runTypes) <<
" match analytic class " <<
label());
132 return impl_->allDependentAnalytics();
136 std::set<QuantLib::Date> mds = {
inputs_->asof()};
137 auto addDates =
impl_->additionalMarketDates();
138 mds.insert(addDates.begin(), addDates.end());
140 for (
const auto& a :
impl_->dependentAnalytics()) {
141 addDates = a.second->impl()->additionalMarketDates();
142 mds.insert(addDates.begin(), addDates.end());
149 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> tmps;
153 for (
const auto& a :
impl_->dependentAnalytics()) {
154 auto ctmps = a.second->todaysMarketParams();
155 tmps.insert(end(tmps), begin(ctmps), end(ctmps));
162 LOG(
"Analytic::engineFactory() called");
165 QuantLib::ext::shared_ptr<EngineData> edCopy = QuantLib::ext::make_shared<EngineData>(*
inputs_->pricingEngine());
166 edCopy->globalParameters()[
"GenerateAdditionalResults"] =
to_string(generateAdditionalResults());
167 edCopy->globalParameters()[
"RunType"] =
"NPV";
172 LOG(
"MarketContext::pricing = " <<
inputs_->marketConfig(
"pricing"));
175 *
inputs_->iborFallbackConfig());
179 const bool marketRequired) {
180 LOG(
"Analytic::buildMarket called");
183 QL_REQUIRE(
loader,
"market data loader not set");
184 QL_REQUIRE(
configurations().curveConfig,
"curve configurations not set");
194 loader_ = QuantLib::ext::make_shared<CompositeLoader>(
loader, bondSpreads);
198 "There are no quotes available for date " <<
configurations().asofDate);
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) {
206 QL_FAIL(
"Failed to build market: " << e.what());
208 WLOG(
"Failed to build market: " << e.what());
211 ALOG(
"Skip building the market due to missing today's market parameters in configurations");
214 LOG(
"Market Build time " << setprecision(2) << mtimer.format(default_places,
"%w") <<
" sec");
226 portfolio_ = QuantLib::ext::make_shared<Portfolio>(
inputs()->buildFailedTrades());
230 for (
const auto& [tradeId, trade] : tmp->trades())
237 LOG(
"Build the portfolio");
238 QuantLib::ext::shared_ptr<EngineFactory> factory =
impl()->engineFactory();
242 Date maturityDate =
inputs()->asof();
243 if (
inputs()->portfolioFilterDate() != Null<Date>())
244 maturityDate =
inputs()->portfolioFilterDate();
246 LOG(
"Filter trades that expire before " << maturityDate);
247 portfolio()->removeMatured(maturityDate);
249 ALOG(
"Skip building the portfolio, because market not set");
258 analytic()->configurations().todaysMarketParams =
inputs_->todaysMarketParams();
262 const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>&
loader,
263 const std::set<std::string>& runTypes) {
265 Settings::instance().evaluationDate() =
inputs_->asof();
266 ObservationMode::instance().setMode(
inputs_->observationModel());
269 analytic()->buildMarket(
loader);
274 const QuantLib::ext::shared_ptr<ore::analytics::InputParameters>& params,
276 const QuantLib::ext::shared_ptr<Loader>&
loader,
277 const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigs,
278 const std::string& excludeRegex) {
283 if (!securities.empty()) {
285 QuantLib::ext::shared_ptr<Market>
market =
287 params->refDataManager(),
false, *params->iborFallbackConfig());
292 return QuantLib::ext::shared_ptr<Loader>();
a wrapper to buffer sensi stream records
std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > dependentAnalytics_
QuantLib::ext::shared_ptr< T > dependentAnalytic(const std::string &key) const
std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics() const
virtual QuantLib::ext::shared_ptr< ore::data::EngineFactory > engineFactory()
build an engine factory
std::set< QuantLib::Date > marketDates() const
Configurations & configurations()
virtual void marketCalibration(const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &mcr=nullptr)
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
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 vecto...
const std::unique_ptr< Impl > & impl()
const std::string label() const
Inspectors.
const QuantLib::ext::shared_ptr< InputParameters > & inputs() const
std::unique_ptr< Impl > impl_
std::set< std::string > types_
list of analytic types run by this analytic
QuantLib::ext::shared_ptr< ore::data::Portfolio > portfolio_
const QuantLib::ext::shared_ptr< ore::data::Portfolio > & portfolio() const
virtual void setUpConfigurations()
QuantLib::ext::shared_ptr< ore::data::Market > market_
const QuantLib::ext::shared_ptr< ore::data::Loader > & loader() const
virtual void replaceTrades()
const QuantLib::ext::shared_ptr< ore::data::Market > & market() const
std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics() const
Configurations configurations_
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams()
QuantLib::ext::shared_ptr< ore::data::Loader > loader_
QuantLib::ext::shared_ptr< InputParameters > inputs_
contains all the input parameters for the run
bool match(const std::set< std::string > &runTypes)
Check whether any of the requested run types is covered by this analytic.
virtual void buildPortfolio()
virtual void buildConfigurations(const bool=false)
void setUpConfigurations() override
void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
static QuantLib::ext::shared_ptr< Loader > implyBondSpreads(const std::map< std::string, QuantLib::ext::shared_ptr< Security > > &securities, const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager, const QuantLib::ext::shared_ptr< Market > &market, const QuantLib::ext::shared_ptr< EngineData > &engineData, const std::string &configuration, const IborFallbackConfig &iborFallbackConfig)
static std::map< std::string, QuantLib::ext::shared_ptr< Security > > requiredSecurities(const Date &asof, const QuantLib::ext::shared_ptr< TodaysMarketParameters > ¶ms, const QuantLib::ext::shared_ptr< CurveConfigurations > &curveConfigs, const Loader &loader, const bool continueOnError=false, const std::string &excludeRegex=std::string())
static const string defaultConfiguration
A Class to write a cube out to file.
Dynamic Initial Margin calculator by regression.
Class that wraps a sensitivity stream and filters out negligible records.
#define MEM_LOG_USING_LEVEL(LEVEL)
QuantLib::ext::shared_ptr< Loader > implyBondSpreads(const Date &asof, const QuantLib::ext::shared_ptr< ore::analytics::InputParameters > ¶ms, 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)
std::string to_string(const LocationInfo &l)
Singleton class to hold global Observation Mode.
A Class to write ORE outputs to reports.
factory classes for simple scenarios
bool sensitivityConfigRequired
bool crossAssetModelConfigRequired
QuantLib::ext::shared_ptr< ore::data::EngineData > engineData
QuantLib::ext::shared_ptr< CurveConfigurations > curveConfig
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
bool simulationConfigRequired
Booleans to determine if these configs are needed.
bool scenarioGeneratorConfigRequired
Class for structured analytics warnings.
vector< string > curveConfigs
Class for converting zero sensitivities to par sensitivities.