Class for writing scenarios to file.
More...
#include <orea/scenario/scenariowriter.hpp>
|
| 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. More...
|
|
| ScenarioWriter (const std::string &filename, const char sep=',', const string &filemode="w+", const std::vector< RiskFactorKey > &headerKeys={}) |
| Constructor to write single scenarios. More...
|
|
| ScenarioWriter (const QuantLib::ext::shared_ptr< ScenarioGenerator > &src, QuantLib::ext::shared_ptr< ore::data::Report > report, const std::vector< RiskFactorKey > &headerKeys={}) |
| Constructor to write into an in-memory report for later io. More...
|
|
virtual | ~ScenarioWriter () |
| Destructor. More...
|
|
virtual QuantLib::ext::shared_ptr< Scenario > | next (const Date &d) override |
| Return the next scenario for the given date. More...
|
|
void | writeScenario (const QuantLib::ext::shared_ptr< Scenario > &s, const bool writeHeader) |
| Write a single scenario. More...
|
|
virtual void | reset () override |
| Reset the generator so calls to next() return the first scenario. More...
|
|
void | close () |
| Close the file if it is open, not normally needed by client code. More...
|
|
virtual | ~ScenarioGenerator () |
| Default destructor. More...
|
|
virtual QuantLib::ext::shared_ptr< Scenario > | next (const Date &d)=0 |
| Return the next scenario for the given date. More...
|
|
virtual void | reset ()=0 |
| Reset the generator so calls to next() return the first scenario. More...
|
|
|
void | open (const std::string &filename, const std::string &filemode="w+") |
|
Class for writing scenarios to file.
Definition at line 34 of file scenariowriter.hpp.
◆ ScenarioWriter() [1/3]
Constructor.
Definition at line 27 of file scenariowriter.cpp.
30 open(filename, filemode);
31}
std::vector< RiskFactorKey > headerKeys_
QuantLib::ext::shared_ptr< ScenarioGenerator > src_
void open(const std::string &filename, const std::string &filemode="w+")
◆ ScenarioWriter() [2/3]
ScenarioWriter |
( |
const std::string & |
filename, |
|
|
const char |
sep = ',' , |
|
|
const string & |
filemode = "w+" , |
|
|
const std::vector< RiskFactorKey > & |
headerKeys = {} |
|
) |
| |
Constructor to write single scenarios.
Definition at line 33 of file scenariowriter.cpp.
36 open(filename, filemode);
37}
◆ ScenarioWriter() [3/3]
Constructor to write into an in-memory report for later io.
Definition at line 39 of file scenariowriter.cpp.
QuantLib::ext::shared_ptr< ore::data::Report > report_
◆ ~ScenarioWriter()
Destructor.
Definition at line 49 of file scenariowriter.cpp.
void close()
Close the file if it is open, not normally needed by client code.
◆ next()
QuantLib::ext::shared_ptr< Scenario > next |
( |
const Date & |
d | ) |
|
|
overridevirtual |
Return the next scenario for the given date.
Implements ScenarioGenerator.
Definition at line 66 of file scenariowriter.cpp.
66 {
67 QL_REQUIRE(
src_,
"No ScenarioGenerator found.");
68 QuantLib::ext::shared_ptr<Scenario> s =
src_->next(d);
70 return s;
71}
void writeScenario(const QuantLib::ext::shared_ptr< Scenario > &s, const bool writeHeader)
Write a single scenario.
◆ writeScenario()
void writeScenario |
( |
const QuantLib::ext::shared_ptr< Scenario > & |
s, |
|
|
const bool |
writeHeader |
|
) |
| |
Write a single scenario.
Definition at line 73 of file scenariowriter.cpp.
73 {
74 const Date d = s->asof();
75
79 if (writeHeader) {
80 QL_REQUIRE(
keys_.size() > 0,
"No keys in scenario");
82 for (Size i = 1; i <
keys_.size(); i++)
85
86
88 }
91
94 fprintf(
fp_,
"%c%.8f",
sep_, s->get(k));
97 }
98
100 if (writeHeader) {
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);
109
111 }
117 report_->add(s->getNumeraire());
119 if (s->has(k))
121 else
122 report_->add(QuantLib::Null<QuantLib::Real>());
123 }
124 }
125}
std::vector< RiskFactorKey > keys_
std::string to_string(const LocationInfo &l)
◆ reset()
◆ close()
Close the file if it is open, not normally needed by client code.
Definition at line 57 of file scenariowriter.cpp.
◆ open()
void open |
( |
const std::string & |
filename, |
|
|
const std::string & |
filemode = "w+" |
|
) |
| |
|
private |
Definition at line 44 of file scenariowriter.cpp.
44 {
45 fp_ = fopen(filename.c_str(), filemode.c_str());
46 QL_REQUIRE(
fp_,
"Error opening file " << filename <<
" for scenarios");
47}
◆ src_
◆ keys_
◆ report_
◆ fp_
◆ firstDate_
◆ i_
◆ sep_
◆ headerKeys_