Skip to content

Commit 7a24fb0

Browse files
Reapply "Allow absolute pathes in master input file"
This reverts commit 4cb3964.
1 parent c5b2856 commit 7a24fb0

4 files changed

Lines changed: 47 additions & 54 deletions

File tree

OREAnalytics/orea/app/inputparameters.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
namespace ore {
3535
namespace analytics {
3636

37-
vector<string> getFileNames(const string& fileString, const string& path) {
37+
vector<string> getFileNames(const string& fileString, const std::filesystem::path& path) {
3838
vector<string> fileNames;
3939
boost::split(fileNames, fileString, boost::is_any_of(",;"), boost::token_compress_on);
4040
for (auto it = fileNames.begin(); it < fileNames.end(); it++) {
4141
boost::trim(*it);
42-
*it = path + "/" + *it;
42+
*it = (path / *it).generic_string();
4343
}
4444
return fileNames;
4545
}
@@ -140,7 +140,7 @@ void InputParameters::setPortfolio(const std::string& xml) {
140140
portfolio_->fromXMLString(xml);
141141
}
142142

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

OREAnalytics/orea/app/inputparameters.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include <ored/portfolio/portfolio.hpp>
5454
#include <ored/portfolio/referencedata.hpp>
5555
#include <ored/utilities/csvfilereader.hpp>
56+
#include <boost/filesystem/path.hpp>
57+
#include <filesystem>
5658

5759
namespace ore {
5860
namespace analytics {
@@ -92,7 +94,7 @@ class InputParameters {
9294
void setTodaysMarketParams(const std::string& xml);
9395
void setTodaysMarketParamsFromFile(const std::string& fileName);
9496
void setPortfolio(const std::string& xml);
95-
void setPortfolioFromFile(const std::string& fileNameString, const std::string& inputPath);
97+
void setPortfolioFromFile(const std::string& fileNameString, const std::filesystem::path& inputPath);
9698
void setMarketConfigs(const std::map<std::string, std::string>& m);
9799
void setThreads(int i) { nThreads_ = i; }
98100
void setEntireMarket(bool b) { entireMarket_ = b; }
@@ -875,6 +877,7 @@ inline const std::string& InputParameters::marketConfig(const std::string& conte
875877
auto it = marketConfigs_.find(context);
876878
return (it != marketConfigs_.end() ? it->second : Market::defaultConfiguration);
877879
}
880+
std::vector<std::string> getFileNames(const std::string& fileString, const std::filesystem::path& path);
878881

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

OREAnalytics/orea/app/oreapp.cpp

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

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

184-
std::string inputPath = params_->get("setup", "inputPath");
174+
filesystem::path inputPath = params_->get("setup", "inputPath");
185175

186176
std::string tmp = params_->get("setup", "implyTodaysFixings", false);
187177
if (tmp != "")
@@ -518,16 +508,16 @@ void OREAppInputParameters::loadParameters() {
518508

519509
QL_REQUIRE(params_->hasGroup("setup"), "parameter group 'setup' missing");
520510

521-
std::string inputPath = params_->get("setup", "inputPath");
511+
filesystem::path inputPath = params_->get("setup", "inputPath");
522512
std::string outputPath = params_->get("setup", "outputPath");
523513

524514
// Load calendar adjustments
525515
std::string tmp = params_->get("setup", "calendarAdjustment", false);
526516
if (tmp != "") {
527517
CalendarAdjustmentConfig calendarAdjustments;
528-
string calendarAdjustmentFile = inputPath + "/" + tmp;
518+
filesystem::path calendarAdjustmentFile = inputPath / tmp;
529519
LOG("Loading calendar adjustments from file: " << calendarAdjustmentFile);
530-
calendarAdjustments.fromFile(calendarAdjustmentFile);
520+
calendarAdjustments.fromFile(calendarAdjustmentFile.generic_string());
531521
} else {
532522
WLOG("Calendar adjustments not found, using defaults");
533523
}
@@ -536,9 +526,9 @@ void OREAppInputParameters::loadParameters() {
536526
tmp = params_->get("setup", "currencyConfiguration", false);
537527
if (tmp != "") {
538528
CurrencyConfig currencyConfig;
539-
string currencyConfigFile = inputPath + "/" + tmp;
529+
filesystem::path currencyConfigFile = inputPath / tmp;
540530
LOG("Loading currency configurations from file: " << currencyConfigFile);
541-
currencyConfig.fromFile(currencyConfigFile);
531+
currencyConfig.fromFile(currencyConfigFile.generic_string());
542532
} else {
543533
WLOG("Currency configurations not found, using defaults");
544534
}
@@ -613,60 +603,61 @@ void OREAppInputParameters::loadParameters() {
613603

614604
tmp = params_->get("setup", "referenceDataFile", false);
615605
if (tmp != "") {
616-
string refDataFile = inputPath + "/" + tmp;
606+
filesystem::path refDataFile = inputPath / tmp;
617607
LOG("Loading reference data from file: " << refDataFile);
618-
setRefDataManagerFromFile(refDataFile);
608+
setRefDataManagerFromFile(refDataFile.generic_string());
619609
} else {
620610
WLOG("Reference data not found");
621611
}
622612

623613
tmp = params_->get("setup", "scriptLibrary", false);
624614
if (tmp != "") {
625-
string scriptFile = inputPath + "/" + tmp;
615+
filesystem::path scriptFile = inputPath / tmp;
626616
LOG("Loading script library from file: " << scriptFile);
627-
setScriptLibraryFromFile(scriptFile);
628-
} else {
617+
setScriptLibraryFromFile(scriptFile.generic_string());
618+
}
619+
else {
629620
WLOG("Script library not loaded");
630621
}
631622

632623
if (params_->has("setup", "conventionsFile") && params_->get("setup", "conventionsFile") != "") {
633-
string conventionsFile = inputPath + "/" + params_->get("setup", "conventionsFile");
624+
filesystem::path conventionsFile = inputPath / params_->get("setup", "conventionsFile");
634625
LOG("Loading conventions from file: " << conventionsFile);
635-
setConventionsFromFile(conventionsFile);
626+
setConventionsFromFile(conventionsFile.generic_string());
636627
} else {
637628
ALOG("Conventions not found");
638629
}
639630

640631
if (params_->has("setup", "iborFallbackConfig") && params_->get("setup", "iborFallbackConfig") != "") {
641-
std::string tmp = inputPath + "/" + params_->get("setup", "iborFallbackConfig");
632+
filesystem::path tmp = inputPath / params_->get("setup", "iborFallbackConfig");
642633
LOG("Loading Ibor fallback config from file: " << tmp);
643-
setIborFallbackConfigFromFile(tmp);
634+
setIborFallbackConfigFromFile(tmp.generic_string());
644635
} else {
645636
WLOG("Using default Ibor fallback config");
646637
}
647638

648639
if (params_->has("setup", "curveConfigFile") && params_->get("setup", "curveConfigFile") != "") {
649-
string curveConfigFile = inputPath + "/" + params_->get("setup", "curveConfigFile");
640+
filesystem::path curveConfigFile = inputPath / params_->get("setup", "curveConfigFile");
650641
LOG("Load curve configurations from file: ");
651-
setCurveConfigsFromFile(curveConfigFile);
642+
setCurveConfigsFromFile(curveConfigFile.generic_string());
652643
} else {
653644
ALOG("no curve configs loaded");
654645
}
655646

656647
tmp = params_->get("setup", "pricingEnginesFile", false);
657648
if (tmp != "") {
658-
string pricingEnginesFile = inputPath + "/" + tmp;
649+
filesystem::path pricingEnginesFile = inputPath / tmp;
659650
LOG("Load pricing engine data from file: " << pricingEnginesFile);
660-
setPricingEngineFromFile(pricingEnginesFile);
651+
setPricingEngineFromFile(pricingEnginesFile.generic_string());
661652
} else {
662653
ALOG("Pricing engine data not found");
663654
}
664655

665656
tmp = params_->get("setup", "marketConfigFile", false);
666657
if (tmp != "") {
667-
string marketConfigFile = inputPath + "/" + tmp;
658+
filesystem::path marketConfigFile = inputPath / tmp;
668659
LOG("Loading today's market parameters from file" << marketConfigFile);
669-
setTodaysMarketParamsFromFile(marketConfigFile);
660+
setTodaysMarketParamsFromFile(marketConfigFile.generic_string());
670661
} else {
671662
ALOG("Today's market parameters not found");
672663
}
@@ -775,7 +766,7 @@ void OREAppInputParameters::loadParameters() {
775766

776767
tmp = params_->get("sensitivity", "marketConfigFile", false);
777768
if (tmp != "") {
778-
string file = inputPath + "/" + tmp;
769+
string file = (inputPath / tmp).generic_string();
779770
LOG("Loading sensitivity scenario sim market parameters from file" << file);
780771
setSensiSimMarketParamsFromFile(file);
781772
} else {
@@ -784,7 +775,7 @@ void OREAppInputParameters::loadParameters() {
784775

785776
tmp = params_->get("sensitivity", "sensitivityConfigFile", false);
786777
if (tmp != "") {
787-
string file = inputPath + "/" + tmp;
778+
string file = (inputPath / tmp).generic_string();
788779
LOG("Load sensitivity scenario data from file" << file);
789780
setSensiScenarioDataFromFile(file);
790781
} else {
@@ -793,7 +784,7 @@ void OREAppInputParameters::loadParameters() {
793784

794785
tmp = params_->get("sensitivity", "pricingEnginesFile", false);
795786
if (tmp != "") {
796-
string file = inputPath + "/" + tmp;
787+
string file = (inputPath / tmp).generic_string();
797788
LOG("Load pricing engine data from file: " << file);
798789
setSensiPricingEngineFromFile(file);
799790
} else {
@@ -843,7 +834,7 @@ void OREAppInputParameters::loadParameters() {
843834
setStressPricingEngine(pricingEngine());
844835
tmp = params_->get("stress", "marketConfigFile", false);
845836
if (tmp != "") {
846-
string file = inputPath + "/" + tmp;
837+
string file = (inputPath / tmp).generic_string();
847838
LOG("Loading stress test scenario sim market parameters from file" << file);
848839
setStressSimMarketParamsFromFile(file);
849840
} else {
@@ -852,7 +843,7 @@ void OREAppInputParameters::loadParameters() {
852843

853844
tmp = params_->get("stress", "stressConfigFile", false);
854845
if (tmp != "") {
855-
string file = inputPath + "/" + tmp;
846+
string file = (inputPath / tmp).generic_string();
856847
LOG("Load stress test scenario data from file" << file);
857848
setStressScenarioDataFromFile(file);
858849
} else {
@@ -861,7 +852,7 @@ void OREAppInputParameters::loadParameters() {
861852

862853
tmp = params_->get("stress", "pricingEnginesFile", false);
863854
if (tmp != "") {
864-
string file = inputPath + "/" + tmp;
855+
string file = (inputPath / tmp).generic_string();
865856
LOG("Load pricing engine data from file: " << file);
866857
setStressPricingEngineFromFile(file);
867858
} else {
@@ -911,13 +902,13 @@ void OREAppInputParameters::loadParameters() {
911902

912903
tmp = params_->get("parametricVar", "covarianceInputFile", false);
913904
QL_REQUIRE(tmp != "", "covarianceInputFile not provided");
914-
std::string covFile = inputPath + "/" + tmp;
905+
std::string covFile = (inputPath / tmp).generic_string();
915906
LOG("Load Covariance Data from file " << covFile);
916907
setCovarianceDataFromFile(covFile);
917908

918909
tmp = params_->get("parametricVar", "sensitivityInputFile", false);
919910
QL_REQUIRE(tmp != "", "sensitivityInputFile not provided");
920-
std::string sensiFile = inputPath + "/" + tmp;
911+
std::string sensiFile = (inputPath / tmp).generic_string();
921912
LOG("Get sensitivity data from file " << sensiFile);
922913
setSensitivityStreamFromFile(sensiFile);
923914
}
@@ -987,7 +978,7 @@ void OREAppInputParameters::loadParameters() {
987978

988979
tmp = params_->get("simm", "crif", false);
989980
if (tmp != "") {
990-
string file = inputPath + "/" + tmp;
981+
string file = (inputPath / tmp).generic_string();
991982
setCrifFromFile(file, csvEolChar(), csvSeparator(), '\"', csvEscapeChar());
992983
}
993984

@@ -1069,7 +1060,7 @@ void OREAppInputParameters::loadParameters() {
10691060
if (analytics().find("EXPOSURE") != analytics().end() || analytics().find("XVA") != analytics().end()) {
10701061
tmp = params_->get("simulation", "simulationConfigFile", false);
10711062
if (tmp != "") {
1072-
string simulationConfigFile = inputPath + "/" + tmp;
1063+
string simulationConfigFile = (inputPath / tmp).generic_string();
10731064
LOG("Loading simulation config from file" << simulationConfigFile);
10741065
setExposureSimMarketParamsFromFile(simulationConfigFile);
10751066
setCrossAssetModelDataFromFile(simulationConfigFile);
@@ -1083,7 +1074,7 @@ void OREAppInputParameters::loadParameters() {
10831074

10841075
tmp = params_->get("simulation", "pricingEnginesFile", false);
10851076
if (tmp != "") {
1086-
string pricingEnginesFile = inputPath + "/" + tmp;
1077+
string pricingEnginesFile = (inputPath / tmp).generic_string();
10871078
LOG("Load simulation pricing engine data from file: " << pricingEnginesFile);
10881079
setSimulationPricingEngineFromFile(pricingEnginesFile);
10891080
} else {
@@ -1092,7 +1083,7 @@ void OREAppInputParameters::loadParameters() {
10921083

10931084
tmp = params_->get("simulation", "amcPricingEnginesFile", false);
10941085
if (tmp != "") {
1095-
string pricingEnginesFile = inputPath + "/" + tmp;
1086+
string pricingEnginesFile = (inputPath / tmp).generic_string(); ;
10961087
LOG("Load amc pricing engine data from file: " << pricingEnginesFile);
10971088
setAmcPricingEngineFromFile(pricingEnginesFile);
10981089
} else {
@@ -1328,7 +1319,7 @@ void OREAppInputParameters::loadParameters() {
13281319

13291320
tmp = params_->get("xva", "deterministicInitialMarginFile", false);
13301321
if (tmp != "") {
1331-
string imFile = inputPath + "/" + tmp;
1322+
string imFile = (inputPath / tmp).generic_string();
13321323
LOG("Load initial margin evolution from file " << tmp);
13331324
setDeterministicInitialMarginFromFile(imFile);
13341325
}
@@ -1415,7 +1406,7 @@ void OREAppInputParameters::loadParameters() {
14151406

14161407
tmp = params_->get("xva", "creditMigrationConfig", false);
14171408
if (tmp != "") {
1418-
string file = inputPath + "/" + tmp;
1409+
string file = (inputPath / tmp).generic_string();
14191410
LOG("Loading credit migration config from file" << file);
14201411
setCreditSimulationParametersFromFile(file);
14211412
}
@@ -1479,7 +1470,7 @@ void OREAppInputParameters::loadParameters() {
14791470

14801471
tmp = params_->get("zeroToParSensiConversion", "marketConfigFile", false);
14811472
if (tmp != "") {
1482-
string file = inputPath + "/" + tmp;
1473+
string file = (inputPath / tmp).generic_string();
14831474
LOG("Loading par converions scenario sim market parameters from file" << file);
14841475
setParConversionSimMarketParamsFromFile(file);
14851476
} else {
@@ -1488,7 +1479,7 @@ void OREAppInputParameters::loadParameters() {
14881479

14891480
tmp = params_->get("zeroToParSensiConversion", "sensitivityConfigFile", false);
14901481
if (tmp != "") {
1491-
string file = inputPath + "/" + tmp;
1482+
string file = (inputPath / tmp).generic_string();
14921483
LOG("Load par conversion scenario data from file" << file);
14931484
setParConversionScenarioDataFromFile(file);
14941485
} else {
@@ -1497,7 +1488,7 @@ void OREAppInputParameters::loadParameters() {
14971488

14981489
tmp = params_->get("zeroToParSensiConversion", "pricingEnginesFile", false);
14991490
if (tmp != "") {
1500-
string file = inputPath + "/" + tmp;
1491+
string file = (inputPath / tmp).generic_string();
15011492
LOG("Load pricing engine data from file: " << file);
15021493
setParConversionPricingEngineFromFile(file);
15031494
} else {
@@ -1530,7 +1521,7 @@ void OREAppInputParameters::loadParameters() {
15301521

15311522
tmp = params_->get("scenarioStatistics", "simulationConfigFile", false);
15321523
if (tmp != "") {
1533-
string simulationConfigFile = inputPath + "/" + tmp;
1524+
string simulationConfigFile = (inputPath / tmp).generic_string();
15341525
LOG("Loading simulation config from file" << simulationConfigFile);
15351526
setExposureSimMarketParamsFromFile(simulationConfigFile);
15361527
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)