25#pragma warning(disable : 4503)
45#include <ql/cashflows/floatingratecoupon.hpp>
46#include <ql/time/calendars/all.hpp>
47#include <ql/time/daycounters/all.hpp>
49#include <boost/algorithm/string.hpp>
50#include <boost/filesystem.hpp>
51#include <boost/timer/timer.hpp>
58using boost::timer::cpu_timer;
59using boost::timer::default_places;
65 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
70 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
75 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
80 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
81 std::set<std::string> names;
83 for (
auto b : rep.second) {
84 string reportName = b.first;
85 if (names.find(reportName) == names.end())
86 names.insert(reportName);
88 ALOG(
"report name " << reportName
89 <<
" occurs more than once, will retrieve the first report with that only");
97 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
99 for (
auto b : rep.second) {
100 if (reportName == b.first)
101 return QuantLib::ext::make_shared<PlainInMemoryReport>(b.second);
104 QL_FAIL(
"report " << reportName <<
" not found in results");
108 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
109 std::set<std::string> names;
111 for (
auto b : c.second) {
112 string cubeName = b.first;
113 if (names.find(cubeName) == names.end())
114 names.insert(cubeName);
116 ALOG(
"cube name " << cubeName
117 <<
" occurs more than once, will retrieve the first cube with that name only");
125 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
127 for (
auto b : c.second) {
128 if (cubeName == b.first)
132 QL_FAIL(
"npv cube " << cubeName <<
" not found in results");
136 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
137 std::set<std::string> names;
139 for (
auto b : c.second) {
140 string cubeName = b.first;
141 if (names.find(cubeName) == names.end())
142 names.insert(cubeName);
144 ALOG(
"market cube name " << cubeName
145 <<
" occurs more than once, will retrieve the first cube with that name only");
153 QL_REQUIRE(
analyticsManager_,
"analyticsManager_ not set yet, call analytics first");
155 for (
auto b : c.second) {
156 if (cubeName == b.first)
160 QL_FAIL(
"market cube " << cubeName <<
" not found in results");
168 boost::chrono::duration<double> seconds = boost::chrono::nanoseconds(
runTimer_.elapsed().wall);
169 return seconds.count();
173 bool implyTodaysFixings =
false;
174 vector<string> marketFiles = {};
175 vector<string> fixingFiles = {};
176 vector<string> dividendFiles = {};
178 filesystem::path inputPath =
params_->get(
"setup",
"inputPath");
180 std::string tmp =
params_->get(
"setup",
"implyTodaysFixings",
false);
184 tmp = params->get(
"setup",
"marketDataFile",
false);
188 ALOG(
"market data file not found");
191 tmp = params->get(
"setup",
"fixingDataFile",
false);
195 ALOG(
"fixing data file not found");
198 tmp = params->get(
"setup",
"dividendDataFile",
false);
202 WLOG(
"dividend data file not found");
205 tmp = params->get(
"setup",
"fixingCutoff",
false);
206 Date cutoff = Date();
210 WLOG(
"fixing cutoff date not set");
213 auto loader = boost::make_shared<CSVLoader>(marketFiles, fixingFiles, dividendFiles, implyTodaysFixings, cutoff);
221 LOG(
"ORE analytics starting");
224 QL_REQUIRE(
params_,
"ORE input parameters not set");
226 Settings::instance().evaluationDate() =
inputs_->asof();
228 GlobalPseudoCurrencyMarketParameters::instance().set(
inputs_->pricingEngine()->globalParameters());
231 InstrumentConventions::instance().setConventions(
inputs_->conventions());
235 auto loader = QuantLib::ext::make_shared<MarketDataCsvLoader>(
inputs_, csvLoader);
244 QuantLib::ext::shared_ptr<MarketCalibrationReportBase> mcr;
245 if (
inputs_->outputTodaysMarketCalibration()) {
246 auto marketCalibrationReport = QuantLib::ext::make_shared<ore::data::InMemoryReport>();
247 mcr = QuantLib::ext::make_shared<MarketCalibrationReport>(
string(), marketCalibrationReport);
262 for (
auto b : a.second) {
263 LOG(
"write npv cube " << b.first);
264 string reportName = b.first;
265 std::string fileName =
inputs_->resultsPath().string() +
"/" +
outputs_->outputFileName(reportName,
"csv.gz");
266 LOG(
"write npv cube " << reportName <<
" to file " << fileName);
269 if (b.first ==
"cube") {
281 for (
auto b : a.second) {
282 string reportName = b.first;
283 std::string fileName =
inputs_->resultsPath().string() +
"/" +
outputs_->outputFileName(reportName,
"csv.gz");
284 LOG(
"write market cube " << reportName <<
" to file " << fileName);
290 for(
auto b: a.second){
291 string reportName = b.first;
292 std::string fileName =
293 inputs_->resultsPath().string() +
"/" +
outputs_->outputFileName(reportName,
"xml");
294 LOG(
"write converted stress test scenario definition " << reportName <<
" to file " << fileName);
295 b.second->toFile(fileName);
300 catch (std::exception& e) {
302 oss <<
"Error in ORE analytics: " << e.what();
310 LOG(
"ORE analytics done");
316 ConsoleLog::instance().switchOn();
323 if (
params_->has(
"setup",
"logMask")) {
331 if (
params_->hasGroup(
"logging")) {
332 string tmp =
params_->get(
"logging",
"logFile",
false);
336 tmp =
params_->get(
"logging",
"logMask",
false);
340 tmp =
params_->get(
"logging",
"progressLogFile",
false);
344 tmp =
params_->get(
"logging",
"progressLogRotationSize",
false);
348 tmp =
params_->get(
"logging",
"progressLogToConsole",
false);
352 tmp =
params_->get(
"logging",
"structuredLogFile",
false);
356 tmp =
params_->get(
"logging",
"structuredLogRotationSize",
false);
370 inputs_ = QuantLib::ext::make_shared<OREAppInputParameters>(
params_);
375 Settings::instance().evaluationDate() =
inputs_->asof();
381 Settings::instance().evaluationDate() =
inputs_->asof();
382 InstrumentConventions::instance().setConventions(
inputs_->conventions());
384 ConsoleLog::instance().switchOn();
401 static std::mutex _s_mutex;
402 std::lock_guard<std::mutex> lock(_s_mutex);
417 ALOG(
"both inputs are empty");
426 }
catch (std::exception& e) {
428 CONSOLE(
"Error: " << e.what());
443 const std::vector<std::string>& fixingData) {
446 static std::mutex _s_mutex;
447 std::lock_guard<std::mutex> lock(_s_mutex);
462 ALOG(
"both inputs are empty");
469 LOG(
"ORE analytics starting");
473 QL_REQUIRE(
inputs_,
"ORE input parameters not set");
476 Settings::instance().evaluationDate() =
inputs_->asof();
479 QL_REQUIRE(
inputs_->pricingEngine(),
"pricingEngine not set");
480 GlobalPseudoCurrencyMarketParameters::instance().set(
inputs_->pricingEngine()->globalParameters());
483 QL_REQUIRE(
inputs_->conventions(),
"conventions not set");
484 InstrumentConventions::instance().setConventions(
inputs_->conventions());
487 auto loader = QuantLib::ext::make_shared<MarketDataInMemoryLoader>(
inputs_, marketData, fixingData);
496 QuantLib::ext::shared_ptr<MarketCalibrationReportBase> mcr;
497 if (
inputs_->outputTodaysMarketCalibration()) {
498 auto marketCalibrationReport = QuantLib::ext::make_shared<ore::data::InMemoryReport>();
499 mcr = QuantLib::ext::make_shared<MarketCalibrationReport>(
string(), marketCalibrationReport);
508 catch (std::exception& e) {
510 oss <<
"Error in ORE analytics: " << e.what();
520 LOG(
"ORE analytics done");
524 const boost::filesystem::path& logRootPath,
const std::string& progressLogFile,
525 Size progressLogRotationSize,
bool progressLogToConsole,
const std::string& structuredLogFile,
526 Size structuredLogRotationSize) {
529 boost::filesystem::path p{path};
530 if (!boost::filesystem::exists(p)) {
531 boost::filesystem::create_directories(p);
533 QL_REQUIRE(boost::filesystem::is_directory(p),
"output path '" << path <<
"' is not a directory.");
535 Log::instance().registerLogger(QuantLib::ext::make_shared<FileLogger>(file));
536 boost::filesystem::path oreRootPath =
537 logRootPath.empty() ? boost::filesystem::path(__FILE__).parent_path().parent_path().parent_path().parent_path()
539 Log::instance().setRootPath(oreRootPath);
540 Log::instance().setMask(mask);
541 Log::instance().switchOn();
544 auto progressLogger = QuantLib::ext::make_shared<ProgressLogger>();
545 string progressLogFilePath = progressLogFile.empty() ? path +
"/log_progress.json" : progressLogFile;
546 progressLogger->setFileLog(progressLogFilePath, path, progressLogRotationSize);
547 progressLogger->setCoutLog(progressLogToConsole);
548 Log::instance().registerIndependentLogger(progressLogger);
552 string structuredLogFilePath = structuredLogFile.empty() ? path +
"/log_structured.json" : structuredLogFile;
553 structuredLogger_->setFileLog(structuredLogFilePath, path, structuredLogRotationSize);
557 auto eventLogger = QuantLib::ext::make_shared<EventLogger>();
558 eventLogger->setFileLog(path +
"/log_event_");
559 ore::data::Log::instance().registerIndependentLogger(eventLogger);
567 LOG(
"load OREAppInputParameters called");
576 QL_REQUIRE(
params_->hasGroup(
"setup"),
"parameter group 'setup' missing");
578 filesystem::path inputPath =
params_->get(
"setup",
"inputPath");
579 std::string outputPath =
params_->get(
"setup",
"outputPath");
582 std::string tmp =
params_->get(
"setup",
"calendarAdjustment",
false);
585 filesystem::path calendarAdjustmentFile = inputPath / tmp;
586 LOG(
"Loading calendar adjustments from file: " << calendarAdjustmentFile);
587 calendarAdjustments.
fromFile(calendarAdjustmentFile.generic_string());
589 WLOG(
"Calendar adjustments not found, using defaults");
593 tmp =
params_->get(
"setup",
"currencyConfiguration",
false);
596 filesystem::path currencyConfigFile = inputPath / tmp;
597 LOG(
"Loading currency configurations from file: " << currencyConfigFile);
598 currencyConfig.
fromFile(currencyConfigFile.generic_string());
600 WLOG(
"Currency configurations not found, using defaults");
606 Settings::instance().evaluationDate() =
asof();
611 tmp =
params_->get(
"setup",
"baseCurrency",
false);
614 else if (
params_->hasGroup(
"npv"))
617 WLOG(
"Base currency not set");
620 tmp =
params_->get(
"setup",
"useMarketDataFixings",
false);
624 tmp =
params_->get(
"setup",
"dryRun",
false);
628 tmp =
params_->get(
"setup",
"reportNaString",
false);
632 tmp =
params_->get(
"setup",
"eomInflationFixings",
false);
636 tmp =
params_->get(
"setup",
"nThreads",
false);
640 tmp =
params_->get(
"setup",
"entireMarket",
false);
644 tmp =
params_->get(
"setup",
"iborFallbackOverride",
false);
648 tmp =
params_->get(
"setup",
"continueOnError",
false);
652 tmp =
params_->get(
"setup",
"lazyMarketBuilding",
false);
656 tmp =
params_->get(
"setup",
"buildFailedTrades",
false);
660 tmp =
params_->get(
"setup",
"observationModel",
false);
667 tmp =
params_->get(
"setup",
"implyTodaysFixings",
false);
671 tmp =
params_->get(
"setup",
"referenceDataFile",
false);
673 filesystem::path refDataFile = inputPath / tmp;
674 LOG(
"Loading reference data from file: " << refDataFile);
677 WLOG(
"Reference data not found");
680 tmp =
params_->get(
"setup",
"scriptLibrary",
false);
682 filesystem::path scriptFile = inputPath / tmp;
683 LOG(
"Loading script library from file: " << scriptFile);
687 WLOG(
"Script library not loaded");
690 if (
params_->has(
"setup",
"conventionsFile") &&
params_->get(
"setup",
"conventionsFile") !=
"") {
691 filesystem::path conventionsFile = inputPath /
params_->get(
"setup",
"conventionsFile");
692 LOG(
"Loading conventions from file: " << conventionsFile);
695 ALOG(
"Conventions not found");
698 if (
params_->has(
"setup",
"iborFallbackConfig") &&
params_->get(
"setup",
"iborFallbackConfig") !=
"") {
699 filesystem::path tmp = inputPath /
params_->get(
"setup",
"iborFallbackConfig");
700 LOG(
"Loading Ibor fallback config from file: " << tmp);
703 WLOG(
"Using default Ibor fallback config");
706 if (
params_->has(
"setup",
"curveConfigFile") &&
params_->get(
"setup",
"curveConfigFile") !=
"") {
707 filesystem::path curveConfigFile = inputPath /
params_->get(
"setup",
"curveConfigFile");
708 LOG(
"Load curve configurations from file: ");
711 ALOG(
"no curve configs loaded");
714 tmp =
params_->get(
"setup",
"pricingEnginesFile",
false);
716 filesystem::path pricingEnginesFile = inputPath / tmp;
717 LOG(
"Load pricing engine data from file: " << pricingEnginesFile);
720 ALOG(
"Pricing engine data not found");
723 tmp =
params_->get(
"setup",
"marketConfigFile",
false);
725 filesystem::path marketConfigFile = inputPath / tmp;
726 LOG(
"Loading today's market parameters from file" << marketConfigFile);
729 ALOG(
"Today's market parameters not found");
732 if (
params_->has(
"setup",
"buildFailedTrades"))
735 tmp =
params_->get(
"setup",
"portfolioFile",
false);
739 WLOG(
"Portfolio data not provided");
742 if (
params_->hasGroup(
"markets")) {
745 LOG(
"MarketContext::" << m.first <<
" = " << m.second);
748 if (
params_->has(
"setup",
"csvCommentReportHeader"))
751 if (
params_->has(
"setup",
"csvSeparator")) {
752 tmp =
params_->get(
"setup",
"csvSeparator");
753 QL_REQUIRE(tmp.size() == 1,
"csvSeparator must be exactly one character");
761 tmp =
params_->get(
"npv",
"active",
false);
765 tmp =
params_->get(
"npv",
"additionalResults",
false);
769 tmp =
params_->get(
"npv",
"additionalResultsReportPrecision",
false);
777 tmp =
params_->get(
"pnl",
"active",
false);
781 tmp =
params_->get(
"pnl",
"mporDate",
false);
785 tmp =
params_->get(
"pnl",
"mporDays",
false);
789 tmp =
params_->get(
"pnl",
"mporCalendar",
false);
793 tmp =
params_->get(
"pnl",
"simulationConfigFile",
false);
795 string simulationConfigFile = (inputPath / tmp).generic_string();
796 LOG(
"Loading scenario simulation config from file" << simulationConfigFile);
800 ALOG(
"Scenario Simulation market data not loaded");
808 tmp =
params_->get(
"cashflow",
"active",
false);
812 tmp =
params_->get(
"cashflow",
"includePastCashflows",
false);
820 tmp =
params_->get(
"curves",
"active",
false);
826 tmp =
params_->get(
"curves",
"grid",
false);
830 tmp =
params_->get(
"curves",
"configuration",
false);
834 tmp =
params_->get(
"curves",
"outputTodaysMarketCalibration",
false);
847 tmp =
params_->get(
"sensitivity",
"active",
false);
851 tmp =
params_->get(
"sensitivity",
"parSensitivity",
false);
855 tmp =
params_->get(
"sensitivity",
"optimiseRiskFactors",
false);
859 tmp =
params_->get(
"sensitivity",
"outputJacobi",
false);
863 tmp =
params_->get(
"sensitivity",
"alignPillars",
false);
869 tmp =
params_->get(
"sensitivity",
"marketConfigFile",
false);
871 string file = (inputPath / tmp).generic_string();
872 LOG(
"Loading sensitivity scenario sim market parameters from file" << file);
875 WLOG(
"ScenarioSimMarket parameters for sensitivity not loaded");
878 tmp =
params_->get(
"sensitivity",
"sensitivityConfigFile",
false);
880 string file = (inputPath / tmp).generic_string();
881 LOG(
"Load sensitivity scenario data from file" << file);
884 WLOG(
"Sensitivity scenario data not loaded");
887 tmp =
params_->get(
"sensitivity",
"pricingEnginesFile",
false);
889 string file = (inputPath / tmp).generic_string();
890 LOG(
"Load pricing engine data from file: " << file);
893 WLOG(
"Pricing engine data not found for sensitivity analysis, using global");
898 tmp =
params_->get(
"sensitivity",
"outputSensitivityThreshold",
false);
902 tmp =
params_->get(
"sensitivity",
"recalibrateModels",
false);
911 tmp =
params_->get(
"scenario",
"active",
false);
915 tmp =
params_->get(
"scenario",
"simulationConfigFile",
false);
917 string simulationConfigFile = (inputPath / tmp).generic_string();
918 LOG(
"Loading scenario simulation config from file" << simulationConfigFile);
921 ALOG(
"Scenario Simulation market data not loaded");
924 tmp =
params_->get(
"scenario",
"scenarioOutputFile",
false);
933 tmp =
params_->get(
"stress",
"active",
false);
937 tmp =
params_->get(
"stress",
"marketConfigFile",
false);
939 string file = (inputPath / tmp).generic_string();
940 LOG(
"Loading stress test scenario sim market parameters from file" << file);
943 WLOG(
"ScenarioSimMarket parameters for stress testing not loaded");
946 tmp =
params_->get(
"stress",
"stressConfigFile",
false);
948 string file = (inputPath / tmp).generic_string();
949 LOG(
"Load stress test scenario data from file" << file);
952 WLOG(
"Stress scenario data not loaded");
955 tmp =
params_->get(
"stress",
"pricingEnginesFile",
false);
957 string file = (inputPath / tmp).generic_string();
958 LOG(
"Load pricing engine data from file: " << file);
961 WLOG(
"Pricing engine data not found for stress testing, using global");
964 tmp =
params_->get(
"stress",
"outputThreshold",
false);
968 tmp =
params_->get(
"stress",
"optimiseRiskFactors",
false);
972 tmp =
params_->get(
"stress",
"sensitivityConfigFile",
false);
974 string file = (inputPath / tmp).generic_string();
975 LOG(
"Load sensitivity scenario data from file" << file);
978 WLOG(
"Sensitivity scenario data not loaded, don't support par stress tests");
981 tmp =
params_->get(
"stress",
"lowerBoundCapVols",
false);
985 tmp =
params_->get(
"stress",
"upperBoundCapVols",
false);
989 tmp =
params_->get(
"stress",
"lowerBoundDiscountFactors",
false);
993 tmp =
params_->get(
"stress",
"upperBoundDiscountFactors",
false);
997 tmp =
params_->get(
"stress",
"lowerBoundSurvivalProb",
false);
1001 tmp =
params_->get(
"stress",
"upperBoundSurvivalProb",
false);
1005 tmp =
params_->get(
"stress",
"accuracy",
false);
1015 tmp =
params_->get(
"parStressConversion",
"active",
false);
1019 tmp =
params_->get(
"parStressConversion",
"marketConfigFile",
false);
1021 string file = (inputPath / tmp).generic_string();
1022 LOG(
"Loading parStressConversion test scenario sim market parameters from file" << file);
1025 WLOG(
"ScenarioSimMarket parameters for par stress conversion testing not loaded");
1028 tmp =
params_->get(
"parStressConversion",
"stressConfigFile",
false);
1030 string file = (inputPath / tmp).generic_string();
1031 LOG(
"Load stress test scenario data from file" << file);
1034 WLOG(
"Stress scenario data not loaded");
1037 tmp =
params_->get(
"parStressConversion",
"pricingEnginesFile",
false);
1039 string file = (inputPath / tmp).generic_string();
1040 LOG(
"Load pricing engine data from file: " << file);
1043 WLOG(
"Pricing engine data not found for stress testing, using global");
1046 tmp =
params_->get(
"parStressConversion",
"sensitivityConfigFile",
false);
1048 string file = (inputPath / tmp).generic_string();
1049 LOG(
"Load sensitivity scenario data from file" << file);
1052 WLOG(
"Sensitivity scenario data not loaded, don't support par stress tests");
1055 tmp =
params_->get(
"parStressConversion",
"lowerBoundCapVols",
false);
1059 tmp =
params_->get(
"parStressConversion",
"upperBoundCapVols",
false);
1063 tmp =
params_->get(
"parStressConversion",
"lowerBoundDiscountFactors",
false);
1067 tmp =
params_->get(
"parStressConversion",
"upperBoundDiscountFactors",
false);
1071 tmp =
params_->get(
"parStressConversion",
"lowerBoundSurvivalProb",
false);
1075 tmp =
params_->get(
"parStressConversion",
"upperBoundSurvivalProb",
false);
1079 tmp =
params_->get(
"parStressConversion",
"accuracy",
false);
1089 tmp =
params_->get(
"zeroToParShift",
"active",
false);
1093 tmp =
params_->get(
"zeroToParShift",
"marketConfigFile",
false);
1095 string file = (inputPath / tmp).generic_string();
1096 LOG(
"Loading zero to par shift conversion scenario sim market parameters from file " << file);
1099 WLOG(
"ScenarioSimMarket parameters for zero to par shift conversion not loaded");
1102 tmp =
params_->get(
"zeroToParShift",
"stressConfigFile",
false);
1104 string file = (inputPath / tmp).generic_string();
1105 LOG(
"Load zero to par shift conversion scenario data from file" << file);
1108 WLOG(
"Zero to par shift conversion scenario data not loaded");
1111 tmp =
params_->get(
"zeroToParShift",
"pricingEnginesFile",
false);
1113 string file = (inputPath / tmp).generic_string();
1114 LOG(
"Load pricing engine data from file: " << file);
1117 WLOG(
"Pricing engine data not found for Zero to par shift conversion, using global");
1120 tmp =
params_->get(
"zeroToParShift",
"sensitivityConfigFile",
false);
1122 string file = (inputPath / tmp).generic_string();
1123 LOG(
"Load sensitivity scenario data from file" << file);
1126 WLOG(
"Sensitivity scenario data not loaded for zero to par shift conversion");
1134 tmp =
params_->get(
"parametricVar",
"active",
false);
1138 tmp =
params_->get(
"parametricVar",
"salvageCovarianceMatrix",
false);
1142 tmp =
params_->get(
"parametricVar",
"quantiles",
false);
1146 tmp =
params_->get(
"parametricVar",
"breakdown",
false);
1150 tmp =
params_->get(
"parametricVar",
"portfolioFilter",
false);
1154 tmp =
params_->get(
"parametricVar",
"method",
false);
1158 tmp =
params_->get(
"parametricVar",
"mcSamples",
false);
1162 tmp =
params_->get(
"parametricVar",
"mcSeed",
false);
1166 tmp =
params_->get(
"parametricVar",
"covarianceInputFile",
false);
1167 QL_REQUIRE(tmp !=
"",
"covarianceInputFile not provided");
1168 std::string covFile = (inputPath / tmp).generic_string();
1169 LOG(
"Load Covariance Data from file " << covFile);
1172 tmp =
params_->get(
"parametricVar",
"sensitivityInputFile",
false);
1173 QL_REQUIRE(tmp !=
"",
"sensitivityInputFile not provided");
1174 std::string sensiFile = (inputPath / tmp).generic_string();
1175 LOG(
"Get sensitivity data from file " << sensiFile);
1178 tmp =
params_->get(
"parametricVar",
"outputHistoricalScenarios",
false);
1187 tmp =
params_->get(
"historicalSimulationVar",
"active",
false);
1191 tmp =
params_->get(
"historicalSimulationVar",
"historicalScenarioFile",
false);
1192 QL_REQUIRE(tmp !=
"",
"historicalScenarioFile not provided");
1193 std::string scenarioFile = (inputPath / tmp).generic_string();
1196 tmp =
params_->get(
"historicalSimulationVar",
"simulationConfigFile",
false);
1197 QL_REQUIRE(tmp !=
"",
"simulationConfigFile not provided");
1198 string simulationConfigFile = (inputPath / tmp).generic_string();
1201 tmp =
params_->get(
"historicalSimulationVar",
"historicalPeriod",
false);
1205 tmp =
params_->get(
"historicalSimulationVar",
"mporDays",
false);
1209 tmp =
params_->get(
"historicalSimulationVar",
"mporCalendar",
false);
1213 tmp =
params_->get(
"historicalSimulationVar",
"mporOverlappingPeriods",
false);
1217 tmp =
params_->get(
"historicalSimulationVar",
"quantiles",
false);
1221 tmp =
params_->get(
"historicalSimulationVar",
"breakdown",
false);
1225 tmp =
params_->get(
"historicalSimulationVar",
"portfolioFilter",
false);
1229 tmp =
params_->get(
"historicalSimulationVar",
"outputHistoricalScenarios",
false);
1237 tmp =
params_->get(
"pnlExplain",
"active",
false);
1241 tmp =
params_->get(
"pnlExplain",
"mporDate",
false);
1245 tmp =
params_->get(
"pnlExplain",
"historicalScenarioFile",
false);
1247 std::string scenarioFile = (inputPath / tmp).generic_string();
1251 tmp =
params_->get(
"pnlExplain",
"simulationConfigFile",
false);
1253 string file = (inputPath / tmp).generic_string();
1254 LOG(
"Loading sensitivity scenario sim market parameters from file" << file);
1258 WLOG(
"ScenarioSimMarket parameters for sensitivity not loaded");
1261 tmp =
params_->get(
"pnlExplain",
"sensitivityConfigFile",
false);
1263 string file = (inputPath / tmp).generic_string();
1264 LOG(
"Load sensitivity scenario data from file" << file);
1267 WLOG(
"Sensitivity scenario data not loaded");
1275 tmp =
params_->get(
"simm",
"active",
false);
1276 bool doSimm = !tmp.empty() ?
parseBool(tmp) :
false;
1280 tmp =
params_->get(
"simm",
"version",
false);
1284 tmp =
params_->get(
"simm",
"mporDays",
false);
1288 tmp =
params_->get(
"simm",
"crif",
false);
1290 string file = (inputPath / tmp).generic_string();
1294 tmp =
params_->get(
"simm",
"simmCalibration",
false);
1296 string file = (inputPath / tmp).generic_string();
1297 if (boost::filesystem::exists(file))
1301 tmp =
params_->get(
"simm",
"calculationCurrency",
false);
1306 QL_REQUIRE(
baseCurrency() !=
"",
"either base currency or calculation currency is required");
1309 tmp =
params_->get(
"simm",
"calculationCurrencyCall",
false);
1314 tmp =
params_->get(
"simm",
"calculationCurrencyPost",
false);
1319 tmp =
params_->get(
"simm",
"resultCurrency",
false);
1325 tmp =
params_->get(
"simm",
"reportingCurrency",
false);
1329 tmp =
params_->get(
"simm",
"enforceIMRegulations",
false);
1333 tmp =
params_->get(
"simm",
"writeIntermediateReports",
false);
1339 tmp =
params_->get(
"imschedule",
"active",
false);
1343 tmp =
params_->get(
"imschedule",
"version",
false);
1345 string tmpSimm =
params_->get(
"simm",
"version",
false);
1346 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"version for imschedule and simm should match");
1349 LOG(
"set SIMM version for IM Schedule to 2.6, required to load CRIF")
1353 tmp =
params_->get(
"imschedule",
"crif",
false);
1355 string tmpSimm =
params_->get(
"simm",
"crif",
false);
1356 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"crif files for imschedule and simm should match");
1357 string file = (inputPath / tmp).generic_string();
1361 tmp =
params_->get(
"imschedule",
"calculationCurrency",
false);
1363 string tmpSimm =
params_->get(
"simm",
"calculationCurrency",
false);
1364 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"calculation currency for for imschedule and simm should match");
1368 QL_REQUIRE(
baseCurrency() !=
"",
"either base currency or calculation currency is required");
1371 tmp =
params_->get(
"imschedule",
"calculationCurrencyCall",
false);
1373 string tmpSimm =
params_->get(
"simm",
"calculationCurrencyCall",
false);
1374 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"calculation currency for imschedule and simm should match");
1378 tmp =
params_->get(
"imschedule",
"calculationCurrencyPost",
false);
1380 string tmpSimm =
params_->get(
"simm",
"calculationCurrencyPost",
false);
1381 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"calculation currency for imschedule and simm should match");
1385 tmp =
params_->get(
"imschedule",
"resultCurrency",
false);
1387 string tmpSimm =
params_->get(
"simm",
"resultCurrency",
false);
1388 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"result currency for imschedule and simm should match");
1394 tmp =
params_->get(
"imschedule",
"reportingCurrency",
false);
1396 string tmpSimm =
params_->get(
"simm",
"reportingCurrency",
false);
1397 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"reporting currency for imschedule and simm should match");
1401 tmp =
params_->get(
"imschedule",
"enforceIMRegulations",
false);
1403 string tmpSimm =
params_->get(
"simm",
"enforceIMRegulations",
false);
1404 QL_REQUIRE(!doSimm || tmp == tmpSimm,
"enforceIMRegulations for imschedule and simm should match");
1413 tmp =
params_->get(
"simulation",
"active",
false);
1419 tmp =
params_->get(
"xva",
"active",
false);
1423 tmp =
params_->get(
"xvaStress",
"active",
false);
1427 tmp =
params_->get(
"xvaSensitivity",
"active",
false);
1431 tmp =
params_->get(
"simulation",
"salvageCorrelationMatrix",
false);
1435 tmp =
params_->get(
"simulation",
"amc",
false);
1439 tmp =
params_->get(
"simulation",
"amcCg",
false);
1443 tmp =
params_->get(
"simulation",
"xvaCgSensitivityConfigFile",
false);
1445 string file = (inputPath / tmp).generic_string();
1446 LOG(
"Load xva cg sensitivity scenario data from file" << file);
1450 tmp =
params_->get(
"simulation",
"amcTradeTypes",
false);
1461 tmp =
params_->get(
"simulation",
"simulationConfigFile",
false);
1463 string simulationConfigFile = (inputPath / tmp).generic_string();
1464 LOG(
"Loading simulation config from file" << simulationConfigFile);
1469 DLOG(
"grid size=" << grid->size() <<
", dates=" << grid->dates().size() <<
", valuationDates="
1470 << grid->valuationDates().size() <<
", closeOutDates=" << grid->closeOutDates().size());
1472 ALOG(
"Simulation market, model and scenario generator data not loaded");
1475 tmp =
params_->get(
"simulation",
"pricingEnginesFile",
false);
1477 string pricingEnginesFile = (inputPath / tmp).generic_string();
1478 LOG(
"Load simulation pricing engine data from file: " << pricingEnginesFile);
1481 WLOG(
"Simulation pricing engine data not found, using standard pricing engines");
1484 tmp =
params_->get(
"simulation",
"amcPricingEnginesFile",
false);
1486 string pricingEnginesFile = (inputPath / tmp).generic_string(); ;
1487 LOG(
"Load amc pricing engine data from file: " << pricingEnginesFile);
1490 WLOG(
"AMC pricing engine data not found, using standard pricing engines");
1495 tmp =
params_->get(
"simulation",
"baseCurrency",
false);
1499 tmp =
params_->get(
"simulation",
"observationModel",
false);
1505 tmp =
params_->get(
"simulation",
"storeFlows",
false);
1509 tmp =
params_->get(
"simulation",
"storeCreditStateNPVs",
false);
1513 tmp =
params_->get(
"simulation",
"storeSurvivalProbabilities",
false);
1517 tmp =
params_->get(
"simulation",
"nettingSetId",
false);
1521 tmp =
params_->get(
"simulation",
"cubeFile",
false);
1525 tmp =
params_->get(
"simulation",
"scenariodump",
false);
1529 tmp =
params_->get(
"simulation",
"xvaCgBumpSensis",
false);
1539 tmp =
params_->get(
"xva",
"baseCurrency",
false);
1547 tmp =
params_->get(
"xva",
"cubeFile",
false);
1549 string cubeFile = (
resultsPath() / tmp).generic_string();
1550 LOG(
"Load cube from file " << cubeFile);
1552 LOG(
"Cube loading done: ids=" <<
cube()->numIds() <<
" dates=" <<
cube()->numDates()
1553 <<
" samples=" <<
cube()->samples() <<
" depth=" <<
cube()->depth());
1555 ALOG(
"cube file name not provided");
1561 tmp =
params_->get(
"xva",
"csaFile",
false);
1562 QL_REQUIRE(tmp !=
"",
"Netting set manager is required for XVA");
1563 string csaFile = (inputPath / tmp).generic_string();
1564 LOG(
"Loading netting and csa data from file " << csaFile);
1567 tmp =
params_->get(
"xva",
"collateralBalancesFile",
false);
1569 string collBalancesFile = (inputPath / tmp).generic_string();
1570 LOG(
"Loading collateral balances from file " << collBalancesFile);
1575 tmp =
params_->get(
"xva",
"nettingSetCubeFile",
false);
1577 string cubeFile = (
resultsPath() / tmp).generic_string();
1578 LOG(
"Load nettingset cube from file " << cubeFile);
1580 DLOG(
"NettingSetCube loading done: ids="
1585 tmp =
params_->get(
"xva",
"cptyCubeFile",
false);
1587 string cubeFile =
resultsPath().string() +
"/" + tmp;
1588 LOG(
"Load cpty cube from file " << cubeFile);
1590 DLOG(
"CptyCube loading done: ids=" <<
cptyCube()->numIds() <<
" dates=" <<
cptyCube()->numDates()
1591 <<
" samples=" <<
cptyCube()->samples() <<
" depth=" <<
cptyCube()->depth());
1594 tmp =
params_->get(
"xva",
"scenarioFile",
false);
1596 string cubeFile =
resultsPath().string() +
"/" + tmp;
1597 LOG(
"Load agg scen data from file " << cubeFile);
1599 LOG(
"MktCube loading done");
1602 tmp =
params_->get(
"xva",
"flipViewXVA",
false);
1606 tmp =
params_->get(
"xva",
"mporCashFlowMode",
false);
1610 tmp =
params_->get(
"xva",
"fullInitialCollateralisation",
false);
1614 tmp =
params_->get(
"xva",
"exposureProfilesByTrade",
false);
1618 tmp =
params_->get(
"xva",
"exposureProfiles",
false);
1622 tmp =
params_->get(
"xva",
"quantile",
false);
1626 tmp =
params_->get(
"xva",
"calculationType",
false);
1630 tmp =
params_->get(
"xva",
"allocationMethod",
false);
1634 tmp =
params_->get(
"xva",
"marginalAllocationLimit",
false);
1638 tmp =
params_->get(
"xva",
"exerciseNextBreak",
false);
1642 tmp =
params_->get(
"xva",
"cva",
false);
1646 tmp =
params_->get(
"xva",
"dva",
false);
1650 tmp =
params_->get(
"xva",
"fva",
false);
1654 tmp =
params_->get(
"xva",
"colva",
false);
1658 tmp =
params_->get(
"xva",
"collateralFloor",
false);
1662 tmp =
params_->get(
"xva",
"dim",
false);
1666 tmp =
params_->get(
"xva",
"dimModel",
false);
1668 QL_REQUIRE(tmp ==
"Regression" || tmp ==
"Flat",
1669 "DIM model " << tmp <<
" not supported, expected Regression or Flat");
1673 tmp =
params_->get(
"xva",
"mva",
false);
1677 tmp =
params_->get(
"xva",
"kva",
false);
1681 tmp =
params_->get(
"xva",
"dynamicCredit",
false);
1685 tmp =
params_->get(
"xva",
"cvaSensi",
false);
1689 tmp =
params_->get(
"xva",
"cvaSensiGrid",
false);
1693 tmp =
params_->get(
"xva",
"cvaSensiShiftSize",
false);
1697 tmp =
params_->get(
"xva",
"dvaName",
false);
1701 tmp =
params_->get(
"xva",
"rawCubeOutputFile",
false);
1707 tmp =
params_->get(
"xva",
"netCubeOutputFile",
false);
1715 tmp =
params_->get(
"xva",
"fvaBorrowingCurve",
false);
1719 tmp =
params_->get(
"xva",
"fvaLendingCurve",
false);
1723 tmp =
params_->get(
"xva",
"flipViewBorrowingCurvePostfix",
false);
1727 tmp =
params_->get(
"xva",
"flipViewLendingCurvePostfix",
false);
1733 tmp =
params_->get(
"xva",
"deterministicInitialMarginFile",
false);
1735 string imFile = (inputPath / tmp).generic_string();
1736 LOG(
"Load initial margin evolution from file " << tmp);
1740 tmp =
params_->get(
"xva",
"dimQuantile",
false);
1744 tmp =
params_->get(
"xva",
"dimHorizonCalendarDays",
false);
1748 tmp =
params_->get(
"xva",
"dimRegressionOrder",
false);
1752 tmp =
params_->get(
"xva",
"dimRegressors",
false);
1756 tmp =
params_->get(
"xva",
"dimOutputGridPoints",
false);
1760 tmp =
params_->get(
"xva",
"dimOutputNettingSet",
false);
1764 tmp =
params_->get(
"xva",
"dimLocalRegressionEvaluations",
false);
1768 tmp =
params_->get(
"xva",
"dimLocalRegressionBandwidth",
false);
1774 tmp =
params_->get(
"xva",
"kvaCapitalDiscountRate",
false);
1778 tmp =
params_->get(
"xva",
"kvaAlpha",
false);
1782 tmp =
params_->get(
"xva",
"kvaRegAdjustment",
false);
1786 tmp =
params_->get(
"xva",
"kvaCapitalHurdle",
false);
1790 tmp =
params_->get(
"xva",
"kvaOurPdFloor",
false);
1794 tmp =
params_->get(
"xva",
"kvaTheirPdFloor",
false);
1798 tmp =
params_->get(
"xva",
"kvaOurCvaRiskWeight",
false);
1802 tmp =
params_->get(
"xva",
"kvaTheirCvaRiskWeight",
false);
1808 tmp =
params_->get(
"xva",
"creditMigration",
false);
1812 tmp =
params_->get(
"xva",
"creditMigrationDistributionGrid",
false);
1816 tmp =
params_->get(
"xva",
"creditMigrationTimeSteps",
false);
1820 tmp =
params_->get(
"xva",
"creditMigrationConfig",
false);
1822 string file = (inputPath / tmp).generic_string();
1823 LOG(
"Loading credit migration config from file" << file);
1827 tmp =
params_->get(
"xva",
"creditMigrationOutputFiles",
false);
1836 tmp =
params_->get(
"xvaStress",
"marketConfigFile",
false);
1838 string file = (inputPath / tmp).generic_string();
1839 LOG(
"Loading xva stress test scenario sim market parameters from file" << file);
1842 WLOG(
"ScenarioSimMarket parameters for xva stress testing not loaded");
1845 tmp =
params_->get(
"xvaStress",
"stressConfigFile",
false);
1847 string file = (inputPath / tmp).generic_string();
1848 LOG(
"Load xav stress test scenario data from file" << file);
1851 WLOG(
"Xva Stress scenario data not loaded");
1854 tmp =
params_->get(
"xvaStress",
"writeCubes",
false);
1856 bool writeCubes =
false;
1857 bool success = tryParse<bool>(tmp, writeCubes,
parseBool);
1863 tmp =
params_->get(
"xvaStress",
"sensitivityConfigFile",
false);
1865 string file = (inputPath / tmp).generic_string();
1866 LOG(
"Load sensitivity scenario data from file" << file);
1869 WLOG(
"Sensitivity scenario data not loaded, don't support par stress tests");
1878 tmp =
params_->get(
"xvaSensitivity",
"marketConfigFile",
false);
1880 string file = (inputPath / tmp).generic_string();
1881 LOG(
"Loading xva sensitivity scenario sim market parameters from file" << file);
1884 WLOG(
"ScenarioSimMarket parameters for xva sensitivity not loaded");
1887 tmp =
params_->get(
"xvaSensitivity",
"sensitivityConfigFile",
false);
1889 string file = (inputPath / tmp).generic_string();
1890 LOG(
"Load xva sensitivity scenario data from file" << file);
1893 WLOG(
"Xva sensitivity scenario data not loaded");
1901 tmp =
params_->get(
"cashflow",
"cashFlowHorizon",
false);
1905 tmp =
params_->get(
"cashflow",
"portfolioFilterDate",
false);
1913 tmp =
params_->get(
"zeroToParSensiConversion",
"active",
false);
1917 tmp =
params_->get(
"zeroToParSensiConversion",
"sensitivityInputFile",
false);
1922 tmp =
params_->get(
"zeroToParSensiConversion",
"idColumn",
false);
1927 tmp =
params_->get(
"zeroToParSensiConversion",
"riskFactorColumn",
false);
1932 tmp =
params_->get(
"zeroToParSensiConversion",
"deltaColumn",
false);
1937 tmp =
params_->get(
"zeroToParSensiConversion",
"currencyColumn",
false);
1942 tmp =
params_->get(
"zeroToParSensiConversion",
"baseNpvColumn",
false);
1947 tmp =
params_->get(
"zeroToParSensiConversion",
"shiftSizeColumn",
false);
1952 tmp =
params_->get(
"zeroToParSensiConversion",
"marketConfigFile",
false);
1954 string file = (inputPath / tmp).generic_string();
1955 LOG(
"Loading par converions scenario sim market parameters from file" << file);
1958 WLOG(
"ScenarioSimMarket parameters for par conversion testing not loaded");
1961 tmp =
params_->get(
"zeroToParSensiConversion",
"sensitivityConfigFile",
false);
1963 string file = (inputPath / tmp).generic_string();
1964 LOG(
"Load par conversion scenario data from file" << file);
1967 WLOG(
"Par conversion scenario data not loaded");
1970 tmp =
params_->get(
"zeroToParSensiConversion",
"pricingEnginesFile",
false);
1972 string file = (inputPath / tmp).generic_string();
1973 LOG(
"Load pricing engine data from file: " << file);
1976 WLOG(
"Pricing engine data not found for par conversion, using global");
1979 tmp =
params_->get(
"zeroToParSensiConversion",
"outputThreshold",
false);
1983 tmp =
params_->get(
"zeroToParSensiConversion",
"outputJacobi",
false);
1992 tmp =
params_->get(
"scenarioStatistics",
"active",
false);
1995 tmp =
params_->get(
"scenarioStatistics",
"distributionBuckets",
false);
1999 tmp =
params_->get(
"scenarioStatistics",
"outputZeroRate",
false);
2003 tmp =
params_->get(
"scenarioStatistics",
"simulationConfigFile",
false);
2005 string simulationConfigFile = (inputPath / tmp).generic_string();
2006 LOG(
"Loading simulation config from file" << simulationConfigFile);
2011 DLOG(
"grid size=" << grid->size() <<
", dates=" << grid->dates().size() <<
", valuationDates="
2012 << grid->valuationDates().size() <<
", closeOutDates=" << grid->closeOutDates().size());
2014 ALOG(
"Simulation market, model and scenario generator data not loaded");
2017 tmp =
params_->get(
"scenarioStatistics",
"scenariodump",
false);
2026 LOG(
"Lazy market build being overridden to \"false\" for MARKETDATA analytic.")
2032 LOG(
"analytic: " << a);
2034 LOG(
"buildInputParameters done");
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< ore::data::InMemoryReport > > > analytic_reports
QuantLib::ext::shared_ptr< AggregationScenarioData > getMarketCube(std::string cubeName)
QuantLib::Size structuredLogRotationSize_
void setupLog(const std::string &path, const std::string &file, QuantLib::Size mask, const boost::filesystem::path &logRootPath, const std::string &progressLogFile="", QuantLib::Size progressLogRotationSize=100 *1024 *1024, bool progressLogToConsole=false, const std::string &structuredLogFile="", QuantLib::Size structuredLogRotationSize=100 *1024 *1024)
set up logging
boost::timer::cpu_timer runTimer_
virtual void run()
Runs analytics and generates reports after using the first OREApp c'tor.
bool progressLogToConsole_
string structuredLogFile_
std::vector< std::string > getErrors()
virtual ~OREApp()
Destructor.
Real getRunTime()
time for executing run(...) in seconds
QuantLib::ext::shared_ptr< AnalyticsManager > analyticsManager_
QuantLib::ext::shared_ptr< PlainInMemoryReport > getReport(std::string reportName)
QuantLib::ext::shared_ptr< OutputParameters > outputs_
std::set< std::string > getMarketCubeNames()
std::vector< std::string > errorMessages_
const QuantLib::ext::shared_ptr< Analytic > & getAnalytic(std::string type)
QuantLib::Size progressLogRotationSize_
QuantLib::ext::shared_ptr< CSVLoader > buildCsvLoader(const QuantLib::ext::shared_ptr< Parameters > ¶ms)
QuantLib::ext::shared_ptr< Parameters > params_
ORE Input parameters.
boost::filesystem::path logRootPath_
std::set< std::string > getSupportedAnalyticTypes()
void closeLog()
remove logs
QuantLib::ext::shared_ptr< NPVCube > getCube(std::string cubeName)
QuantLib::ext::shared_ptr< StructuredLogger > structuredLogger_
std::set< std::string > getReportNames()
std::set< std::string > getCubeNames()
QuantLib::ext::shared_ptr< InputParameters > inputs_
std::set< std::string > getAnalyticTypes()
void fromFile(const std::string &filename)
load / save cubes and agg scen data from / to disk
MporCashFlowMode parseMporCashFlowMode(const std::string &s)
Date parseDate(const string &s)
bool parseBool(const string &s)
Real parseReal(const string &s)
Integer parseInteger(const string &s)
#define MEM_LOG_USING_LEVEL(LEVEL)
vector< string > getFileNames(const string &fileString, const std::filesystem::path &path)
void saveCube(const std::string &filename, const NPVCubeWithMetaData &cube, const bool doublePrecision)
void saveAggregationScenarioData(const std::string &filename, const AggregationScenarioData &cube)
Size size(const ValueType &v)
std::string to_string(const LocationInfo &l)
Singleton class to hold global Observation Mode.
Structured analytics error.
Class for structured analytics warnings.
#define OPEN_SOURCE_RISK_VERSION