Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
oreapp.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016-2023 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 orea/app/oreapp.hpp
20 \brief Open Risk Engine App
21 \ingroup app
22 */
23
24#pragma once
25
29
30#include <boost/make_shared.hpp>
31#include <boost/timer/timer.hpp>
32
33namespace ore {
34namespace analytics {
35using namespace ore::data;
36
37//! Orchestrates the processes covered by ORE, data loading, analytics and reporting
38/*! \ingroup app
39 */
40class OREApp {
41public:
42 //! Constructor that uses ORE parameters and input data from files
43 OREApp(QuantLib::ext::shared_ptr<Parameters> params, bool console = false,
44 const boost::filesystem::path& logRootPath = boost::filesystem::path())
45 : params_(params), inputs_(nullptr), console_(console), logRootPath_(logRootPath) {}
46
47 //! Constructor that assumes we have already assembled input parameters via API
48 OREApp(const QuantLib::ext::shared_ptr<InputParameters>& inputs, const std::string& logFile, Size logLevel = 31,
49 bool console = false, const boost::filesystem::path& logRootPath = boost::filesystem::path())
50 : params_(nullptr), inputs_(inputs), logFile_(logFile), logMask_(logLevel), console_(console),
51 logRootPath_(logRootPath) {}
52
53 //! Destructor
54 virtual ~OREApp();
55
56 //! Runs analytics and generates reports after using the first OREApp c'tor
57 virtual void run();
58
59 //! Runs analytics and generates reports after using the second OREApp c'tor
60 void run(const std::vector<std::string>& marketData,
61 const std::vector<std::string>& fixingData);
62
63 QuantLib::ext::shared_ptr<InputParameters> getInputs() { return inputs_; }
64
65 std::set<std::string> getAnalyticTypes();
66 std::set<std::string> getSupportedAnalyticTypes();
67 const QuantLib::ext::shared_ptr<Analytic>& getAnalytic(std::string type);
68
69 std::set<std::string> getReportNames();
70 QuantLib::ext::shared_ptr<PlainInMemoryReport> getReport(std::string reportName);
71
72 std::set<std::string> getCubeNames();
73 QuantLib::ext::shared_ptr<NPVCube> getCube(std::string cubeName);
74
75 std::set<std::string> getMarketCubeNames();
76 QuantLib::ext::shared_ptr<AggregationScenarioData> getMarketCube(std::string cubeName);
77
78 std::vector<std::string> getErrors();
79
80 //! time for executing run(...) in seconds
81 Real getRunTime();
82
83 std::string version();
84
85protected:
86 virtual void analytics();
87
88 //! Populate InputParameters object from classic ORE key-value pairs in Parameters
89 void buildInputParameters(QuantLib::ext::shared_ptr<InputParameters> inputs,
90 const QuantLib::ext::shared_ptr<Parameters>& params);
91 QuantLib::ext::shared_ptr<CSVLoader> buildCsvLoader(const QuantLib::ext::shared_ptr<Parameters>& params);
92 //! set up logging
93 void setupLog(const std::string& path, const std::string& file, QuantLib::Size mask,
94 const boost::filesystem::path& logRootPath, const std::string& progressLogFile = "",
95 QuantLib::Size progressLogRotationSize = 100 * 1024 * 1024, bool progressLogToConsole = false,
96 const std::string& structuredLogFile = "", QuantLib::Size structuredLogRotationSize = 100 * 1024 * 1024);
97 //! remove logs
98 void closeLog();
99
100 void initFromParams();
101 void initFromInputs();
102
103 //! ORE Input parameters
104 QuantLib::ext::shared_ptr<Parameters> params_;
105 QuantLib::ext::shared_ptr<InputParameters> inputs_;
106 QuantLib::ext::shared_ptr<OutputParameters> outputs_;
107
108 QuantLib::ext::shared_ptr<AnalyticsManager> analyticsManager_;
109 QuantLib::ext::shared_ptr<StructuredLogger> structuredLogger_;
110 boost::timer::cpu_timer runTimer_;
111
112 //! Logging
113 string logFile_;
117 boost::filesystem::path logRootPath_;
118 string progressLogFile_ = "";
119 QuantLib::Size progressLogRotationSize_ = 100 * 1024 * 1024;
122 QuantLib::Size structuredLogRotationSize_ = 100 * 1024 * 1024;
123
124 // Cached error messages of a run
125 std::vector<std::string> errorMessages_;
126};
127
129public:
130 OREAppInputParameters(const QuantLib::ext::shared_ptr<Parameters>& params) : params_(params) {}
131
132 // load input parameters
133 virtual void loadParameters() override;
134
135 //! write out parameters
136 virtual void writeOutParameters() override{};
137
138private:
139 QuantLib::ext::shared_ptr<Parameters> params_;
140};
141
142} // namespace analytics
143} // namespace ore
ORE Analytics Manager.
Base class for input data, also exposed via SWIG.
Orchestrates the processes covered by ORE, data loading, analytics and reporting.
Definition: oreapp.hpp:40
QuantLib::ext::shared_ptr< AggregationScenarioData > getMarketCube(std::string cubeName)
Definition: oreapp.cpp:152
QuantLib::Size structuredLogRotationSize_
Definition: oreapp.hpp:122
void setupLog(const std::string &path, const std::string &file, QuantLib::Size mask, const boost::filesystem::path &logRootPath, const std::string &progressLogFile="", QuantLib::Size progressLogRotationSize=100 *1024 *1024, bool progressLogToConsole=false, const std::string &structuredLogFile="", QuantLib::Size structuredLogRotationSize=100 *1024 *1024)
set up logging
Definition: oreapp.cpp:523
boost::timer::cpu_timer runTimer_
Definition: oreapp.hpp:110
virtual void run()
Runs analytics and generates reports after using the first OREApp c'tor.
Definition: oreapp.cpp:398
std::vector< std::string > getErrors()
Definition: oreapp.cpp:163
virtual ~OREApp()
Destructor.
Definition: oreapp.cpp:393
Real getRunTime()
time for executing run(...) in seconds
Definition: oreapp.cpp:167
QuantLib::ext::shared_ptr< AnalyticsManager > analyticsManager_
Definition: oreapp.hpp:108
QuantLib::ext::shared_ptr< PlainInMemoryReport > getReport(std::string reportName)
Definition: oreapp.cpp:96
QuantLib::ext::shared_ptr< InputParameters > getInputs()
Definition: oreapp.hpp:63
QuantLib::ext::shared_ptr< OutputParameters > outputs_
Definition: oreapp.hpp:106
std::set< std::string > getMarketCubeNames()
Definition: oreapp.cpp:135
std::vector< std::string > errorMessages_
Definition: oreapp.hpp:125
const QuantLib::ext::shared_ptr< Analytic > & getAnalytic(std::string type)
Definition: oreapp.cpp:74
QuantLib::Size progressLogRotationSize_
Definition: oreapp.hpp:119
QuantLib::ext::shared_ptr< CSVLoader > buildCsvLoader(const QuantLib::ext::shared_ptr< Parameters > &params)
Definition: oreapp.cpp:172
QuantLib::ext::shared_ptr< Parameters > params_
ORE Input parameters.
Definition: oreapp.hpp:104
virtual void analytics()
Definition: oreapp.cpp:218
boost::filesystem::path logRootPath_
Definition: oreapp.hpp:117
std::set< std::string > getSupportedAnalyticTypes()
Definition: oreapp.cpp:69
OREApp(const QuantLib::ext::shared_ptr< InputParameters > &inputs, const std::string &logFile, Size logLevel=31, bool console=false, const boost::filesystem::path &logRootPath=boost::filesystem::path())
Constructor that assumes we have already assembled input parameters via API.
Definition: oreapp.hpp:48
std::string version()
Definition: oreapp.cpp:564
void closeLog()
remove logs
Definition: oreapp.cpp:562
QuantLib::ext::shared_ptr< NPVCube > getCube(std::string cubeName)
Definition: oreapp.cpp:124
string logFile_
Logging.
Definition: oreapp.hpp:113
OREApp(QuantLib::ext::shared_ptr< Parameters > params, bool console=false, const boost::filesystem::path &logRootPath=boost::filesystem::path())
Constructor that uses ORE parameters and input data from files.
Definition: oreapp.hpp:43
QuantLib::ext::shared_ptr< StructuredLogger > structuredLogger_
Definition: oreapp.hpp:109
std::set< std::string > getReportNames()
Definition: oreapp.cpp:79
std::set< std::string > getCubeNames()
Definition: oreapp.cpp:107
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: oreapp.hpp:105
std::set< std::string > getAnalyticTypes()
Definition: oreapp.cpp:64
void buildInputParameters(QuantLib::ext::shared_ptr< InputParameters > inputs, const QuantLib::ext::shared_ptr< Parameters > &params)
Populate InputParameters object from classic ORE key-value pairs in Parameters.
OREAppInputParameters(const QuantLib::ext::shared_ptr< Parameters > &params)
Definition: oreapp.hpp:130
QuantLib::ext::shared_ptr< Parameters > params_
Definition: oreapp.hpp:139
virtual void loadParameters() override
Definition: oreapp.cpp:566
virtual void writeOutParameters() override
write out parameters
Definition: oreapp.hpp:136
Input Parameters.
Open Risk Engine setup and analytics choice.