Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
analytic.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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/analytic.hpp
20 \brief ORE Analytics Manager
21*/
22
23#pragma once
24
29
36
39
40#include <boost/any.hpp>
41#include <iostream>
42
43namespace ore {
44namespace analytics {
45
46class Analytic {
47public:
48 class Impl;
49
50 typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<ore::data::InMemoryReport>>>
52
53 typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<NPVCube>>>
55
56 typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<AggregationScenarioData>>>
58
59 typedef std::map<std::string, std::map<std::string, QuantLib::ext::shared_ptr<StressTestScenarioData>>>
61
63 //! Booleans to determine if these configs are needed
68 QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters> todaysMarketParams;
69 QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters> simMarketParams;
70 QuantLib::ext::shared_ptr<ore::analytics::SensitivityScenarioData> sensiScenarioData;
71 QuantLib::ext::shared_ptr<ore::analytics::ScenarioGeneratorData> scenarioGeneratorData;
72 QuantLib::ext::shared_ptr<ore::analytics::CrossAssetModelData> crossAssetModelData;
73 QuantLib::ext::shared_ptr<CurveConfigurations> curveConfig;
74 QuantLib::ext::shared_ptr<ore::data::EngineData> engineData;
75 QuantLib::Date asofDate;
76 };
77
78 //! Constructors
80 Analytic(//! Concrete implementation of the analytic
81 std::unique_ptr<Impl> impl,
82 //! The types of all (sub) analytics covered by this Analytic object
83 //! e.g. NPV, CASHFLOW, CASHFLOWNPV, etc., covered by the PricingAnalytic
84 const std::set<std::string>& analyticTypes,
85 //! Any inputs required by this Analytic
86 const QuantLib::ext::shared_ptr<InputParameters>& inputs,
87 //! Flag to indicate whether a simulation config file is required for this analytic
88 bool simulationConfig = false,
89 //! Flag to indicate whether a sensitivity config file is required for this analytic
90 bool sensitivityConfig = false,
91 //! Flag to indicate whether a scenario generator config file is required for this analytic
92 bool scenarioGeneratorConfig = false,
93 //! Flag to indicate whether a cross asset model config file is required for this analytic
94 bool crossAssetModelConfig = false);
95
96 virtual ~Analytic() {}
97
98 //! Run only those analytic types that are inclcuded in the runTypes vector, run all if the runType vector is empty
99 virtual void runAnalytic(const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
100 const std::set<std::string>& runTypes = {});
101
102 // we can build configurations here (today's market params, scenario sim market params, sensitivity scenasrio data)
103 virtual void buildConfigurations(const bool = false){};
104 virtual void setUpConfigurations();
105
106 virtual void buildMarket(const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
107 const bool marketRequired = true);
108 virtual void buildPortfolio();
109 virtual void marketCalibration(const QuantLib::ext::shared_ptr<MarketCalibrationReportBase>& mcr = nullptr);
110 virtual void modifyPortfolio() {}
111 virtual void replaceTrades() {}
112
113 //! Inspectors
114 const std::string label() const;
115 const std::set<std::string>& analyticTypes() const { return types_; }
116 const QuantLib::ext::shared_ptr<InputParameters>& inputs() const { return inputs_; }
117 const QuantLib::ext::shared_ptr<ore::data::Market>& market() const { return market_; };
118 // To allow SWIG wrapping
119 QuantLib::ext::shared_ptr<MarketImpl> getMarket() const {
120 return QuantLib::ext::dynamic_pointer_cast<MarketImpl>(market_);
121 }
122 const QuantLib::ext::shared_ptr<ore::data::Portfolio>& portfolio() const { return portfolio_; };
123 void setInputs(const QuantLib::ext::shared_ptr<InputParameters>& inputs) { inputs_ = inputs; }
124 void setMarket(const QuantLib::ext::shared_ptr<ore::data::Market>& market) { market_ = market; };
125 void setPortfolio(const QuantLib::ext::shared_ptr<ore::data::Portfolio>& portfolio) { portfolio_ = portfolio; };
126 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> todaysMarketParams();
127 const QuantLib::ext::shared_ptr<ore::data::Loader>& loader() const { return loader_; };
129
130 //! Result reports
135
138
139 //! Check whether any of the requested run types is covered by this analytic
140 bool match(const std::set<std::string>& runTypes);
141
142 const std::unique_ptr<Impl>& impl() {
143 return impl_;
144 }
145
146 std::set<QuantLib::Date> marketDates() const;
147
148 std::vector<QuantLib::ext::shared_ptr<Analytic>> allDependentAnalytics() const;
149
150protected:
151 std::unique_ptr<Impl> impl_;
152
153 //! list of analytic types run by this analytic
154 std::set<std::string> types_;
155 //! contains all the input parameters for the run
156 QuantLib::ext::shared_ptr<InputParameters> inputs_;
157
159 QuantLib::ext::shared_ptr<ore::data::Market> market_;
160 QuantLib::ext::shared_ptr<ore::data::Loader> loader_;
161 QuantLib::ext::shared_ptr<ore::data::Portfolio> portfolio_;
162
167
168 //! Whether to write intermediate reports or not.
169 //! This would typically be used when the analytic is being called by another analytic
170 //! and that parent/calling analytic will be writing its own set of intermediate reports
172};
173
175public:
176 Impl() {}
177 Impl(const QuantLib::ext::shared_ptr<InputParameters>& inputs) : inputs_(inputs) {}
178 virtual ~Impl(){}
179
180 virtual void runAnalytic(
181 const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
182 const std::set<std::string>& runTypes = {}) = 0;
183
184 virtual void setUpConfigurations(){};
185
186 //! build an engine factory
187 virtual QuantLib::ext::shared_ptr<ore::data::EngineFactory> engineFactory();
188
189 void setLabel(const string& label) { label_ = label; }
190 const std::string& label() const { return label_; };
191
193 Analytic* analytic() const { return analytic_; }
194 void setInputs(const QuantLib::ext::shared_ptr<InputParameters>& inputs) { inputs_ = inputs; }
195
199 }
200
201 bool hasDependentAnalytic(const std::string& key) {
202 return dependentAnalytics_.find(key) != dependentAnalytics_.end();
203 }
204 template <class T> QuantLib::ext::shared_ptr<T> dependentAnalytic(const std::string& key) const;
205 QuantLib::ext::shared_ptr<Analytic> dependentAnalytic(const std::string& key) const;
206 const std::map<std::string, QuantLib::ext::shared_ptr<Analytic>>& dependentAnalytics() const {
207 return dependentAnalytics_;
208 }
209 void addDependentAnalytic(const std::string& key, const QuantLib::ext::shared_ptr<Analytic>& analytic) {
211 }
212 std::vector<QuantLib::ext::shared_ptr<Analytic>> allDependentAnalytics() const;
213 virtual std::vector<QuantLib::Date> additionalMarketDates() const { return {}; }
214
215protected:
216 QuantLib::ext::shared_ptr<InputParameters> inputs_;
217
218 //! label for logging purposes primarily
219 std::string label_;
220
221 std::map<std::string, QuantLib::ext::shared_ptr<Analytic>> dependentAnalytics_;
222
223private:
226};
227
228/*! Market analytics
229 Does not need a portfolio
230 Builds the market
231 Reports market calibration and curves
232*/
234public:
235 static constexpr const char* LABEL = "MARKETDATA";
236
237 MarketDataAnalyticImpl(const QuantLib::ext::shared_ptr<InputParameters>& inputs) : Analytic::Impl(inputs) {
239 }
240 void runAnalytic(const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
241 const std::set<std::string>& runTypes = {}) override;
242 void setUpConfigurations() override;
243};
244
246public:
247 MarketDataAnalytic(const QuantLib::ext::shared_ptr<InputParameters>& inputs)
248 : Analytic(std::make_unique<MarketDataAnalyticImpl>(inputs), {"MARKETDATA"}, inputs) {}
249};
250
251template <class T> inline QuantLib::ext::shared_ptr<T> Analytic::Impl::dependentAnalytic(const std::string& key) const {
252 auto it = dependentAnalytics_.find(key);
253 QL_REQUIRE(it != dependentAnalytics_.end(), "Could not find dependent Analytic " << key);
254 QuantLib::ext::shared_ptr<T> analytic = QuantLib::ext::dynamic_pointer_cast<T>(it->second);
255 QL_REQUIRE(analytic, "Could not cast analytic for key " << key);
256 return analytic;
257}
258
259QuantLib::ext::shared_ptr<ore::data::Loader> implyBondSpreads(const Date& asof,
260 const QuantLib::ext::shared_ptr<InputParameters>& params,
261 const QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>& todaysMarketParams,
262 const QuantLib::ext::shared_ptr<ore::data::Loader>& loader,
263 const QuantLib::ext::shared_ptr<ore::data::CurveConfigurations>& curveConfigs,
264 const std::string& excludeRegex);
265
266} // namespace analytics
267} // namespace oreplus
Analytic * analytic() const
Definition: analytic.hpp:193
bool hasDependentAnalytic(const std::string &key)
Definition: analytic.hpp:201
bool generateAdditionalResults() const
Definition: analytic.hpp:196
void setLabel(const string &label)
Definition: analytic.hpp:189
virtual std::vector< QuantLib::Date > additionalMarketDates() const
Definition: analytic.hpp:213
std::string label_
label for logging purposes primarily
Definition: analytic.hpp:219
void addDependentAnalytic(const std::string &key, const QuantLib::ext::shared_ptr< Analytic > &analytic)
Definition: analytic.hpp:209
const std::string & label() const
Definition: analytic.hpp:190
void setAnalytic(Analytic *analytic)
Definition: analytic.hpp:192
std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > dependentAnalytics_
Definition: analytic.hpp:221
void setGenerateAdditionalResults(const bool generateAdditionalResults)
Definition: analytic.hpp:197
QuantLib::ext::shared_ptr< T > dependentAnalytic(const std::string &key) const
Definition: analytic.hpp:251
Impl(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: analytic.hpp:177
virtual void setUpConfigurations()
Definition: analytic.hpp:184
void setInputs(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: analytic.hpp:194
std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics() const
Definition: analytic.cpp:97
const std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > & dependentAnalytics() const
Definition: analytic.hpp:206
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: analytic.hpp:216
virtual QuantLib::ext::shared_ptr< ore::data::EngineFactory > engineFactory()
build an engine factory
Definition: analytic.cpp:161
virtual void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={})=0
analytic_reports & reports()
Result reports.
Definition: analytic.hpp:131
void setWriteIntermediateReports(const bool flag)
Definition: analytic.hpp:137
std::set< QuantLib::Date > marketDates() const
Definition: analytic.cpp:135
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< AggregationScenarioData > > > analytic_mktcubes
Definition: analytic.hpp:57
analytic_npvcubes & npvCubes()
Definition: analytic.hpp:132
Configurations & configurations()
Definition: analytic.hpp:128
analytic_stresstests & stressTests()
Definition: analytic.hpp:134
void setPortfolio(const QuantLib::ext::shared_ptr< ore::data::Portfolio > &portfolio)
Definition: analytic.hpp:125
virtual void modifyPortfolio()
Definition: analytic.hpp:110
virtual void marketCalibration(const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &mcr=nullptr)
Definition: analytic.cpp:217
analytic_mktcubes mktCubes_
Definition: analytic.hpp:165
virtual void buildMarket(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const bool marketRequired=true)
Definition: analytic.cpp:178
virtual void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={})
Run only those analytic types that are inclcuded in the runTypes vector, run all if the runType vecto...
Definition: analytic.cpp:83
const std::unique_ptr< Impl > & impl()
Definition: analytic.hpp:142
const std::string label() const
Inspectors.
Definition: analytic.cpp:113
const QuantLib::ext::shared_ptr< InputParameters > & inputs() const
Definition: analytic.hpp:116
std::unique_ptr< Impl > impl_
Definition: analytic.hpp:151
std::set< std::string > types_
list of analytic types run by this analytic
Definition: analytic.hpp:154
void setMarket(const QuantLib::ext::shared_ptr< ore::data::Market > &market)
Definition: analytic.hpp:124
QuantLib::ext::shared_ptr< ore::data::Portfolio > portfolio_
Definition: analytic.hpp:161
const QuantLib::ext::shared_ptr< ore::data::Portfolio > & portfolio() const
Definition: analytic.hpp:122
Analytic()
Constructors.
Definition: analytic.hpp:79
virtual void setUpConfigurations()
Definition: analytic.cpp:92
QuantLib::ext::shared_ptr< ore::data::Market > market_
Definition: analytic.hpp:159
const QuantLib::ext::shared_ptr< ore::data::Loader > & loader() const
Definition: analytic.hpp:127
virtual void replaceTrades()
Definition: analytic.hpp:111
const QuantLib::ext::shared_ptr< ore::data::Market > & market() const
Definition: analytic.hpp:117
analytic_npvcubes npvCubes_
Definition: analytic.hpp:164
void setInputs(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: analytic.hpp:123
QuantLib::ext::shared_ptr< MarketImpl > getMarket() const
Definition: analytic.hpp:119
std::vector< QuantLib::ext::shared_ptr< Analytic > > allDependentAnalytics() const
Definition: analytic.cpp:131
const bool getWriteIntermediateReports() const
Definition: analytic.hpp:136
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< ore::data::InMemoryReport > > > analytic_reports
Definition: analytic.hpp:51
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< StressTestScenarioData > > > analytic_stresstests
Definition: analytic.hpp:60
analytic_reports reports_
Definition: analytic.hpp:163
analytic_stresstests stressTests_
Definition: analytic.hpp:166
Configurations configurations_
Definition: analytic.hpp:158
const std::set< std::string > & analyticTypes() const
Definition: analytic.hpp:115
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams()
Definition: analytic.cpp:147
QuantLib::ext::shared_ptr< ore::data::Loader > loader_
Definition: analytic.hpp:160
QuantLib::ext::shared_ptr< InputParameters > inputs_
contains all the input parameters for the run
Definition: analytic.hpp:156
analytic_mktcubes & mktCubes()
Definition: analytic.hpp:133
bool match(const std::set< std::string > &runTypes)
Check whether any of the requested run types is covered by this analytic.
Definition: analytic.cpp:118
virtual void buildPortfolio()
Definition: analytic.cpp:222
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< NPVCube > > > analytic_npvcubes
Definition: analytic.hpp:54
virtual void buildConfigurations(const bool=false)
Definition: analytic.hpp:103
MarketDataAnalytic(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: analytic.hpp:247
MarketDataAnalyticImpl(const QuantLib::ext::shared_ptr< InputParameters > &inputs)
Definition: analytic.hpp:237
void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
Definition: analytic.cpp:261
static constexpr const char * LABEL
Definition: analytic.hpp:235
Collateral Account Balance (stored in base currency)
Collateral Exposure Helper Functions (stored in base currency)
class describing the layout of an npv cube and aggregation scenario data
Input Parameters.
ORE Analytics Manager.
QuantLib::ext::shared_ptr< Loader > implyBondSpreads(const Date &asof, const QuantLib::ext::shared_ptr< ore::analytics::InputParameters > &params, const QuantLib::ext::shared_ptr< TodaysMarketParameters > &todaysMarketParams, const QuantLib::ext::shared_ptr< Loader > &loader, const QuantLib::ext::shared_ptr< CurveConfigurations > &curveConfigs, const std::string &excludeRegex)
Definition: analytic.cpp:273
Exposure aggregation and XVA calculation.
A class to hold Scenario parameters for scenarioSimMarket.
Class for streaming SensitivityRecords from a SensitivityCube.
QuantLib::ext::shared_ptr< ore::analytics::SensitivityScenarioData > sensiScenarioData
Definition: analytic.hpp:70
QuantLib::ext::shared_ptr< ore::analytics::CrossAssetModelData > crossAssetModelData
Definition: analytic.hpp:72
QuantLib::ext::shared_ptr< ore::data::EngineData > engineData
Definition: analytic.hpp:74
QuantLib::ext::shared_ptr< CurveConfigurations > curveConfig
Definition: analytic.hpp:73
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams
Definition: analytic.hpp:68
bool simulationConfigRequired
Booleans to determine if these configs are needed.
Definition: analytic.hpp:64
QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > simMarketParams
Definition: analytic.hpp:69
QuantLib::ext::shared_ptr< ore::analytics::ScenarioGeneratorData > scenarioGeneratorData
Definition: analytic.hpp:71
Date asof(14, Jun, 2018)