86 {
87 LOG(
"Build trade to portfolio id mapping");
88 ParametricVarCalculator::ParametricVarParams varParams(
inputs_->varMethod(),
inputs_->mcVarSamples(),
90
91 QuantLib::ext::shared_ptr<SensitivityStream> ss =
sensiStream(loader);
92
93 LOG(
"Build VaR calculator");
94 if (
inputs_->covarianceData().size() > 0) {
95 std::unique_ptr<MarketRiskReport::SensiRunArgs> sensiArgs =
96 std::make_unique<MarketRiskReport::SensiRunArgs>(ss,
nullptr, 0.01,
inputs_->covarianceData());
97
98 varReport_ = ext::make_shared<ParametricVarReport>(
100 varParams,
101 inputs_->salvageCovariance(), boost::none, std::move(sensiArgs),
inputs_->varBreakDown());
102 } else {
103 TimePeriod benchmarkVarPeriod(parseListOfValues<Date>(
inputs_->benchmarkVarPeriod(), &parseDate),
105
106 QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors> adjFactors;
107 if (auto adjLoader = QuantLib::ext::dynamic_pointer_cast<AdjustedInMemoryLoader>(loader))
108 adjFactors = QuantLib::ext::make_shared<ore::data::AdjustmentFactors>(adjLoader->adjustmentFactors());
109
111 benchmarkVarPeriod,
inputs_->mporCalendar(),
inputs_->mporDays(),
analytic()->configurations().simMarketParams,
112 analytic()->configurations().todaysMarketParams,
inputs_->mporOverlappingPeriods());
113
114 if (
inputs_->outputHistoricalScenarios())
115 ReportWriter().writeHistoricalScenarios(
116 scenarios->scenarioLoader(),
117 QuantLib::ext::make_shared<CSVFileReport>(path(
inputs_->resultsPath() /
"backtest_histscenrios.csv").string(),
119
120 auto simMarket = QuantLib::ext::make_shared<ScenarioSimMarket>(
122 *
analytic()->configurations().curveConfig, *
analytic()->configurations().todaysMarketParams,
true,
false,
123 false,
false, *
inputs_->iborFallbackConfig());
124 simMarket->scenarioGenerator() = scenarios;
125 scenarios->baseScenario() = simMarket->baseScenario();
126
127 QuantLib::ext::shared_ptr<ScenarioShiftCalculator> shiftCalculator = QuantLib::ext::make_shared<ScenarioShiftCalculator>(
128 analytic()->configurations().sensiScenarioData,
analytic()->configurations().simMarketParams);
129
130 std::unique_ptr<MarketRiskReport::SensiRunArgs> sensiArgs =
131 std::make_unique<MarketRiskReport::SensiRunArgs>(ss, shiftCalculator, 0.01,
inputs_->covarianceData());
132
133 varReport_ = ext::make_shared<ParametricVarReport>(
135 inputs_->varQuantiles(), varParams,
136 inputs_->salvageCovariance(), benchmarkVarPeriod, std::move(sensiArgs),
inputs_->varBreakDown());
137 }
138}
virtual QuantLib::ext::shared_ptr< SensitivityStream > sensiStream(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader)
QuantLib::ext::shared_ptr< VarReport > varReport_
static const string defaultConfiguration
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)