29using namespace boost::filesystem;
30using namespace QuantLib::ext;
44 const std::set<std::string>& runTypes) {
46 LOG(
"Running parametric VaR");
48 Settings::instance().evaluationDate() =
inputs_->asof();
49 ObservationMode::instance().setMode(
inputs_->observationModel());
51 LOG(
"VAR: Build Market");
52 CONSOLEW(
"Risk: Build Market for VaR");
56 CONSOLEW(
"Risk: Build Portfolio for VaR");
61 QL_REQUIRE(
varReport_,
"No Var Report created");
63 LOG(
"Call VaR calculation");
65 ext::shared_ptr<MarketRiskReport::Reports> reports = ext::make_shared<MarketRiskReport::Reports>();
66 QuantLib::ext::shared_ptr<InMemoryReport> varReport = QuantLib::ext::make_shared<InMemoryReport>();
67 reports->add(varReport);
80 if (
inputs_->covarianceData().size() == 0) {
87 LOG(
"Build trade to portfolio id mapping");
91 QuantLib::ext::shared_ptr<SensitivityStream> ss =
sensiStream(loader);
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());
98 varReport_ = ext::make_shared<ParametricVarReport>(
101 inputs_->salvageCovariance(), boost::none, std::move(sensiArgs),
inputs_->varBreakDown());
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());
111 benchmarkVarPeriod,
inputs_->mporCalendar(),
inputs_->mporDays(),
analytic()->configurations().simMarketParams,
112 analytic()->configurations().todaysMarketParams,
inputs_->mporOverlappingPeriods());
114 if (
inputs_->outputHistoricalScenarios())
116 scenarios->scenarioLoader(),
117 QuantLib::ext::make_shared<CSVFileReport>(path(
inputs_->resultsPath() /
"backtest_histscenrios.csv").string(),
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();
127 QuantLib::ext::shared_ptr<ScenarioShiftCalculator> shiftCalculator = QuantLib::ext::make_shared<ScenarioShiftCalculator>(
128 analytic()->configurations().sensiScenarioData,
analytic()->configurations().simMarketParams);
130 std::unique_ptr<MarketRiskReport::SensiRunArgs> sensiArgs =
131 std::make_unique<MarketRiskReport::SensiRunArgs>(ss, shiftCalculator, 0.01,
inputs_->covarianceData());
133 varReport_ = ext::make_shared<ParametricVarReport>(
135 inputs_->varQuantiles(), varParams,
136 inputs_->salvageCovariance(), benchmarkVarPeriod, std::move(sensiArgs),
inputs_->varBreakDown());
146 const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader) {
148 LOG(
"Build VaR calculator");
151 QuantLib::ext::shared_ptr<ore::data::AdjustmentFactors> adjFactors;
152 if (
auto adjLoader = QuantLib::ext::dynamic_pointer_cast<AdjustedInMemoryLoader>(loader))
153 adjFactors = QuantLib::ext::make_shared<ore::data::AdjustmentFactors>(adjLoader->adjustmentFactors());
158 analytic()->configurations().todaysMarketParams,
inputs_->mporOverlappingPeriods());
160 if (
inputs_->outputHistoricalScenarios())
162 scenarios->scenarioLoader(),
163 QuantLib::ext::make_shared<CSVFileReport>(path(
inputs_->resultsPath() /
"var_histscenarios.csv").string(),
',',
166 auto simMarket = QuantLib::ext::make_shared<ScenarioSimMarket>(
168 *
analytic()->configurations().curveConfig, *
analytic()->configurations().todaysMarketParams,
true,
false,
false,
169 false, *
inputs_->iborFallbackConfig());
170 simMarket->scenarioGenerator() = scenarios;
171 scenarios->baseScenario() = simMarket->baseScenario();
173 std::unique_ptr<MarketRiskReport::FullRevalArgs> fullRevalArgs = std::make_unique<MarketRiskReport::FullRevalArgs>(
176 varReport_ = ext::make_shared<HistoricalSimulationVarReport>(
178 inputs_->varQuantiles(), benchmarkVarPeriod, scenarios, std::move(fullRevalArgs),
inputs_->varBreakDown());
Analytic * analytic() const
std::string label_
label for logging purposes primarily
QuantLib::ext::shared_ptr< InputParameters > inputs_
analytic_reports & reports()
Result reports.
Configurations & configurations()
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
virtual void buildPortfolio()
void setUpConfigurations() override
void setVarReport(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader) override
virtual void setUpConfigurations() override
virtual QuantLib::ext::shared_ptr< SensitivityStream > sensiStream(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader)
void setVarReport(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader) override
Write ORE outputs to reports.
void writeHistoricalScenarios(const QuantLib::ext::shared_ptr< HistoricalScenarioLoader > &hsloader, const QuantLib::ext::shared_ptr< ore::data::Report > &report)
virtual void setUpConfigurations() override
virtual void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
virtual void setVarReport(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader)
QuantLib::ext::shared_ptr< VarReport > varReport_
static const string defaultConfiguration
Date parseDate(const string &s)
Perform historical simulation var calculation for a given portfolio.
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)
Singleton class to hold global Observation Mode.
Perform parametric var calculation for a given portfolio.
A Class to write ORE outputs to reports.
QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > sensiScenarioData
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams
A container for holding the parametric VAR parameters.