Skip to content

Commit 64402f3

Browse files
Merge remote-tracking branch 'github/pr_abs_path' into github-205
2 parents f834974 + b11432c commit 64402f3

4 files changed

Lines changed: 48 additions & 56 deletions

File tree

OREAnalytics/orea/app/inputparameters.cpp

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

35-
vector<string> getFileNames(const string& fileString, const string& path) {
35+
vector<string> getFileNames(const string& fileString, const std::filesystem::path& path) {
3636
vector<string> fileNames;
3737
boost::split(fileNames, fileString, boost::is_any_of(",;"), boost::token_compress_on);
3838
for (auto it = fileNames.begin(); it < fileNames.end(); it++) {
3939
boost::trim(*it);
40-
*it = path + "/" + *it;
40+
*it = (path / *it).generic_string();
4141
}
4242
return fileNames;
4343
}
@@ -138,7 +138,7 @@ void InputParameters::setPortfolio(const std::string& xml) {
138138
portfolio_->fromXMLString(xml);
139139
}
140140

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

OREAnalytics/orea/app/inputparameters.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include <ored/portfolio/portfolio.hpp>
5252
#include <ored/portfolio/referencedata.hpp>
5353
#include <ored/utilities/csvfilereader.hpp>
54+
#include <boost/filesystem/path.hpp>
55+
#include <filesystem>
5456

5557
namespace ore {
5658
namespace analytics {
@@ -90,7 +92,7 @@ class InputParameters {
9092
void setTodaysMarketParams(const std::string& xml);
9193
void setTodaysMarketParamsFromFile(const std::string& fileName);
9294
void setPortfolio(const std::string& xml);
93-
void setPortfolioFromFile(const std::string& fileNameString, const std::string& inputPath);
95+
void setPortfolioFromFile(const std::string& fileNameString, const std::filesystem::path& inputPath);
9496
void setMarketConfigs(const std::map<std::string, std::string>& m);
9597
void setThreads(int i) { nThreads_ = i; }
9698
void setEntireMarket(bool b) { entireMarket_ = b; }
@@ -860,6 +862,7 @@ inline const std::string& InputParameters::marketConfig(const std::string& conte
860862
auto it = marketConfigs_.find(context);
861863
return (it != marketConfigs_.end() ? it->second : Market::defaultConfiguration);
862864
}
865+
std::vector<std::string> getFileNames(const std::string& fileString, const std::filesystem::path& path);
863866

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

OREAnalytics/orea/app/oreapp.cpp

Lines changed: 41 additions & 51 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 != "")
@@ -478,16 +468,16 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
478468

479469
QL_REQUIRE(params_->hasGroup("setup"), "parameter group 'setup' missing");
480470

481-
std::string inputPath = params_->get("setup", "inputPath");
471+
filesystem::path inputPath = params_->get("setup", "inputPath");
482472
std::string outputPath = params_->get("setup", "outputPath");
483473

484474
// Load calendar adjustments
485475
std::string tmp = params_->get("setup", "calendarAdjustment", false);
486476
if (tmp != "") {
487477
CalendarAdjustmentConfig calendarAdjustments;
488-
string calendarAdjustmentFile = inputPath + "/" + tmp;
478+
filesystem::path calendarAdjustmentFile = inputPath / tmp;
489479
LOG("Loading calendar adjustments from file: " << calendarAdjustmentFile);
490-
calendarAdjustments.fromFile(calendarAdjustmentFile);
480+
calendarAdjustments.fromFile(calendarAdjustmentFile.generic_string());
491481
} else {
492482
WLOG("Calendar adjustments not found, using defaults");
493483
}
@@ -496,9 +486,9 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
496486
tmp = params_->get("setup", "currencyConfiguration", false);
497487
if (tmp != "") {
498488
CurrencyConfig currencyConfig;
499-
string currencyConfigFile = inputPath + "/" + tmp;
489+
filesystem::path currencyConfigFile = inputPath / tmp;
500490
LOG("Loading currency configurations from file: " << currencyConfigFile);
501-
currencyConfig.fromFile(currencyConfigFile);
491+
currencyConfig.fromFile(currencyConfigFile.generic_string());
502492
} else {
503493
WLOG("Currency configurations not found, using defaults");
504494
}
@@ -573,61 +563,61 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
573563

574564
tmp = params_->get("setup", "referenceDataFile", false);
575565
if (tmp != "") {
576-
string refDataFile = inputPath + "/" + tmp;
566+
filesystem::path refDataFile = inputPath / tmp;
577567
LOG("Loading reference data from file: " << refDataFile);
578-
inputs->setRefDataManagerFromFile(refDataFile);
568+
inputs->setRefDataManagerFromFile(refDataFile.generic_string());
579569
} else {
580570
WLOG("Reference data not found");
581571
}
582572

583573
tmp = params_->get("setup", "scriptLibrary", false);
584574
if (tmp != "") {
585-
string scriptFile = inputPath + "/" + tmp;
575+
filesystem::path scriptFile = inputPath / tmp;
586576
LOG("Loading script library from file: " << scriptFile);
587-
inputs->setScriptLibraryFromFile(scriptFile);
577+
inputs->setScriptLibraryFromFile(scriptFile.generic_string());
588578
}
589579
else {
590580
WLOG("Script library not loaded");
591581
}
592582

593583
if (params_->has("setup", "conventionsFile") && params_->get("setup", "conventionsFile") != "") {
594-
string conventionsFile = inputPath + "/" + params_->get("setup", "conventionsFile");
584+
filesystem::path conventionsFile = inputPath / params_->get("setup", "conventionsFile");
595585
LOG("Loading conventions from file: " << conventionsFile);
596-
inputs->setConventionsFromFile(conventionsFile);
586+
inputs->setConventionsFromFile(conventionsFile.generic_string());
597587
} else {
598588
ALOG("Conventions not found");
599589
}
600590

601591
if (params_->has("setup", "iborFallbackConfig") && params_->get("setup", "iborFallbackConfig") != "") {
602-
std::string tmp = inputPath + "/" + params_->get("setup", "iborFallbackConfig");
592+
filesystem::path tmp = inputPath / params_->get("setup", "iborFallbackConfig");
603593
LOG("Loading Ibor fallback config from file: " << tmp);
604-
inputs->setIborFallbackConfigFromFile(tmp);
594+
inputs->setIborFallbackConfigFromFile(tmp.generic_string());
605595
} else {
606596
WLOG("Using default Ibor fallback config");
607597
}
608598

609599
if (params_->has("setup", "curveConfigFile") && params_->get("setup", "curveConfigFile") != "") {
610-
string curveConfigFile = inputPath + "/" + params_->get("setup", "curveConfigFile");
600+
filesystem::path curveConfigFile = inputPath / params_->get("setup", "curveConfigFile");
611601
LOG("Load curve configurations from file: ");
612-
inputs->setCurveConfigsFromFile(curveConfigFile);
602+
inputs->setCurveConfigsFromFile(curveConfigFile.generic_string());
613603
} else {
614604
ALOG("no curve configs loaded");
615605
}
616606

617607
tmp = params_->get("setup", "pricingEnginesFile", false);
618608
if (tmp != "") {
619-
string pricingEnginesFile = inputPath + "/" + tmp;
609+
filesystem::path pricingEnginesFile = inputPath / tmp;
620610
LOG("Load pricing engine data from file: " << pricingEnginesFile);
621-
inputs->setPricingEngineFromFile(pricingEnginesFile);
611+
inputs->setPricingEngineFromFile(pricingEnginesFile.generic_string());
622612
} else {
623613
ALOG("Pricing engine data not found");
624614
}
625615

626616
tmp = params_->get("setup", "marketConfigFile", false);
627617
if (tmp != "") {
628-
string marketConfigFile = inputPath + "/" + tmp;
618+
filesystem::path marketConfigFile = inputPath / tmp;
629619
LOG("Loading today's market parameters from file" << marketConfigFile);
630-
inputs->setTodaysMarketParamsFromFile(marketConfigFile);
620+
inputs->setTodaysMarketParamsFromFile(marketConfigFile.generic_string());
631621
} else {
632622
ALOG("Today's market parameters not found");
633623
}
@@ -736,7 +726,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
736726

737727
tmp = params_->get("sensitivity", "marketConfigFile", false);
738728
if (tmp != "") {
739-
string file = inputPath + "/" + tmp;
729+
string file = (inputPath / tmp).generic_string();
740730
LOG("Loading sensitivity scenario sim market parameters from file" << file);
741731
inputs->setSensiSimMarketParamsFromFile(file);
742732
} else {
@@ -745,7 +735,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
745735

746736
tmp = params_->get("sensitivity", "sensitivityConfigFile", false);
747737
if (tmp != "") {
748-
string file = inputPath + "/" + tmp;
738+
string file = (inputPath / tmp).generic_string();
749739
LOG("Load sensitivity scenario data from file" << file);
750740
inputs->setSensiScenarioDataFromFile(file);
751741
} else {
@@ -754,7 +744,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
754744

755745
tmp = params_->get("sensitivity", "pricingEnginesFile", false);
756746
if (tmp != "") {
757-
string file = inputPath + "/" + tmp;
747+
string file = (inputPath / tmp).generic_string();
758748
LOG("Load pricing engine data from file: " << file);
759749
inputs->setSensiPricingEngineFromFile(file);
760750
} else {
@@ -805,7 +795,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
805795
inputs->setStressPricingEngine(inputs->pricingEngine());
806796
tmp = params_->get("stress", "marketConfigFile", false);
807797
if (tmp != "") {
808-
string file = inputPath + "/" + tmp;
798+
string file = (inputPath / tmp).generic_string();
809799
LOG("Loading stress test scenario sim market parameters from file" << file);
810800
inputs->setStressSimMarketParamsFromFile(file);
811801
} else {
@@ -814,7 +804,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
814804

815805
tmp = params_->get("stress", "stressConfigFile", false);
816806
if (tmp != "") {
817-
string file = inputPath + "/" + tmp;
807+
string file = (inputPath / tmp).generic_string();
818808
LOG("Load stress test scenario data from file" << file);
819809
inputs->setStressScenarioDataFromFile(file);
820810
} else {
@@ -823,7 +813,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
823813

824814
tmp = params_->get("stress", "pricingEnginesFile", false);
825815
if (tmp != "") {
826-
string file = inputPath + "/" + tmp;
816+
string file = (inputPath / tmp).generic_string();
827817
LOG("Load pricing engine data from file: " << file);
828818
inputs->setStressPricingEngineFromFile(file);
829819
} else {
@@ -873,13 +863,13 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
873863

874864
tmp = params_->get("parametricVar", "covarianceInputFile", false);
875865
QL_REQUIRE(tmp != "", "covarianceInputFile not provided");
876-
std::string covFile = inputPath + "/" + tmp;
866+
std::string covFile = (inputPath / tmp).generic_string();
877867
LOG("Load Covariance Data from file " << covFile);
878868
inputs->setCovarianceDataFromFile(covFile);
879869

880870
tmp = params_->get("parametricVar", "sensitivityInputFile", false);
881871
QL_REQUIRE(tmp != "", "sensitivityInputFile not provided");
882-
std::string sensiFile = inputPath + "/" + tmp;
872+
std::string sensiFile = (inputPath / tmp).generic_string();
883873
LOG("Get sensitivity data from file " << sensiFile);
884874
inputs->setSensitivityStreamFromFile(sensiFile);
885875
}
@@ -902,7 +892,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
902892

903893
tmp = params_->get("simm", "crif", false);
904894
if (tmp != "") {
905-
string file = inputPath + "/" + tmp;
895+
string file = (inputPath / tmp).generic_string();
906896
inputs->setCrifFromFile(file, inputs->csvEolChar(), inputs->csvSeparator(), '\"', inputs->csvEscapeChar());
907897
}
908898

@@ -986,7 +976,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
986976
inputs->analytics().find("XVA") != inputs->analytics().end()) {
987977
tmp = params_->get("simulation", "simulationConfigFile", false) ;
988978
if (tmp != "") {
989-
string simulationConfigFile = inputPath + "/" + tmp;
979+
string simulationConfigFile = (inputPath / tmp).generic_string();
990980
LOG("Loading simulation config from file" << simulationConfigFile);
991981
inputs->setExposureSimMarketParamsFromFile(simulationConfigFile);
992982
inputs->setCrossAssetModelDataFromFile(simulationConfigFile);
@@ -1001,7 +991,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
1001991

1002992
tmp = params_->get("simulation", "pricingEnginesFile", false);
1003993
if (tmp != "") {
1004-
string pricingEnginesFile = inputPath + "/" + tmp;
994+
string pricingEnginesFile = (inputPath / tmp).generic_string();
1005995
LOG("Load simulation pricing engine data from file: " << pricingEnginesFile);
1006996
inputs->setSimulationPricingEngineFromFile(pricingEnginesFile);
1007997
} else {
@@ -1010,7 +1000,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
10101000

10111001
tmp = params_->get("simulation", "amcPricingEnginesFile", false);
10121002
if (tmp != "") {
1013-
string pricingEnginesFile = inputPath + "/" + tmp;
1003+
string pricingEnginesFile = (inputPath / tmp).generic_string(); ;
10141004
LOG("Load amc pricing engine data from file: " << pricingEnginesFile);
10151005
inputs->setAmcPricingEngineFromFile(pricingEnginesFile);
10161006
} else {
@@ -1084,8 +1074,8 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
10841074
if (inputs->analytics().find("XVA") != inputs->analytics().end()) {
10851075
tmp = params_->get("xva", "csaFile", false);
10861076
QL_REQUIRE(tmp != "", "Netting set manager is required for XVA");
1087-
string csaFile = inputPath + "/" + tmp;
1088-
LOG("Loading netting and csa data from file " << csaFile);
1077+
string csaFile = (inputPath / tmp).generic_string();
1078+
LOG("Loading netting and csa data from file" << csaFile);
10891079
inputs->setNettingSetManagerFromFile(csaFile);
10901080

10911081
tmp = params_->get("xva", "collateralBalancesFile", false);
@@ -1252,7 +1242,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
12521242

12531243
tmp = params_->get("xva", "deterministicInitialMarginFile", false);
12541244
if (tmp != "") {
1255-
string imFile = inputPath + "/" + tmp;
1245+
string imFile = (inputPath / tmp).generic_string();
12561246
LOG("Load initial margin evolution from file " << tmp);
12571247
inputs->setDeterministicInitialMarginFromFile(imFile);
12581248
}
@@ -1339,7 +1329,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
13391329

13401330
tmp = params_->get("xva", "creditMigrationConfig", false);
13411331
if (tmp != "") {
1342-
string file = inputPath + "/" + tmp;
1332+
string file = (inputPath / tmp).generic_string();
13431333
LOG("Loading credit migration config from file" << file);
13441334
inputs->setCreditSimulationParametersFromFile(file);
13451335
}
@@ -1368,7 +1358,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
13681358

13691359
tmp = params_->get("zeroToParSensiConversion", "sensitivityInputFile", false);
13701360
if (tmp != "") {
1371-
inputs->setParConversionInputFile(inputPath + "/" + tmp);
1361+
inputs->setParConversionInputFile((inputPath / tmp).generic_string());
13721362
}
13731363

13741364
tmp = params_->get("zeroToParSensiConversion", "idColumn", false);
@@ -1403,7 +1393,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
14031393

14041394
tmp = params_->get("zeroToParSensiConversion", "marketConfigFile", false);
14051395
if (tmp != "") {
1406-
string file = inputPath + "/" + tmp;
1396+
string file = (inputPath / tmp).generic_string();
14071397
LOG("Loading par converions scenario sim market parameters from file" << file);
14081398
inputs->setParConversionSimMarketParamsFromFile(file);
14091399
} else {
@@ -1412,7 +1402,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
14121402

14131403
tmp = params_->get("zeroToParSensiConversion", "sensitivityConfigFile", false);
14141404
if (tmp != "") {
1415-
string file = inputPath + "/" + tmp;
1405+
string file = (inputPath / tmp).generic_string();
14161406
LOG("Load par conversion scenario data from file" << file);
14171407
inputs->setParConversionScenarioDataFromFile(file);
14181408
} else {
@@ -1421,7 +1411,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
14211411

14221412
tmp = params_->get("zeroToParSensiConversion", "pricingEnginesFile", false);
14231413
if (tmp != "") {
1424-
string file = inputPath + "/" + tmp;
1414+
string file = (inputPath / tmp).generic_string();
14251415
LOG("Load pricing engine data from file: " << file);
14261416
inputs->setParConversionPricingEngineFromFile(file);
14271417
} else {
@@ -1455,7 +1445,7 @@ void OREApp::buildInputParameters(boost::shared_ptr<InputParameters> inputs,
14551445

14561446
tmp = params_->get("scenarioStatistics", "simulationConfigFile", false);
14571447
if (tmp != "") {
1458-
string simulationConfigFile = inputPath + "/" + tmp;
1448+
string simulationConfigFile = (inputPath / tmp).generic_string();
14591449
LOG("Loading simulation config from file" << simulationConfigFile);
14601450
inputs->setExposureSimMarketParamsFromFile(simulationConfigFile);
14611451
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)