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();
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);
130 auto newAnalytic = ext::make_shared<XvaAnalytic>(
132 (
label ==
"BASE" ?
nullptr :
analytic()->configurations().simMarketParams));
133 CONSOLE(
"XVA_SENSITIVITY: Calculate Exposure and XVA")
134 newAnalytic->
runAnalytic(loader, {
"EXPOSURE",
"XVA"});
135
136 for (auto& [name, rpt] : newAnalytic->reports()["XVA"]) {
137
138 if (boost::starts_with(name, "exposure") || boost::starts_with(name, "xva")) {
139 DLOG(
"Save and extend report " << name);
141 }
142 }
143
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) {
153 if (report != nullptr) {
155 }
156 }
157}
const std::string & label() const
analytic_reports & reports()
Result reports.
void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
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)