43 const std::set<std::string>& runTypes) {
45 CONSOLEW(
"PNL Explain: Build Market");
49 CONSOLEW(
"PNL Explain: Build Portfolio");
54 QL_REQUIRE(pnlexplainAnalytic,
"Analytic must be of type PnlExplainAnalytic");
57 pnlAnalytic->runAnalytic(loader);
58 auto pnlReport = pnlAnalytic->reports().at(
"PNL").at(
"pnl");
64 inputs_->setSensiThreshold(QuantLib::Null<QuantLib::Real>());
65 sensiAnalytic->runAnalytic(loader, {
"SENSITIVITY"});
67 auto sensireport = sensiAnalytic->reports().at(
"SENSITIVITY").at(
"sensitivity");
69 ext::shared_ptr<SensitivityStream> ss = ext::make_shared<SensitivityReportStream>(sensiAnalytic->reports().at(
"SENSITIVITY").at(
"sensitivity"));
70 ss = ext::make_shared<FilteredSensitivityStream>(ss, 1e-6);
72 auto sensiReports = sensiAnalytic->reports();
74 QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors> adjFactors;
75 if (
auto adjLoader = QuantLib::ext::dynamic_pointer_cast<AdjustedInMemoryLoader>(loader))
76 adjFactors = QuantLib::ext::make_shared<ore::data::AdjustmentFactors>(adjLoader->adjustmentFactors());
80 pnlDates.insert(
inputs_->asof());
81 pnlDates.insert(
inputs_->mporDate());
84 QuantLib::ext::shared_ptr<HistoricalScenarioGenerator> scenarios;
85 if (!
inputs_->historicalScenarioReader()) {
87 auto pnlImpl =
static_cast<PnlAnalyticImpl*
>(pnlAnalytic->impl().get());
88 QL_REQUIRE(pnlImpl,
"Impl must of type PNLAnalyticImpl");
89 auto t0Scenario = pnlImpl->t0Scenario();
90 auto t1Scenario = pnlImpl->t1Scenario();
92 analytic()->
reports()[
label_][
"pnl_scenario_t0"] = pnlAnalytic->reports().at(
"PNL").at(
"pnl_scenario_t0");
93 analytic()->
reports()[
label_][
"pnl_scenario_t1"] = pnlAnalytic->reports().at(
"PNL").at(
"pnl_scenario_t1");
95 vector<QuantLib::ext::shared_ptr<ore::analytics::Scenario>> histScens = {t0Scenario, t1Scenario};
97 QuantLib::ext::shared_ptr<HistoricalScenarioLoader> scenarioLoader =
98 QuantLib::ext::make_shared<HistoricalScenarioLoader>(histScens, pnlDates);
100 scenarios = QuantLib::ext::make_shared<HistoricalScenarioGenerator>(
101 scenarioLoader, QuantLib::ext::make_shared<SimpleScenarioFactory>(), adjFactors,
105 analytic()->configurations().simMarketParams,
106 analytic()->configurations().todaysMarketParams);
109 auto simMarket = QuantLib::ext::make_shared<ScenarioSimMarket>(
111 *
analytic()->configurations().curveConfig, *
analytic()->configurations().todaysMarketParams,
true,
true,
112 false,
false, *
inputs_->iborFallbackConfig());
113 simMarket->scenarioGenerator() = scenarios;
114 scenarios->baseScenario() = simMarket->baseScenario();
116 ext::shared_ptr<ScenarioShiftCalculator> shiftCalculator = ext::make_shared<ScenarioShiftCalculator>(
117 analytic()->configurations().sensiScenarioData,
analytic()->configurations().simMarketParams);
119 std::unique_ptr<MarketRiskReport::SensiRunArgs> sensiArgs =
120 std::make_unique<MarketRiskReport::SensiRunArgs>(ss, shiftCalculator);
122 auto pnlExplainReport =
123 ext::make_shared<PnlExplainReport>(
inputs_->baseCurrency(),
analytic()->portfolio(),
inputs_->portfolioFilter(),
124 period, pnlReport, scenarios, std::move(sensiArgs),
nullptr,
nullptr,
true);
126 LOG(
"Call PNL Explain calculation");
127 CONSOLEW(
"Risk: PNL Explain Calculation");
128 ext::shared_ptr<MarketRiskReport::Reports> reports = ext::make_shared<MarketRiskReport::Reports>();
129 QuantLib::ext::shared_ptr<InMemoryReport> pnlExplainOutput = QuantLib::ext::make_shared<InMemoryReport>();
130 reports->add(pnlReport);
132 pnlExplainReport->calculate(reports);
Analytic * analytic() const
std::string label_
label for logging purposes primarily
QuantLib::ext::shared_ptr< T > dependentAnalytic(const std::string &key) const
QuantLib::ext::shared_ptr< InputParameters > inputs_
analytic_reports & reports()
Result reports.
Configurations & configurations()
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
virtual void buildPortfolio()
virtual void setUpConfigurations() override
static constexpr const char * sensiLookupKey
virtual void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
static constexpr const char * pnlLookupKey
Return type for historical scenario generation (absolute, relative, log)
static const string defaultConfiguration
Class that wraps a sensitivity stream and filters out negligible records.
QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > buildHistoricalScenarioGenerator(const QuantLib::ext::shared_ptr< HistoricalScenarioReader > &hsr, const QuantLib::ext::shared_ptr< ore::data::AdjustmentFactors > &adjFactors, const TimePeriod &period, Calendar calendar, Size mporDays, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &simParams, const QuantLib::ext::shared_ptr< TodaysMarketParameters > &marketParams, const bool overlapping)
Class for calculating the shift multiple between two scenarios for a given key.
Class for streaming SensitivityRecords from a report.
factory classes for simple scenarios
bool sensitivityConfigRequired
QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > sensiScenarioData
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
bool simulationConfigRequired
Booleans to determine if these configs are needed.
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams