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

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

+ Inheritance diagram for XvaSensitivityAnalyticImpl:
+ Collaboration diagram for XvaSensitivityAnalyticImpl:

Public Member Functions

 XvaSensitivityAnalyticImpl (const QuantLib::ext::shared_ptr< InputParameters > &inputs)
 
void runAnalytic (const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
 
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 = "XVA_SENSITIVITY"
 

Private Member Functions

void runSensitivity (const QuantLib::ext::shared_ptr< SensitivityScenarioGenerator > &scenarioGenerator, const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader)
 

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 32 of file xvasensitivityanalytic.hpp.

Constructor & Destructor Documentation

◆ XvaSensitivityAnalyticImpl()

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

Definition at line 32 of file xvasensitivityanalytic.cpp.

33 : Analytic::Impl(inputs) {
35}
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 37 of file xvasensitivityanalytic.cpp.

38 {
39
40 // basic setup
41
42 LOG("Running XVA_SENSITIVITY analytic.");
43
44 Settings::instance().evaluationDate() = inputs_->asof();
45
46 QL_REQUIRE(inputs_->portfolio(), "XvaSensitivityAnalytic::run: No portfolio loaded.");
47
48 Settings::instance().evaluationDate() = inputs_->asof();
49 std::string marketConfig = inputs_->marketConfig("pricing"); // FIXME
50
51 auto xvaAnalytic = dependentAnalytic<XvaAnalytic>("XVA");
52
53 // build t0, sim market, stress scenario generator
54
55 CONSOLEW("XVA_SENSI: Build T0 and Sim Markets and Stress Scenario Generator");
56
57 analytic()->buildMarket(loader);
58
59 LOG("XvaSensitivityAnalytic: Build SimMarket")
60 auto simMarket = QuantLib::ext::make_shared<ScenarioSimMarket>(
61 analytic()->market(), analytic()->configurations().simMarketParams, marketConfig,
62 *analytic()->configurations().curveConfig, *analytic()->configurations().todaysMarketParams,
63 inputs_->continueOnError(), analytic()->configurations().sensiScenarioData->useSpreadedTermStructures(), false,
64 false, *inputs_->iborFallbackConfig(), true);
65
66 LOG("XvaSensitivityAnalytic: Build SensitivityScenarioGenerator")
67
68 auto baseScenario = simMarket->baseScenario();
69 auto scenarioFactory = QuantLib::ext::make_shared<CloneScenarioFactory>(baseScenario);
70 auto scenarioGenerator = QuantLib::ext::make_shared<SensitivityScenarioGenerator>(
71 analytic()->configurations().sensiScenarioData, baseScenario, analytic()->configurations().simMarketParams,
72 simMarket, scenarioFactory, false);
73 simMarket->scenarioGenerator() = scenarioGenerator;
74
75 CONSOLE("OK");
76
77 // generate the stress scenarios and run dependent xva analytic under each of them
78
79 CONSOLE("XVA_SENSI: Running sensi scenarios");
80
81 // run stress test
82 LOG("Run XVA Sensitivity")
83 runSensitivity(scenarioGenerator, loader);
84
85 LOG("Running XVA Sensitivity analytic finished.");
86}
Analytic * analytic() const
Definition: analytic.hpp:193
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: analytic.hpp:216
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
Definition: analytic.cpp:178
void runSensitivity(const QuantLib::ext::shared_ptr< SensitivityScenarioGenerator > &scenarioGenerator, const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader)
#define LOG(text)
#define CONSOLEW(text)
+ Here is the call graph for this function:

◆ setUpConfigurations()

void setUpConfigurations ( )
overridevirtual

Reimplemented from Analytic::Impl.

Definition at line 159 of file xvasensitivityanalytic.cpp.

159 {
160 analytic()->configurations().todaysMarketParams = inputs_->todaysMarketParams();
161 analytic()->configurations().simMarketParams = inputs_->xvaSensiSimMarketParams();
162 analytic()->configurations().sensiScenarioData = inputs_->xvaSensiScenarioData();
163}
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
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams
Definition: analytic.hpp:69
+ Here is the call graph for this function:

◆ runSensitivity()

void runSensitivity ( const QuantLib::ext::shared_ptr< SensitivityScenarioGenerator > &  scenarioGenerator,
const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &  loader 
)
private

Definition at line 88 of file xvasensitivityanalytic.cpp.

90 {
91
92 std::map<std::string, std::vector<QuantLib::ext::shared_ptr<ore::data::InMemoryReport>>> xvaReports;
93 for (size_t i = 0; i < scenarioGenerator->samples(); ++i) {
94 auto scenario = scenarioGenerator->next(inputs_->asof());
95 auto desc = scenarioGenerator->scenarioDescriptions()[i];
96 const auto label = scenario->label();
97 QuantLib::ext::shared_ptr<ore::data::InMemoryReport> descReport =
98 QuantLib::ext::make_shared<ore::data::InMemoryReport>();
99
100 double shiftSize1 = 0.0;
101 auto itShiftSize1 = scenarioGenerator->shiftSizes().find(desc.key1());
102 if (itShiftSize1 != scenarioGenerator->shiftSizes().end()){
103 shiftSize1 = (itShiftSize1->second);
104 }
105 double shiftSize2 = 0.0;
106 auto itShiftSize2 = scenarioGenerator->shiftSizes().find(desc.key2());
107 if (itShiftSize2 != scenarioGenerator->shiftSizes().end()) {
108 shiftSize2 = (itShiftSize2->second);
109 }
110 descReport->addColumn("Type", string());
111 descReport->addColumn("IsPar", string());
112 descReport->addColumn("Factor_1", string());
113 descReport->addColumn("ShiftSize_1", double(), 8);
114 descReport->addColumn("Factor_2", string());
115 descReport->addColumn("ShiftSize_2", double(), 8);
116 descReport->addColumn("Currency", string());
117 descReport->next();
118 descReport->add(ore::data::to_string(desc.type()));
119 descReport->add("false");
120 descReport->add(desc.factor1());
121 descReport->add(shiftSize1);
122 descReport->add(desc.factor2());
123 descReport->add(shiftSize2);
124 descReport->add(inputs_->baseCurrency());
125 descReport->end();
126
127 try {
128 DLOG("Calculate XVA for scenario " << label);
129 CONSOLE("XVA_SENSITIVITY: Apply scenario " << label);
130 auto newAnalytic = ext::make_shared<XvaAnalytic>(
131 inputs_, (label == "BASE" ? nullptr : scenario),
132 (label == "BASE" ? nullptr : analytic()->configurations().simMarketParams));
133 CONSOLE("XVA_SENSITIVITY: Calculate Exposure and XVA")
134 newAnalytic->runAnalytic(loader, {"EXPOSURE", "XVA"});
135 // Collect exposure and xva reports
136 for (auto& [name, rpt] : newAnalytic->reports()["XVA"]) {
137 // add scenario column to report and copy it, concat it later
138 if (boost::starts_with(name, "exposure") || boost::starts_with(name, "xva")) {
139 DLOG("Save and extend report " << name);
140 xvaReports[name].push_back(addColumnsToExisitingReport(descReport, rpt));
141 }
142 }
143 // writeCubes(label, newAnalytic);
144 } catch (const std::exception& e) {
145 StructuredAnalyticsErrorMessage("XvaSensitivity", "XVACalc",
146 "Error during XVA calc under scenario " + label + ", got " + e.what() +
147 ". Skip it")
148 .log();
149 }
150 }
151 for (auto& [name, reports] : xvaReports) {
152 auto report = concatenateReports(reports);
153 if (report != nullptr) {
154 analytic()->reports()[label()][name] = report;
155 }
156 }
157}
const std::string & label() const
Definition: analytic.hpp:190
analytic_reports & reports()
Result reports.
Definition: analytic.hpp:131
void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
#define DLOG(text)
#define CONSOLE(text)
std::string to_string(const LocationInfo &l)
QuantLib::ext::shared_ptr< ore::data::InMemoryReport > concatenateReports(const std::vector< QuantLib::ext::shared_ptr< ore::data::InMemoryReport > > &reports)
QuantLib::ext::shared_ptr< ore::data::InMemoryReport > addColumnsToExisitingReport(const QuantLib::ext::shared_ptr< ore::data::InMemoryReport > &newColsReport, const QuantLib::ext::shared_ptr< ore::data::InMemoryReport > &report)
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ LABEL

constexpr const char* LABEL = "XVA_SENSITIVITY"
staticconstexpr

Definition at line 34 of file xvasensitivityanalytic.hpp.