28 const char sep,
const string& filemode,
const std::vector<RiskFactorKey>& headerKeys)
29 : src_(src), fp_(nullptr), i_(0), sep_(sep), headerKeys_(headerKeys) {
30 open(filename, filemode);
34 const std::vector<RiskFactorKey>& headerKeys)
35 : fp_(nullptr), i_(0), sep_(sep), headerKeys_(headerKeys) {
36 open(filename, filemode);
40 QuantLib::ext::shared_ptr<ore::data::Report> report,
41 const std::vector<RiskFactorKey>& headerKeys)
42 : src_(src), report_(report), fp_(nullptr), i_(0), sep_(
','), headerKeys_(headerKeys) {}
45 fp_ = fopen(filename.c_str(), filemode.c_str());
46 QL_REQUIRE(
fp_,
"Error opening file " << filename <<
" for scenarios");
67 QL_REQUIRE(
src_,
"No ScenarioGenerator found.");
68 QuantLib::ext::shared_ptr<Scenario> s =
src_->next(d);
74 const Date d = s->asof();
80 QL_REQUIRE(
keys_.size() > 0,
"No keys in scenario");
82 for (Size i = 1; i <
keys_.size(); i++)
94 fprintf(
fp_,
"%c%.8f",
sep_, s->get(k));
101 QL_REQUIRE(
keys_.size() > 0,
"No keys in scenario");
104 report_->addColumn(
"Date",
string());
105 report_->addColumn(
"Scenario", Size());
106 report_->addColumn(
"Numeraire",
double(), 8);
117 report_->add(s->getNumeraire());
122 report_->add(QuantLib::Null<QuantLib::Real>());
std::vector< RiskFactorKey > headerKeys_
void writeScenario(const QuantLib::ext::shared_ptr< Scenario > &s, const bool writeHeader)
Write a single scenario.
void close()
Close the file if it is open, not normally needed by client code.
virtual QuantLib::ext::shared_ptr< Scenario > next(const Date &d) override
Return the next scenario for the given date.
virtual ~ScenarioWriter()
Destructor.
ScenarioWriter(const QuantLib::ext::shared_ptr< ScenarioGenerator > &src, const std::string &filename, const char sep=',', const string &filemode="w+", const std::vector< RiskFactorKey > &headerKeys={})
Constructor.
std::vector< RiskFactorKey > keys_
QuantLib::ext::shared_ptr< ScenarioGenerator > src_
QuantLib::ext::shared_ptr< ore::data::Report > report_
virtual void reset() override
Reset the generator so calls to next() return the first scenario.
void open(const std::string &filename, const std::string &filemode="w+")
std::string to_string(const LocationInfo &l)