Skip to content

Commit b11432c

Browse files
committed
Allow absolute pathes in master input file
1 parent d2e1ae6 commit b11432c

4 files changed

Lines changed: 46 additions & 55 deletions

File tree

OREAnalytics/orea/app/inputparameters.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
namespace ore {
3232
namespace analytics {
3333

34-
vector<string> getFileNames(const string& fileString, const string& path) {
34+
vector<string> getFileNames(const string& fileString, const std::filesystem::path& path) {
3535
vector<string> fileNames;
3636
boost::split(fileNames, fileString, boost::is_any_of(",;"), boost::token_compress_on);
3737
for (auto it = fileNames.begin(); it < fileNames.end(); it++) {
3838
boost::trim(*it);
39-
*it = path + "/" + *it;
39+
*it = (path / *it).generic_string();
4040
}
4141
return fileNames;
4242
}
@@ -136,7 +136,7 @@ void InputParameters::setPortfolio(const std::string& xml) {
136136
portfolio_->fromXMLString(xml);
137137
}
138138

139-
void InputParameters::setPortfolioFromFile(const std::string& fileNameString, const std::string& inputPath) {
139+
void InputParameters::setPortfolioFromFile(const std::string& fileNameString, const std::filesystem::path& inputPath) {
140140
vector<string> files = getFileNames(fileNameString, inputPath);
141141
portfolio_ = boost::make_shared<Portfolio>(buildFailedTrades_);
142142
for (auto file : files) {

OREAnalytics/orea/app/inputparameters.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <ored/marketdata/csvloader.hpp>
4545
#include <ored/utilities/csvfilereader.hpp>
4646
#include <boost/filesystem/path.hpp>
47+
#include <filesystem>
4748

4849
namespace ore {
4950
namespace analytics {
@@ -83,7 +84,7 @@ class InputParameters {
8384
void setTodaysMarketParams(const std::string& xml);
8485
void setTodaysMarketParamsFromFile(const std::string& fileName);
8586
void setPortfolio(const std::string& xml);
86-
void setPortfolioFromFile(const std::string& fileNameString, const std::string& inputPath);
87+
void setPortfolioFromFile(const std::string& fileNameString, const std::filesystem::path& inputPath);
8788
void setMarketConfigs(const std::map<std::string, std::string>& m);
8889
void setThreads(int i) { nThreads_ = i; }
8990
void setEntireMarket(bool b) { entireMarket_ = b; }
@@ -806,6 +807,7 @@ inline const std::string& InputParameters::marketConfig(const std::string& conte
806807
auto it = marketConfigs_.find(context);
807808
return (it != marketConfigs_.end() ? it->second : Market::defaultConfiguration);
808809
}
810+
std::vector<std::string> getFileNames(const std::string& fileString, const std::filesystem::path& path);
809811

810812
//! Traditional ORE input via ore.xml and various files, output into files
811813
class OutputParameters {

OREAnalytics/orea/app/oreapp.cpp

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,13 @@ Real OREApp::getRunTime() {
164164
return seconds.count();
165165
}
166166

167-
vector<string> OREApp::getFileNames(const string& fileString, const string& path) {
168-
vector<string> fileNames;
169-
boost::split(fileNames, fileString, boost::is_any_of(",;"), boost::token_compress_on);
170-
for (auto it = fileNames.begin(); it < fileNames.end(); it++) {
171-
boost::trim(*it);
172-
*it = path + "/" + *it;
173-
}
174-
return fileNames;
175-
}
176-
177167
boost::shared_ptr<CSVLoader> OREApp::buildCsvLoader(const boost::shared_ptr<Parameters>& params) {
178168
bool implyTodaysFixings = false;
179169
vector<string> marketFiles = {};
180170
vector<string> fixingFiles = {};
181171
vector<string> dividendFiles = {};
182172

183-
std::string inputPath = params_->get("setup", "inputPath");
173+
filesystem::path inputPath = params_->get("setup", "inputPath");
184174

185175
std::string tmp = params_->get("setup", "implyTodaysFixings", false);
186176
if (tmp != "")
@@ -469,16 +459,16 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
469459

470460
QL_REQUIRE(params_->hasGroup("setup"), "parameter group 'setup' missing");
471461

472-
std::string inputPath = params_->get("setup", "inputPath");
462+
filesystem::path inputPath = params_->get("setup", "inputPath");
473463
std::string outputPath = params_->get("setup", "outputPath");
474464

475465
// Load calendar adjustments
476466
std::string tmp = params_->get("setup", "calendarAdjustment", false);
477467
if (tmp != "") {
478468
CalendarAdjustmentConfig calendarAdjustments;
479-
string calendarAdjustmentFile = inputPath + "/" + tmp;
469+
filesystem::path calendarAdjustmentFile = inputPath / tmp;
480470
LOG("Loading calendar adjustments from file: " << calendarAdjustmentFile);
481-
calendarAdjustments.fromFile(calendarAdjustmentFile);
471+
calendarAdjustments.fromFile(calendarAdjustmentFile.generic_string());
482472
} else {
483473
WLOG("Calendar adjustments not found, using defaults");
484474
}
@@ -487,9 +477,9 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
487477
tmp = params_->get("setup", "currencyConfiguration", false);
488478
if (tmp != "") {
489479
CurrencyConfig currencyConfig;
490-
string currencyConfigFile = inputPath + "/" + tmp;
480+
filesystem::path currencyConfigFile = inputPath / tmp;
491481
LOG("Loading currency configurations from file: " << currencyConfigFile);
492-
currencyConfig.fromFile(currencyConfigFile);
482+
currencyConfig.fromFile(currencyConfigFile.generic_string());
493483
} else {
494484
WLOG("Currency configurations not found, using defaults");
495485
}
@@ -560,61 +550,61 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
560550

561551
tmp = params_->get("setup", "referenceDataFile", false);
562552
if (tmp != "") {
563-
string refDataFile = inputPath + "/" + tmp;
553+
filesystem::path refDataFile = inputPath / tmp;
564554
LOG("Loading reference data from file: " << refDataFile);
565-
inputs->setRefDataManagerFromFile(refDataFile);
555+
inputs->setRefDataManagerFromFile(refDataFile.generic_string());
566556
} else {
567557
WLOG("Reference data not found");
568558
}
569559

570560
tmp = params_->get("setup", "scriptLibrary", false);
571561
if (tmp != "") {
572-
string scriptFile = inputPath + "/" + tmp;
562+
filesystem::path scriptFile = inputPath / tmp;
573563
LOG("Loading script library from file: " << scriptFile);
574-
inputs->setScriptLibraryFromFile(scriptFile);
564+
inputs->setScriptLibraryFromFile(scriptFile.generic_string());
575565
}
576566
else {
577567
WLOG("Script library not loaded");
578568
}
579569

580570
if (params_->has("setup", "conventionsFile") && params_->get("setup", "conventionsFile") != "") {
581-
string conventionsFile = inputPath + "/" + params_->get("setup", "conventionsFile");
571+
filesystem::path conventionsFile = inputPath / params_->get("setup", "conventionsFile");
582572
LOG("Loading conventions from file: " << conventionsFile);
583-
inputs->setConventionsFromFile(conventionsFile);
573+
inputs->setConventionsFromFile(conventionsFile.generic_string());
584574
} else {
585575
ALOG("Conventions not found");
586576
}
587577

588578
if (params_->has("setup", "iborFallbackConfig") && params_->get("setup", "iborFallbackConfig") != "") {
589-
std::string tmp = inputPath + "/" + params_->get("setup", "iborFallbackConfig");
579+
filesystem::path tmp = inputPath / params_->get("setup", "iborFallbackConfig");
590580
LOG("Loading Ibor fallback config from file: " << tmp);
591-
inputs->setIborFallbackConfigFromFile(tmp);
581+
inputs->setIborFallbackConfigFromFile(tmp.generic_string());
592582
} else {
593583
WLOG("Using default Ibor fallback config");
594584
}
595585

596586
if (params_->has("setup", "curveConfigFile") && params_->get("setup", "curveConfigFile") != "") {
597-
string curveConfigFile = inputPath + "/" + params_->get("setup", "curveConfigFile");
587+
filesystem::path curveConfigFile = inputPath / params_->get("setup", "curveConfigFile");
598588
LOG("Load curve configurations from file: ");
599-
inputs->setCurveConfigsFromFile(curveConfigFile);
589+
inputs->setCurveConfigsFromFile(curveConfigFile.generic_string());
600590
} else {
601591
ALOG("no curve configs loaded");
602592
}
603593

604594
tmp = params_->get("setup", "pricingEnginesFile", false);
605595
if (tmp != "") {
606-
string pricingEnginesFile = inputPath + "/" + tmp;
596+
filesystem::path pricingEnginesFile = inputPath / tmp;
607597
LOG("Load pricing engine data from file: " << pricingEnginesFile);
608-
inputs->setPricingEngineFromFile(pricingEnginesFile);
598+
inputs->setPricingEngineFromFile(pricingEnginesFile.generic_string());
609599
} else {
610600
ALOG("Pricing engine data not found");
611601
}
612602

613603
tmp = params_->get("setup", "marketConfigFile", false);
614604
if (tmp != "") {
615-
string marketConfigFile = inputPath + "/" + tmp;
605+
filesystem::path marketConfigFile = inputPath / tmp;
616606
LOG("Loading today's market parameters from file" << marketConfigFile);
617-
inputs->setTodaysMarketParamsFromFile(marketConfigFile);
607+
inputs->setTodaysMarketParamsFromFile(marketConfigFile.generic_string());
618608
} else {
619609
ALOG("Today's market parameters not found");
620610
}
@@ -708,7 +698,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
708698

709699
tmp = params_->get("sensitivity", "marketConfigFile", false);
710700
if (tmp != "") {
711-
string file = inputPath + "/" + tmp;
701+
string file = (inputPath / tmp).generic_string();
712702
LOG("Loading sensitivity scenario sim market parameters from file" << file);
713703
inputs->setSensiSimMarketParamsFromFile(file);
714704
} else {
@@ -717,7 +707,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
717707

718708
tmp = params_->get("sensitivity", "sensitivityConfigFile", false);
719709
if (tmp != "") {
720-
string file = inputPath + "/" + tmp;
710+
string file = (inputPath / tmp).generic_string();
721711
LOG("Load sensitivity scenario data from file" << file);
722712
inputs->setSensiScenarioDataFromFile(file);
723713
} else {
@@ -726,7 +716,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
726716

727717
tmp = params_->get("sensitivity", "pricingEnginesFile", false);
728718
if (tmp != "") {
729-
string file = inputPath + "/" + tmp;
719+
string file = (inputPath / tmp).generic_string();
730720
LOG("Load pricing engine data from file: " << file);
731721
inputs->setSensiPricingEngineFromFile(file);
732722
} else {
@@ -750,7 +740,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
750740
inputs->setStressPricingEngine(inputs->pricingEngine());
751741
tmp = params_->get("stress", "marketConfigFile", false);
752742
if (tmp != "") {
753-
string file = inputPath + "/" + tmp;
743+
string file = (inputPath / tmp).generic_string();
754744
LOG("Loading stress test scenario sim market parameters from file" << file);
755745
inputs->setStressSimMarketParamsFromFile(file);
756746
} else {
@@ -759,7 +749,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
759749

760750
tmp = params_->get("stress", "stressConfigFile", false);
761751
if (tmp != "") {
762-
string file = inputPath + "/" + tmp;
752+
string file = (inputPath / tmp).generic_string();
763753
LOG("Load stress test scenario data from file" << file);
764754
inputs->setStressScenarioDataFromFile(file);
765755
} else {
@@ -768,7 +758,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
768758

769759
tmp = params_->get("stress", "pricingEnginesFile", false);
770760
if (tmp != "") {
771-
string file = inputPath + "/" + tmp;
761+
string file = (inputPath / tmp).generic_string();
772762
LOG("Load pricing engine data from file: " << file);
773763
inputs->setStressPricingEngineFromFile(file);
774764
} else {
@@ -818,13 +808,13 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
818808

819809
tmp = params_->get("parametricVar", "covarianceInputFile", false);
820810
QL_REQUIRE(tmp != "", "covarianceInputFile not provided");
821-
std::string covFile = inputPath + "/" + tmp;
811+
std::string covFile = (inputPath / tmp).generic_string();
822812
LOG("Load Covariance Data from file " << covFile);
823813
inputs->setCovarianceDataFromFile(covFile);
824814

825815
tmp = params_->get("parametricVar", "sensitivityInputFile", false);
826816
QL_REQUIRE(tmp != "", "sensitivityInputFile not provided");
827-
std::string sensiFile = inputPath + "/" + tmp;
817+
std::string sensiFile = (inputPath / tmp).generic_string();
828818
LOG("Get sensitivity data from file " << sensiFile);
829819
inputs->setSensitivityStreamFromFile(sensiFile);
830820
}
@@ -847,7 +837,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
847837

848838
tmp = params_->get("simm", "crif", false);
849839
if (tmp != "") {
850-
string file = inputPath + "/" + tmp;
840+
string file = (inputPath / tmp).generic_string();
851841
inputs->setCrifFromFile(file, inputs->csvEolChar(), inputs->csvSeparator(), '\"', inputs->csvEscapeChar());
852842
}
853843

@@ -909,7 +899,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
909899
inputs->analytics().find("XVA") != inputs->analytics().end()) {
910900
tmp = params_->get("simulation", "simulationConfigFile", false) ;
911901
if (tmp != "") {
912-
string simulationConfigFile = inputPath + "/" + tmp;
902+
string simulationConfigFile = (inputPath / tmp).generic_string();
913903
LOG("Loading simulation config from file" << simulationConfigFile);
914904
inputs->setExposureSimMarketParamsFromFile(simulationConfigFile);
915905
inputs->setCrossAssetModelDataFromFile(simulationConfigFile);
@@ -924,7 +914,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
924914

925915
tmp = params_->get("simulation", "pricingEnginesFile", false);
926916
if (tmp != "") {
927-
string pricingEnginesFile = inputPath + "/" + tmp;
917+
string pricingEnginesFile = (inputPath / tmp).generic_string();
928918
LOG("Load simulation pricing engine data from file: " << pricingEnginesFile);
929919
inputs->setSimulationPricingEngineFromFile(pricingEnginesFile);
930920
} else {
@@ -933,7 +923,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
933923

934924
tmp = params_->get("simulation", "amcPricingEnginesFile", false);
935925
if (tmp != "") {
936-
string pricingEnginesFile = inputPath + "/" + tmp;
926+
string pricingEnginesFile = (inputPath / tmp).generic_string(); ;
937927
LOG("Load amc pricing engine data from file: " << pricingEnginesFile);
938928
inputs->setAmcPricingEngineFromFile(pricingEnginesFile);
939929
} else {
@@ -1008,7 +998,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
1008998
inputs->analytics().find("EXPOSURE") != inputs->analytics().end()) {
1009999
tmp = params_->get("xva", "csaFile", false);
10101000
QL_REQUIRE(tmp != "", "Netting set manager is required for XVA");
1011-
string csaFile = inputPath + "/" + tmp;
1001+
string csaFile = (inputPath / tmp).generic_string();
10121002
LOG("Loading netting and csa data from file" << csaFile);
10131003
inputs->setNettingSetManagerFromFile(csaFile);
10141004
}
@@ -1165,7 +1155,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
11651155

11661156
tmp = params_->get("xva", "deterministicInitialMarginFile", false);
11671157
if (tmp != "") {
1168-
string imFile = inputPath + "/" + tmp;
1158+
string imFile = (inputPath / tmp).generic_string();
11691159
LOG("Load initial margin evolution from file " << tmp);
11701160
inputs->setDeterministicInitialMarginFromFile(imFile);
11711161
}
@@ -1252,7 +1242,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
12521242

12531243
tmp = params_->get("xva", "creditMigrationConfig", false);
12541244
if (tmp != "") {
1255-
string file = inputPath + "/" + tmp;
1245+
string file = (inputPath / tmp).generic_string();
12561246
LOG("Loading credit migration config from file" << file);
12571247
inputs->setCreditSimulationParametersFromFile(file);
12581248
}
@@ -1281,7 +1271,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
12811271

12821272
tmp = params_->get("zeroToParSensiConversion", "sensitivityInputFile", false);
12831273
if (tmp != "") {
1284-
inputs->setParConversionInputFile(inputPath + "/" + tmp);
1274+
inputs->setParConversionInputFile((inputPath / tmp).generic_string());
12851275
}
12861276

12871277
tmp = params_->get("zeroToParSensiConversion", "idColumn", false);
@@ -1316,7 +1306,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
13161306

13171307
tmp = params_->get("zeroToParSensiConversion", "marketConfigFile", false);
13181308
if (tmp != "") {
1319-
string file = inputPath + "/" + tmp;
1309+
string file = (inputPath / tmp).generic_string();
13201310
LOG("Loading par converions scenario sim market parameters from file" << file);
13211311
inputs->setParConversionSimMarketParamsFromFile(file);
13221312
} else {
@@ -1325,7 +1315,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
13251315

13261316
tmp = params_->get("zeroToParSensiConversion", "sensitivityConfigFile", false);
13271317
if (tmp != "") {
1328-
string file = inputPath + "/" + tmp;
1318+
string file = (inputPath / tmp).generic_string();
13291319
LOG("Load par conversion scenario data from file" << file);
13301320
inputs->setParConversionScenarioDataFromFile(file);
13311321
} else {
@@ -1334,7 +1324,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
13341324

13351325
tmp = params_->get("zeroToParSensiConversion", "pricingEnginesFile", false);
13361326
if (tmp != "") {
1337-
string file = inputPath + "/" + tmp;
1327+
string file = (inputPath / tmp).generic_string();
13381328
LOG("Load pricing engine data from file: " << file);
13391329
inputs->setParConversionPricingEngineFromFile(file);
13401330
} else {
@@ -1368,7 +1358,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
13681358

13691359
tmp = params_->get("scenarioStatistics", "simulationConfigFile", false);
13701360
if (tmp != "") {
1371-
string simulationConfigFile = inputPath + "/" + tmp;
1361+
string simulationConfigFile = (inputPath / tmp).generic_string();
13721362
LOG("Loading simulation config from file" << simulationConfigFile);
13731363
inputs->setExposureSimMarketParamsFromFile(simulationConfigFile);
13741364
inputs->setCrossAssetModelDataFromFile(simulationConfigFile);

OREAnalytics/orea/app/oreapp.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class OREApp {
8484
//! Populate InputParameters object from classic ORE key-value pairs in Parameters
8585
void buildInputParameters(boost::shared_ptr<InputParameters> inputs,
8686
const boost::shared_ptr<Parameters>& params);
87-
vector<string> getFileNames(const string& fileString, const string& path);
8887
boost::shared_ptr<CSVLoader> buildCsvLoader(const boost::shared_ptr<Parameters>& params);
8988
//! set up logging
9089
void setupLog(const std::string& path, const std::string& file, QuantLib::Size mask,

0 commit comments

Comments
 (0)