Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
scenariowriter.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file scenario/scenariowriter.hpp
20 \brief ScenarioWriter class
21 \ingroup scenario
22*/
23
24#pragma once
25
29
30namespace ore {
31namespace analytics {
32
33//! Class for writing scenarios to file.
35public:
36 //! Constructor
37 ScenarioWriter(const QuantLib::ext::shared_ptr<ScenarioGenerator>& src, const std::string& filename, const char sep = ',',
38 const string& filemode = "w+", const std::vector<RiskFactorKey>& headerKeys = {});
39
40 //! Constructor to write single scenarios
41 ScenarioWriter(const std::string& filename, const char sep = ',', const string& filemode = "w+",
42 const std::vector<RiskFactorKey>& headerKeys = {});
43
44 //! Constructor to write into an in-memory report for later io
45 ScenarioWriter(const QuantLib::ext::shared_ptr<ScenarioGenerator>& src, QuantLib::ext::shared_ptr<ore::data::Report> report,
46 const std::vector<RiskFactorKey>& headerKeys = {});
47
48 //! Destructor
49 virtual ~ScenarioWriter();
50
51 //! Return the next scenario for the given date.
52 virtual QuantLib::ext::shared_ptr<Scenario> next(const Date& d) override;
53
54 //! Write a single scenario
55 void writeScenario(const QuantLib::ext::shared_ptr<Scenario>& s, const bool writeHeader);
56
57 //! Reset the generator so calls to next() return the first scenario.
58 virtual void reset() override;
59
60 //! Close the file if it is open, not normally needed by client code
61 void close();
62
63private:
64 void open(const std::string& filename, const std::string& filemode = "w+");
65
66 QuantLib::ext::shared_ptr<ScenarioGenerator> src_;
67 std::vector<RiskFactorKey> keys_;
68 QuantLib::ext::shared_ptr<ore::data::Report> report_;
69 FILE* fp_;
71 Size i_;
72 const char sep_ = ',';
73 std::vector<RiskFactorKey> headerKeys_;
74};
75} // namespace analytics
76} // namespace ore
Scenario generator base class.
Class for writing scenarios to file.
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.
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+")
Scenario class.
Scenario generator base classes.