84 {
85
86
87
88 LOG(
"Running XVA Stress analytic.");
89
90 Settings::instance().evaluationDate() =
inputs_->asof();
91
92 QL_REQUIRE(
inputs_->portfolio(),
"XvaStressAnalytic::run: No portfolio loaded.");
93
94 Settings::instance().evaluationDate() =
inputs_->asof();
95 std::string marketConfig =
inputs_->marketConfig(
"pricing");
96
97 auto xvaAnalytic = dependentAnalytic<XvaAnalytic>("XVA");
98
99
100
101 CONSOLEW(
"XVA_STRESS: Build T0 and Sim Markets and Stress Scenario Generator");
102
104
105 QuantLib::ext::shared_ptr<StressTestScenarioData> scenarioData =
inputs_->xvaStressScenarioData();
106 if (scenarioData != nullptr && scenarioData->hasScenarioWithParShifts()) {
107 try {
108 ParStressTestConverter converter(
110 analytic()->configurations().simMarketParams,
analytic()->configurations().sensiScenarioData,
112 scenarioData = converter.convertStressScenarioData(scenarioData);
114 } catch (const std::exception& e) {
115 scenarioData =
inputs_->xvaStressScenarioData();
116 StructuredAnalyticsErrorMessage(
label(),
"ParConversionFailed", e.what()).log();
117 }
118 }
119
120 LOG(
"XVA Stress: Build SimMarket and StressTestScenarioGenerator")
121 auto simMarket =
QuantLib::ext::make_shared<ScenarioSimMarket>(
122 analytic()->market(),
analytic()->configurations().simMarketParams, marketConfig,
123 *
analytic()->configurations().curveConfig, *
analytic()->configurations().todaysMarketParams,
124 inputs_->continueOnError(), scenarioData->useSpreadedTermStructures(), false, false,
125 *
inputs_->iborFallbackConfig(), true);
126
127 auto baseScenario = simMarket->baseScenario();
128 auto scenarioFactory =
QuantLib::ext::make_shared<CloneScenarioFactory>(baseScenario);
129 auto scenarioGenerator =
QuantLib::ext::make_shared<StressScenarioGenerator>(
130 scenarioData, baseScenario,
analytic()->configurations().simMarketParams, simMarket, scenarioFactory,
131 simMarket->baseScenarioAbsolute());
132 simMarket->scenarioGenerator() = scenarioGenerator;
133
134 CONSOLE("OK");
135
136
137
138 CONSOLE("XVA_STRESS: Running stress scenarios");
139
140
141 LOG("Run XVA Stresstest")
143
144 LOG("Running XVA Stress
analytic finished.");
145}
Analytic * analytic() const
const std::string & label() const
QuantLib::ext::shared_ptr< InputParameters > inputs_
analytic_stresstests & stressTests()
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
void runStressTest(const QuantLib::ext::shared_ptr< ore::analytics::StressScenarioGenerator > &scenarioGenerator, const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader)