30vector<string> getFilenames(
const string& fileString,
const string& path) {
31 vector<string> fileNames;
32 boost::split(fileNames, fileString, boost::is_any_of(
",;"), boost::token_compress_on);
33 for (
auto it = fileNames.begin(); it < fileNames.end(); it++) {
35 *it = path +
"/" + *it;
46 const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigs,
47 const QuantLib::ext::shared_ptr<TodaysMarketParameters>& todaysMarketParams) {
50 LOG(
"Running sensitivity analysis");
53 sensiData_ = QuantLib::ext::make_shared<SensitivityScenarioData>();
54 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
55 QuantLib::ext::shared_ptr<Portfolio> sensiPortfolio = QuantLib::ext::make_shared<Portfolio>();
56 string marketConfiguration =
params_->get(
"markets",
"sensitivity");
60 bool recalibrateModels =
61 params_->has(
"sensitivity",
"recalibrateModels") &&
parseBool(
params_->get(
"sensitivity",
"recalibrateModels"));
63 bool analyticFxSensis =
false;
64 if (
params_->has(
"sensitivity",
"analyticFxSensis")) {
65 analyticFxSensis =
parseBool(
params_->get(
"sensitivity",
"analyticFxSensis"));
68 QuantLib::ext::shared_ptr<SensitivityAnalysis> sensiAnalysis = QuantLib::ext::make_shared<SensitivityAnalysis>(
69 sensiPortfolio, market, marketConfiguration, engineData, simMarketData,
sensiData_, recalibrateModels,
72 sensiAnalysis->generateSensitivities();
78 LOG(
"Sensitivity analysis completed");
83 QuantLib::ext::shared_ptr<SensitivityScenarioData>& sensiData,
84 QuantLib::ext::shared_ptr<EngineData>& engineData,
85 QuantLib::ext::shared_ptr<Portfolio>& sensiPortfolio) {
87 DLOG(
"sensiInputInitialize called");
89 LOG(
"Get Simulation Market Parameters");
90 string inputPath =
params_->get(
"setup",
"inputPath");
91 string marketConfigFile = inputPath +
"/" +
params_->get(
"sensitivity",
"marketConfigFile");
92 simMarketData->fromFile(marketConfigFile);
94 LOG(
"Get Sensitivity Parameters");
95 string sensitivityConfigFile = inputPath +
"/" +
params_->get(
"sensitivity",
"sensitivityConfigFile");
96 sensiData->fromFile(sensitivityConfigFile);
98 LOG(
"Get Engine Data");
99 string sensiPricingEnginesFile = inputPath +
"/" +
params_->get(
"sensitivity",
"pricingEnginesFile");
100 engineData->fromFile(sensiPricingEnginesFile);
102 LOG(
"Get Portfolio");
103 string portfoliosString =
params_->get(
"setup",
"portfolioFile");
104 vector<string> portfolioFiles = getFilenames(portfoliosString, inputPath);
106 for (
auto portfolioFile : portfolioFiles) {
107 sensiPortfolio->fromFile(portfolioFile);
110 DLOG(
"sensiInputInitialize done");
115 string outputPath =
params_->get(
"setup",
"outputPath");
116 Real sensiThreshold =
parseReal(
params_->get(
"sensitivity",
"outputSensitivityThreshold"));
118 string outputFile = outputPath +
"/" +
params_->get(
"sensitivity",
"scenarioOutputFile");
123 auto baseCurrency = sensiAnalysis->simMarketData()->baseCcy();
124 auto ss = QuantLib::ext::make_shared<SensitivityCubeStream>(sensiAnalysis->sensiCube(), baseCurrency);
126 Size outputPrecision = 2;
127 if (
params_->has(
"sensitivity",
"outputPrecision")) {
131 outputFile = outputPath +
"/" +
params_->get(
"sensitivity",
"sensitivityOutputFile");
135 CSVFileReport pricingStatsReport(
params_->get(
"setup",
"outputPath") +
"/pricingstats_sensi.csv");
Write ORE outputs to reports.
virtual void writeSensitivityReport(ore::data::Report &report, const QuantLib::ext::shared_ptr< SensitivityStream > &ss, QuantLib::Real outputThreshold=0.0, QuantLib::Size outputPrecision=2)
virtual void writeScenarioReport(ore::data::Report &report, const std::vector< QuantLib::ext::shared_ptr< SensitivityCube > > &sensitivityCubes, QuantLib::Real outputThreshold=0.0)
virtual void writePricingStats(ore::data::Report &report, const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
ScenarioSimMarket description.
QuantLib::ext::shared_ptr< SensitivityScenarioData > sensiData_
Sensitivity configuration data used for the sensitivity run.
const bool continueOnError_
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
Scenario simulation market that is bumped for the sensitivity run.
QuantLib::ext::shared_ptr< Parameters > params_
virtual void sensiInputInitialize(QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &simMarketData, QuantLib::ext::shared_ptr< SensitivityScenarioData > &sensiData, QuantLib::ext::shared_ptr< EngineData > &engineData, QuantLib::ext::shared_ptr< Portfolio > &sensiPortfolio)
Initialize input parameters to the sensitivities analysis.
QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > referenceData_
IborFallbackConfig iborFallbackConfig_
virtual void runSensitivityAnalysis(QuantLib::ext::shared_ptr< ore::data::Market > market, const QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > &curveConfigs, const QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > &todaysMarketParams)
virtual void sensiOutputReports(const QuantLib::ext::shared_ptr< SensitivityAnalysis > &sensiAnalysis)
Write out some standard sensitivities reports.
const QuantLib::ext::shared_ptr< SensitivityScenarioData > & sensiData() const
bool parseBool(const string &s)
Real parseReal(const string &s)
Integer parseInteger(const string &s)
A Class to write ORE outputs to reports.
Class for streaming SensitivityRecords from a SensitivityCube.
A class to run the sensitivity analysis.
vector< string > curveConfigs