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

#include <orea/app/analytics/scenariostatisticsanalytic.hpp>

+ Inheritance diagram for ScenarioStatisticsAnalyticImpl:
+ Collaboration diagram for ScenarioStatisticsAnalyticImpl:

Public Member Functions

 ScenarioStatisticsAnalyticImpl (const QuantLib::ext::shared_ptr< InputParameters > &inputs)
 
virtual void runAnalytic (const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
 
void setUpConfigurations () override
 
QuantLib::ext::shared_ptr< ScenarioGeneratorscenarioGenerator ()
 
- Public Member Functions inherited from Analytic::Impl
 Impl ()
 
 Impl (const QuantLib::ext::shared_ptr< InputParameters > &inputs)
 
virtual ~Impl ()
 
virtual void runAnalytic (const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={})=0
 
virtual void setUpConfigurations ()
 
virtual QuantLib::ext::shared_ptr< ore::data::EngineFactoryengineFactory ()
 build an engine factory More...
 
void setLabel (const string &label)
 
const std::string & label () const
 
void setAnalytic (Analytic *analytic)
 
Analyticanalytic () const
 
void setInputs (const QuantLib::ext::shared_ptr< InputParameters > &inputs)
 
bool generateAdditionalResults () const
 
void setGenerateAdditionalResults (const bool generateAdditionalResults)
 
bool hasDependentAnalytic (const std::string &key)
 
template<class T >
QuantLib::ext::shared_ptr< T > dependentAnalytic (const std::string &key) const
 
QuantLib::ext::shared_ptr< AnalyticdependentAnalytic (const std::string &key) const
 
const std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > & dependentAnalytics () const
 
void addDependentAnalytic (const std::string &key, const QuantLib::ext::shared_ptr< Analytic > &analytic)
 
std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics () const
 
virtual std::vector< QuantLib::Date > additionalMarketDates () const
 

Static Public Attributes

static constexpr const char * LABEL = "SCENARIO_STATISTICS"
 

Protected Member Functions

void buildScenarioSimMarket ()
 
void buildCrossAssetModel (bool continueOnError)
 
void buildScenarioGenerator (bool continueOnError)
 

Protected Attributes

QuantLib::ext::shared_ptr< ScenarioSimMarketsimMarket_
 
QuantLib::ext::shared_ptr< CrossAssetModelmodel_
 
QuantLib::ext::shared_ptr< ScenarioGeneratorscenarioGenerator_
 
QuantLib::ext::shared_ptr< DateGridgrid_
 
Size samples_ = 0
 
- Protected Attributes inherited from Analytic::Impl
QuantLib::ext::shared_ptr< InputParametersinputs_
 
std::string label_
 label for logging purposes primarily More...
 
std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > dependentAnalytics_
 

Detailed Description

Definition at line 30 of file scenariostatisticsanalytic.hpp.

Constructor & Destructor Documentation

◆ ScenarioStatisticsAnalyticImpl()

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

Definition at line 34 of file scenariostatisticsanalytic.hpp.

34: Analytic::Impl(inputs) { setLabel(LABEL); }
void setLabel(const string &label)
Definition: analytic.hpp:189
+ Here is the call graph for this function:

Member Function Documentation

◆ runAnalytic()

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

Implements Analytic::Impl.

Definition at line 100 of file scenariostatisticsanalytic.cpp.

101 {
102
103 LOG("Scenario analytic called with asof " << io::iso_date(inputs_->asof()));
104
105 Settings::instance().evaluationDate() = inputs_->asof();
106 //ObservationMode::instance().setMode(inputs_->exposureObservationModel());
107
108 LOG("SCENARIO_STATISTICS: Build Today's Market");
109 CONSOLEW("SCENARIO_STATISTICS: Build Market");
110 analytic()->buildMarket(loader);
111 CONSOLE("OK");
112
114
115 LOG("SCENARIO_STATISTICS: Build simulation market");
117
118 LOG("SCENARIO_STATISTICS: Build Scenario Generator");
119 auto globalParams = inputs_->simulationPricingEngine()->globalParameters();
120 auto continueOnCalErr = globalParams.find("ContinueOnCalibrationError");
121 bool continueOnErr = (continueOnCalErr != globalParams.end()) && parseBool(continueOnCalErr->second);
122 buildScenarioGenerator(continueOnErr);
123
124 LOG("SCENARIO_STATISTICS: Attach Scenario Generator to ScenarioSimMarket");
125 simMarket_->scenarioGenerator() = scenarioGenerator_;
126
127 MEM_LOG;
128
129 // Output scenario statistics and distribution reports
130 const vector<RiskFactorKey>& keys = simMarket_->baseScenario()->keys();
131 QuantLib::ext::shared_ptr<ScenarioGenerator> scenarioGenerator =
132 inputs_->scenarioOutputZeroRate()
133 ? QuantLib::ext::make_shared<ScenarioGeneratorTransform>(scenarioGenerator_, simMarket_,
134 analytic()->configurations().simMarketParams)
136
137 auto statsReport = QuantLib::ext::make_shared<InMemoryReport>();
138 scenarioGenerator->reset();
139 ReportWriter().writeScenarioStatistics(scenarioGenerator, keys, samples_, grid_->valuationDates(),
140 *statsReport);
141 analytic()->reports()["SCENARIO_STATISTICS"]["scenario_statistics"] = statsReport;
142
143 auto distributionReport = QuantLib::ext::make_shared<InMemoryReport>();
144 scenarioGenerator->reset();
145 ReportWriter().writeScenarioDistributions(scenarioGenerator, keys, samples_, grid_->valuationDates(),
146 inputs_->scenarioDistributionSteps(), *distributionReport);
147 analytic()->reports()["SCENARIO_STATISTICS"]["scenario_distribution"] = distributionReport;
148}
Analytic * analytic() const
Definition: analytic.hpp:193
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: analytic.hpp:216
analytic_reports & reports()
Result reports.
Definition: analytic.hpp:131
Configurations & configurations()
Definition: analytic.hpp:128
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
Definition: analytic.cpp:178
QuantLib::ext::shared_ptr< ScenarioGenerator > scenarioGenerator()
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
QuantLib::ext::shared_ptr< ScenarioGenerator > scenarioGenerator_
bool parseBool(const string &s)
#define MEM_LOG
#define LOG(text)
#define CONSOLEW(text)
#define CONSOLE(text)
QuantLib::ext::shared_ptr< ore::analytics::ScenarioGeneratorData > scenarioGeneratorData
Definition: analytic.hpp:71
+ Here is the call graph for this function:

◆ setUpConfigurations()

void setUpConfigurations ( )
overridevirtual

Reimplemented from Analytic::Impl.

Definition at line 41 of file scenariostatisticsanalytic.cpp.

41 {
42 LOG("ScenarioStatisticsAnalytic::setUpConfigurations() called");
43 analytic()->configurations().todaysMarketParams = inputs_->todaysMarketParams();
44 analytic()->configurations().simMarketParams = inputs_->exposureSimMarketParams();
45 analytic()->configurations().scenarioGeneratorData = inputs_->scenarioGeneratorData();
46 analytic()->configurations().crossAssetModelData = inputs_->crossAssetModelData();
47}
QuantLib::ext::shared_ptr< ore::analytics::CrossAssetModelData > crossAssetModelData
Definition: analytic.hpp:72
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
Definition: analytic.hpp:68
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams
Definition: analytic.hpp:69
+ Here is the call graph for this function:

◆ scenarioGenerator()

QuantLib::ext::shared_ptr< ScenarioGenerator > scenarioGenerator ( )

Definition at line 39 of file scenariostatisticsanalytic.hpp.

39{ return scenarioGenerator_; }
+ Here is the caller graph for this function:

◆ buildScenarioSimMarket()

void buildScenarioSimMarket ( )
protected

Definition at line 49 of file scenariostatisticsanalytic.cpp.

49 {
50
51 std::string configuration = inputs_->marketConfig("simulation");
52 simMarket_ = QuantLib::ext::make_shared<ScenarioSimMarket>(
53 analytic()->market(),
54 analytic()->configurations().simMarketParams,
55 QuantLib::ext::make_shared<FixingManager>(inputs_->asof()),
56 configuration,
57 *inputs_->curveConfigs().get(),
58 *analytic()->configurations().todaysMarketParams,
59 inputs_->continueOnError(),
60 false, true, false,
61 *inputs_->iborFallbackConfig(),
62 false);
63}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildCrossAssetModel()

void buildCrossAssetModel ( bool  continueOnError)
protected

Definition at line 87 of file scenariostatisticsanalytic.cpp.

87 {
88 LOG("SCENARIO_STATISTICS: Build Simulation Model (continueOnCalibrationError = "
89 << std::boolalpha << continueOnCalibrationError << ")");
90 CrossAssetModelBuilder modelBuilder(
91 analytic()->market(), analytic()->configurations().crossAssetModelData, inputs_->marketConfig("lgmcalibration"),
92 inputs_->marketConfig("fxcalibration"), inputs_->marketConfig("eqcalibration"),
93 inputs_->marketConfig("infcalibration"), inputs_->marketConfig("crcalibration"),
94 inputs_->marketConfig("simulation"), false, continueOnCalibrationError, "",
95 inputs_->salvageCorrelationMatrix() ? SalvagingAlgorithm::Spectral : SalvagingAlgorithm::None,
96 "xva cam building");
97 model_ = *modelBuilder.model();
98}
QuantLib::ext::shared_ptr< CrossAssetModel > model_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildScenarioGenerator()

void buildScenarioGenerator ( bool  continueOnError)
protected

Definition at line 65 of file scenariostatisticsanalytic.cpp.

65 {
66 if (!model_)
67 buildCrossAssetModel(continueOnCalibrationError);
68 ScenarioGeneratorBuilder sgb(analytic()->configurations().scenarioGeneratorData);
69 QuantLib::ext::shared_ptr<ScenarioFactory> sf = QuantLib::ext::make_shared<SimpleScenarioFactory>(true);
70 string config = inputs_->marketConfig("simulation");
71 scenarioGenerator_ = sgb.build(model_, sf, analytic()->configurations().simMarketParams, inputs_->asof(), analytic()->market(), config);
72 QL_REQUIRE(scenarioGenerator_, "failed to build the scenario generator");
74 LOG("simulation grid size " << grid_->size());
75 LOG("simulation grid valuation dates " << grid_->valuationDates().size());
76 LOG("simulation grid close-out dates " << grid_->closeOutDates().size());
77 LOG("simulation grid front date " << io::iso_date(grid_->dates().front()));
78 LOG("simulation grid back date " << io::iso_date(grid_->dates().back()));
79
80 if (inputs_->writeScenarios()) {
81 auto report = QuantLib::ext::make_shared<InMemoryReport>();
82 analytic()->reports()["SCENARIO_STATISTICS"]["scenario"] = report;
83 scenarioGenerator_ = QuantLib::ext::make_shared<ScenarioWriter>(scenarioGenerator_, report);
84 }
85}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ LABEL

constexpr const char* LABEL = "SCENARIO_STATISTICS"
staticconstexpr

Definition at line 32 of file scenariostatisticsanalytic.hpp.

◆ simMarket_

QuantLib::ext::shared_ptr<ScenarioSimMarket> simMarket_
protected

Definition at line 46 of file scenariostatisticsanalytic.hpp.

◆ model_

QuantLib::ext::shared_ptr<CrossAssetModel> model_
protected

Definition at line 47 of file scenariostatisticsanalytic.hpp.

◆ scenarioGenerator_

QuantLib::ext::shared_ptr<ScenarioGenerator> scenarioGenerator_
protected

Definition at line 48 of file scenariostatisticsanalytic.hpp.

◆ grid_

QuantLib::ext::shared_ptr<DateGrid> grid_
protected

Definition at line 50 of file scenariostatisticsanalytic.hpp.

◆ samples_

Size samples_ = 0
protected

Definition at line 51 of file scenariostatisticsanalytic.hpp.