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

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

+ Inheritance diagram for PnlExplainAnalyticImpl:
+ Collaboration diagram for PnlExplainAnalyticImpl:

Public Member Functions

 PnlExplainAnalyticImpl (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
 
virtual void setUpConfigurations () override
 
- 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 = "PNL_EXPLAIN"
 
static constexpr const char * sensiLookupKey = "SENSI"
 
static constexpr const char * pnlLookupKey = "PNL"
 

Additional Inherited Members

- 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 33 of file pnlexplainanalytic.hpp.

Constructor & Destructor Documentation

◆ PnlExplainAnalyticImpl()

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

Definition at line 38 of file pnlexplainanalytic.hpp.

39 : Analytic::Impl(inputs) {
41
42 auto sensiAnalytic = AnalyticFactory::instance().build("SENSITIVITY", inputs_);
43 if (sensiAnalytic.second)
44 addDependentAnalytic(sensiLookupKey, sensiAnalytic.second);
45
46 auto pnlAnalytic = AnalyticFactory::instance().build("PNL", inputs_);
47 if (pnlAnalytic.second)
48 addDependentAnalytic(pnlLookupKey, pnlAnalytic.second);
49 }
void setLabel(const string &label)
Definition: analytic.hpp:189
void addDependentAnalytic(const std::string &key, const QuantLib::ext::shared_ptr< Analytic > &analytic)
Definition: analytic.hpp:209
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: analytic.hpp:216
static constexpr const char * sensiLookupKey
static constexpr const char * LABEL
static constexpr const char * pnlLookupKey
+ 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 42 of file pnlexplainanalytic.cpp.

43 {
44
45 CONSOLEW("PNL Explain: Build Market");
46 analytic()->buildMarket(loader);
47 CONSOLE("OK");
48
49 CONSOLEW("PNL Explain: Build Portfolio");
51 CONSOLE("OK");
52
53 auto pnlexplainAnalytic = static_cast<PnlExplainAnalytic*>(analytic());
54 QL_REQUIRE(pnlexplainAnalytic, "Analytic must be of type PnlExplainAnalytic");
55
56 auto pnlAnalytic = dependentAnalytic(pnlLookupKey);
57 pnlAnalytic->runAnalytic(loader);
58 auto pnlReport = pnlAnalytic->reports().at("PNL").at("pnl");
59
60 auto sensiAnalytic = dependentAnalytic(sensiLookupKey);
61
62 // Explicitily set the sensi threshold to 0.0 for sensi analysis, this ensures we get a felta entry for each gamma
63 // TODO: Pass the threshold into the sensi analytic
64 inputs_->setSensiThreshold(QuantLib::Null<QuantLib::Real>());
65 sensiAnalytic->runAnalytic(loader, {"SENSITIVITY"});
66
67 auto sensireport = sensiAnalytic->reports().at("SENSITIVITY").at("sensitivity");
68 analytic()->reports()[label_]["sensitivity"] = sensireport;
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);
71
72 auto sensiReports = sensiAnalytic->reports();
73
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());
77
78 // dates needed for scenarios
79 set<Date> pnlDates;
80 pnlDates.insert(inputs_->asof());
81 pnlDates.insert(inputs_->mporDate());
82 TimePeriod period({inputs_->asof(), inputs_->mporDate()});
83
84 QuantLib::ext::shared_ptr<HistoricalScenarioGenerator> scenarios;
85 if (!inputs_->historicalScenarioReader()) {
86
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();
91
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");
94
95 vector<QuantLib::ext::shared_ptr<ore::analytics::Scenario>> histScens = {t0Scenario, t1Scenario};
96
97 QuantLib::ext::shared_ptr<HistoricalScenarioLoader> scenarioLoader =
98 QuantLib::ext::make_shared<HistoricalScenarioLoader>(histScens, pnlDates);
99
100 scenarios = QuantLib::ext::make_shared<HistoricalScenarioGenerator>(
101 scenarioLoader, QuantLib::ext::make_shared<SimpleScenarioFactory>(), adjFactors,
102 ReturnConfiguration(), "hs_");
103 } else {
104 auto scenarios = buildHistoricalScenarioGenerator(inputs_->historicalScenarioReader(), adjFactors, pnlDates,
105 analytic()->configurations().simMarketParams,
106 analytic()->configurations().todaysMarketParams);
107 }
108
109 auto simMarket = QuantLib::ext::make_shared<ScenarioSimMarket>(
110 analytic()->market(), analytic()->configurations().simMarketParams, Market::defaultConfiguration,
111 *analytic()->configurations().curveConfig, *analytic()->configurations().todaysMarketParams, true, true,
112 false, false, *inputs_->iborFallbackConfig());
113 simMarket->scenarioGenerator() = scenarios;
114 scenarios->baseScenario() = simMarket->baseScenario();
115
116 ext::shared_ptr<ScenarioShiftCalculator> shiftCalculator = ext::make_shared<ScenarioShiftCalculator>(
117 analytic()->configurations().sensiScenarioData, analytic()->configurations().simMarketParams);
118
119 std::unique_ptr<MarketRiskReport::SensiRunArgs> sensiArgs =
120 std::make_unique<MarketRiskReport::SensiRunArgs>(ss, shiftCalculator);
121
122 auto pnlExplainReport =
123 ext::make_shared<PnlExplainReport>(inputs_->baseCurrency(), analytic()->portfolio(), inputs_->portfolioFilter(),
124 period, pnlReport, scenarios, std::move(sensiArgs), nullptr, nullptr, true);
125
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);
131
132 pnlExplainReport->calculate(reports);
133 analytic()->reports()[label_]["pnl"] = pnlReport;
134 analytic()->reports()[label_]["pnl_explain"] = pnlReport;
135}
Analytic * analytic() const
Definition: analytic.hpp:193
std::string label_
label for logging purposes primarily
Definition: analytic.hpp:219
QuantLib::ext::shared_ptr< T > dependentAnalytic(const std::string &key) const
Definition: analytic.hpp:251
analytic_reports & reports()
Result reports.
Definition: analytic.hpp:131
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
Definition: analytic.cpp:178
virtual void buildPortfolio()
Definition: analytic.cpp:222
static const string defaultConfiguration
#define LOG(text)
#define CONSOLEW(text)
#define CONSOLE(text)
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)
+ Here is the call graph for this function:

