19#include <boost/algorithm/string.hpp>
35 const QuantLib::ext::shared_ptr<ScenarioFactory> scenarioFactory,
const char sep)
36 : sep_(sep), filename_(filename), scenarioFactory_(scenarioFactory) {
43 QL_REQUIRE(!
file_.eof(),
"error reading file: No header found in scenariofile" <<
filename_);
47 string strsep(1,
sep_);
48 vector<string> tokens;
49 boost::split(tokens, line, boost::is_any_of(strsep), boost::token_compress_on);
50 QL_REQUIRE(tokens.size() > 3,
"No RiskFactorKeys found in " <<
filename_);
51 keys_.resize(tokens.size() - 3);
52 for (Size i = 3; i < tokens.size(); i++) {
58 QL_REQUIRE(!
file_.eof(),
"unexpected end of scenario file " <<
filename_);
63 vector<string> tokens;
65 string strsep(1,
sep_);
66 boost::split(tokens, line, boost::is_any_of(strsep), boost::token_compress_on);
69 QL_REQUIRE(
to_string(d) == tokens[0],
"Incompatible date " << tokens[0] <<
" in " <<
filename_);
72 const QuantLib::ext::shared_ptr<Scenario> scenario =
scenarioFactory_->buildScenario(d,
true);
75 QL_REQUIRE(
keys_.size() == tokens.size() - 3,
"Erroneus line in " <<
filename_);
76 for (Size i = 3; i < tokens.size(); i++) {
84 file_.seekg(std::ios::beg);
86 getline(
file_, dummy);
const QuantLib::ext::shared_ptr< ScenarioFactory > scenarioFactory_
CSVScenarioGenerator(const std::string &filename, const QuantLib::ext::shared_ptr< ScenarioFactory > scenarioFactory, const char sep=',')
const std::string & filename_
virtual QuantLib::ext::shared_ptr< Scenario > next(const Date &d) override
Return the next scenario for the given date.
virtual ~CSVScenarioGenerator()
vector< RiskFactorKey > keys_
virtual void reset() override
Reset the generator so calls to next() return the first scenario.
Real parseReal(const string &s)
RiskFactorKey parseRiskFactorKey(const string &str)
std::string to_string(const LocationInfo &l)