23#include <ql/errors.hpp>
35 const QuantLib::ext::shared_ptr<ScenarioFactory>& scenarioFactory)
36 : scenarioFactory_(scenarioFactory), file_(fileName, true), finished_(false) {
39 QL_REQUIRE(
file_.
fields().size() >= 4,
"Need at least 4 columns in the file " << fileName);
40 QL_REQUIRE(
file_.
fields()[0] ==
"Date",
"First column must be 'Date' in the file " << fileName);
41 QL_REQUIRE(
file_.
fields()[1] ==
"Scenario",
"Second column should be 'Scenario' in the file " << fileName);
42 QL_REQUIRE(
file_.
fields()[2] ==
"Numeraire",
"Third column should be 'Numeraire' in the file " << fileName);
54 LOG(
"The file has been closed");
76 TLOG(
"Creating scenario for date " << io::iso_date(
date));
77 QuantLib::ext::shared_ptr<Scenario>
scenario =
80 for (Size k = 0; k <
keys_.size(); ++k) {
ore::data::CSVFileReader file_
Handle on the csv file.
~HistoricalScenarioFileReader() override
Destructor.
HistoricalScenarioFileReader(const std::string &fileName, const QuantLib::ext::shared_ptr< ScenarioFactory > &scenarioFactory)
QuantLib::ext::shared_ptr< Scenario > scenario() const override
Return the current scenario if reader is still valid and nullptr otherwise.
bool finished_
Flag indicating if the reader has no more scenarios to read.
std::vector< RiskFactorKey > keys_
The risk factor keys of the scenarios in the file.
QuantLib::Date date() const override
Return the current scenario's date if reader is still valid and Null<Date>() otherwise.
QuantLib::ext::shared_ptr< ScenarioFactory > scenarioFactory_
Scenario factory.
bool next() override
Return true if there is another Scenario to read and move to it.
const std::vector< std::string > & fields() const
std::string get(const std::string &field) const
SafeStack< ValueType > value
bool tryParseReal(const string &s, QuantLib::Real &result)
Date parseDate(const string &s)
Real parseReal(const string &s)
Class for reading historical scenarios from file.
RiskFactorKey parseRiskFactorKey(const string &str)
Size size(const ValueType &v)