◆ setUpConfigurations()

void setUpConfigurations ( )
overridevirtual

Reimplemented from Analytic::Impl.

Definition at line 34 of file pnlexplainanalytic.cpp.

34 {
37 analytic()->configurations().todaysMarketParams = inputs_->todaysMarketParams();
38 analytic()->configurations().simMarketParams = inputs_->scenarioSimMarketParams();
39 analytic()->configurations().sensiScenarioData = inputs_->sensiScenarioData();
40}
Configurations & configurations()
Definition: analytic.hpp:128
QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > sensiScenarioData
Definition: analytic.hpp:70
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
Definition: analytic.hpp:68
bool simulationConfigRequired
Booleans to determine if these configs are needed.
Definition: analytic.hpp:64
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams
Definition: analytic.hpp:69
+ Here is the call graph for this function:

Member Data Documentation

◆ LABEL

constexpr const char* LABEL = "PNL_EXPLAIN"
staticconstexpr

Definition at line 35 of file pnlexplainanalytic.hpp.

◆ sensiLookupKey

constexpr const char* sensiLookupKey = "SENSI"
staticconstexpr

Definition at line 36 of file pnlexplainanalytic.hpp.

◆ pnlLookupKey

constexpr const char* pnlLookupKey = "PNL"
staticconstexpr

Definition at line 37 of file pnlexplainanalytic.hpp.