Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
AnalyticsManager Class Reference

#include <orea/app/analyticsmanager.hpp>

+ Collaboration diagram for AnalyticsManager:

Public Member Functions

 AnalyticsManager (const QuantLib::ext::shared_ptr< InputParameters > &inputs, const QuantLib::ext::shared_ptr< MarketDataLoader > &marketDataLoader)
 
virtual ~AnalyticsManager ()
 
bool hasAnalytic (const std::string &type)
 Valid analytics in the analytics manager are the union of analytics types provided by analytics_ map. More...
 
const std::set< std::string > & validAnalytics ()
 
const std::set< std::string > & requestedAnalytics ()
 
const QuantLib::ext::shared_ptr< Analytic > & getAnalytic (const std::string &type) const
 
Size numberOfAnalytics ()
 
const QuantLib::ext::shared_ptr< InputParameters > & inputs ()
 
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams ()
 
void runAnalytics (const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &marketCalibrationReport=nullptr)
 
void addAnalytic (const std::string &label, const QuantLib::ext::shared_ptr< Analytic > &analytic)
 
std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > analytics ()
 
void clear ()
 
Analytic::analytic_reports const reports ()
 
Analytic::analytic_npvcubes const npvCubes ()
 
Analytic::analytic_mktcubes const mktCubes ()
 
Analytic::analytic_stresstests const stressTests ()
 
void toFile (const Analytic::analytic_reports &reports, const std::string &outputPath, const std::map< std::string, std::string > &reportNames={}, const char sep=',', const bool commentCharacter=false, char quoteChar='\0', const string &nullString="#N/A", const std::set< std::string > &lowerHeaderReportNames={})
 

Private Attributes

std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > analytics_
 
QuantLib::ext::shared_ptr< InputParametersinputs_
 
QuantLib::ext::shared_ptr< MarketDataLoadermarketDataLoader_
 
Analytic::analytic_reports reports_
 
std::set< std::string > validAnalytics_
 

Detailed Description

Definition at line 35 of file analyticsmanager.hpp.

Constructor & Destructor Documentation

◆ AnalyticsManager()

AnalyticsManager ( const QuantLib::ext::shared_ptr< InputParameters > &  inputs,
const QuantLib::ext::shared_ptr< MarketDataLoader > &  marketDataLoader 
)
Parameters
inputsContainer for the inputs required by the standard analytics
marketDataLoaderA market data loader object that can retrieve required data from a large repository

Definition at line 49 of file analyticsmanager.cpp.

51 : inputs_(inputs), marketDataLoader_(marketDataLoader) {
52
53 for (const auto& a : inputs_->analytics()) {
54 auto ap = AnalyticFactory::instance().build(a, inputs);
55 if (ap.second)
56 addAnalytic(ap.first, ap.second);
57 }
58}
const QuantLib::ext::shared_ptr< InputParameters > & inputs()
QuantLib::ext::shared_ptr< MarketDataLoader > marketDataLoader_
void addAnalytic(const std::string &label, const QuantLib::ext::shared_ptr< Analytic > &analytic)
QuantLib::ext::shared_ptr< InputParameters > inputs_
+ Here is the call graph for this function:

◆ ~AnalyticsManager()

virtual ~AnalyticsManager ( )
virtual

Definition at line 41 of file analyticsmanager.hpp.

41{};

Member Function Documentation

◆ hasAnalytic()

bool hasAnalytic ( const std::string &  type)

Valid analytics in the analytics manager are the union of analytics types provided by analytics_ map.

Definition at line 89 of file analyticsmanager.cpp.

89 {
90 const std::set<std::string>& va = validAnalytics();
91 return va.find(type) != va.end();
92}
const std::set< std::string > & validAnalytics()
+ Here is the call graph for this function:

◆ validAnalytics()

const std::set< std::string > & validAnalytics ( )

Definition at line 75 of file analyticsmanager.cpp.

75 {
76 if (validAnalytics_.size() == 0) {
77 for (auto a : analytics_) {
78 const std::set<std::string>& types = a.second->analyticTypes();
79 validAnalytics_.insert(types.begin(), types.end());
80 }
81 }
82 return validAnalytics_;
83}
std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > analytics_
std::set< std::string > validAnalytics_
boost::bimap< std::string, TRS::FundingData::NotionalType > types
+ Here is the caller graph for this function:

◆ requestedAnalytics()

const std::set< std::string > & requestedAnalytics ( )

Definition at line 85 of file analyticsmanager.cpp.

85 {
86 return inputs_->analytics();
87}

◆ getAnalytic()

const QuantLib::ext::shared_ptr< Analytic > & getAnalytic ( const std::string &  type) const

Definition at line 94 of file analyticsmanager.cpp.

94 {
95 for (const auto& a : analytics_) {
96 const std::set<std::string>& types = a.second->analyticTypes();
97 if (types.find(type) != types.end())
98 return a.second;
99 }
100 QL_FAIL("analytic type " << type << " not found, check validAnalytics()");
101}

◆ numberOfAnalytics()

Size numberOfAnalytics ( )

Definition at line 48 of file analyticsmanager.hpp.

48{ return analytics_.size(); }

◆ inputs()

const QuantLib::ext::shared_ptr< InputParameters > & inputs ( )

Definition at line 49 of file analyticsmanager.hpp.

49{ return inputs_; }
+ Here is the caller graph for this function:

◆ todaysMarketParams()

std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams ( )

Definition at line 103 of file analyticsmanager.cpp.

103 {
104 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> tmps;
105 for (const auto& a : analytics_) {
106 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> atmps = a.second->todaysMarketParams();
107 tmps.insert(end(tmps), begin(atmps), end(atmps));
108 }
109 return tmps;
110}
+ Here is the caller graph for this function:

◆ runAnalytics()

void runAnalytics ( const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &  marketCalibrationReport = nullptr)

Definition at line 112 of file analyticsmanager.cpp.

112 {
113 if (analytics_.size() == 0)
114 return;
115
116 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> tmps = todaysMarketParams();
117 std::set<Date> marketDates;
118 for (const auto& a : analytics_) {
119 auto mdates = a.second->marketDates();
120 marketDates.insert(mdates.begin(), mdates.end());
121 }
122
123 // Do we need market data
124 bool requireMarketData = false;
125 for (const auto& tmp : tmps) {
126 if (!tmp->empty())
127 requireMarketData = true;
128 }
129
130 LOG("AnalyticsManager::runAnalytics: requireMarketData " << (requireMarketData ? "Y" : "N"));
131
132 if (requireMarketData) {
133 // load the market data
134 if (tmps.size() > 0) {
135 LOG("AnalyticsManager::runAnalytics: populate loader for dates: " << to_string(marketDates));
136 marketDataLoader_->populateLoader(tmps, marketDates);
137 }
138
139 QuantLib::ext::shared_ptr<InMemoryReport> mdReport = QuantLib::ext::make_shared<InMemoryReport>();
140 QuantLib::ext::shared_ptr<InMemoryReport> fixingReport = QuantLib::ext::make_shared<InMemoryReport>();
141 QuantLib::ext::shared_ptr<InMemoryReport> dividendReport = QuantLib::ext::make_shared<InMemoryReport>();
142
143 ore::analytics::ReportWriter(inputs_->reportNaString())
144 .writeMarketData(*mdReport, marketDataLoader_->loader(), inputs_->asof(),
145 marketDataLoader_->quotes()[inputs_->asof()],
146 !inputs_->entireMarket());
147 ore::analytics::ReportWriter(inputs_->reportNaString())
148 .writeFixings(*fixingReport, marketDataLoader_->loader());
149 ore::analytics::ReportWriter(inputs_->reportNaString())
150 .writeDividends(*dividendReport, marketDataLoader_->loader());
151
152 reports_["MARKETDATA"]["marketdata"] = mdReport;
153 reports_["FIXINGS"]["fixings"] = fixingReport;
154 reports_["DIVIDENDS"]["dividends"] = dividendReport;
155 }
156
157 // run requested analytics
158 for (auto a : analytics_) {
159 LOG("run analytic with label '" << a.first << "'");
160 a.second->runAnalytic(marketDataLoader_->loader(), inputs_->analytics());
161 LOG("run analytic with label '" << a.first << "' finished.");
162 // then populate the market calibration report if required
163 if (marketCalibrationReport)
164 a.second->marketCalibration(marketCalibrationReport);
165 }
166
167 if (inputs_->portfolio()) {
168 auto pricingStatsReport = QuantLib::ext::make_shared<InMemoryReport>();
169 ReportWriter(inputs_->reportNaString())
170 .writePricingStats(*pricingStatsReport, inputs_->portfolio());
171 reports_["STATS"]["pricingstats"] = pricingStatsReport;
172 }
173
174 if (marketCalibrationReport) {
175 auto report = marketCalibrationReport->outputCalibrationReport();
176 if (report) {
177 if (auto rpt = QuantLib::ext::dynamic_pointer_cast<InMemoryReport>(report))
178 reports_["MARKET"]["todaysmarketcalibration"] = rpt;
179 }
180 }
181
182 inputs_->writeOutParameters();
183}
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams()
Analytic::analytic_reports reports_
Write ORE outputs to reports.
virtual void writeMarketData(ore::data::Report &report, const QuantLib::ext::shared_ptr< ore::data::Loader > &loader, const QuantLib::Date &asof, const set< string > &quoteNames, bool returnAll)
virtual void writeDividends(ore::data::Report &report, const QuantLib::ext::shared_ptr< ore::data::Loader > &loader)
virtual void writeFixings(ore::data::Report &report, const QuantLib::ext::shared_ptr< ore::data::Loader > &loader)
#define LOG(text)
std::string to_string(const LocationInfo &l)
+ Here is the call graph for this function:

◆ addAnalytic()

void addAnalytic ( const std::string &  label,
const QuantLib::ext::shared_ptr< Analytic > &  analytic 
)

Definition at line 66 of file analyticsmanager.cpp.

66 {
67 // Label is not necessarily a valid analytics type
68 // Get the latter via analytic->analyticTypes()
69 LOG("register analytic with label '" << label << "' and sub-analytics " << to_string(analytic->analyticTypes()));
70 analytics_[label] = analytic;
71 // This forces an update of valid analytics vector with the next call to validAnalytics()
72 validAnalytics_.clear();
73}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ analytics()

std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > analytics ( )

Definition at line 55 of file analyticsmanager.hpp.

55{ return analytics_; }

◆ clear()

void clear ( )

Definition at line 60 of file analyticsmanager.cpp.

60 {
61 LOG("AnalyticsManager: Remove all analytics currently registered");
62 analytics_.clear();
63 validAnalytics_.clear();
64}

◆ reports()

Analytic::analytic_reports const reports ( )

Definition at line 185 of file analyticsmanager.cpp.

185 {
187 for (auto a : analytics_) {
188 auto rs = a.second->reports();
189 reports.insert(rs.begin(), rs.end());
190 }
191 return reports;
192}
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< ore::data::InMemoryReport > > > analytic_reports
Definition: analytic.hpp:51
Analytic::analytic_reports const reports()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ npvCubes()

Analytic::analytic_npvcubes const npvCubes ( )

Definition at line 194 of file analyticsmanager.cpp.

194 {
196 for (auto a : analytics_) {
197 auto rs = a.second->npvCubes();
198 results.insert(rs.begin(), rs.end());
199 }
200 return results;
201}
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< NPVCube > > > analytic_npvcubes
Definition: analytic.hpp:54

◆ mktCubes()

Analytic::analytic_mktcubes const mktCubes ( )

Definition at line 203 of file analyticsmanager.cpp.

203 {
205 for (auto a : analytics_) {
206 auto rs = a.second->mktCubes();
207 results.insert(rs.begin(), rs.end());
208 }
209 return results;
210}
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< AggregationScenarioData > > > analytic_mktcubes
Definition: analytic.hpp:57

◆ stressTests()

Analytic::analytic_stresstests const stressTests ( )

Definition at line 212 of file analyticsmanager.cpp.

212 {
214 for (auto a : analytics_) {
215 auto rs = a.second->stressTests();
216 results.insert(rs.begin(), rs.end());
217 }
218 return results;
219}
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< StressTestScenarioData > > > analytic_stresstests
Definition: analytic.hpp:60

◆ toFile()

void toFile ( const Analytic::analytic_reports reports,
const std::string &  outputPath,
const std::map< std::string, std::string > &  reportNames = {},
const char  sep = ',',
const bool  commentCharacter = false,
char  quoteChar = '\0',
const string &  nullString = "#N/A",
const std::set< std::string > &  lowerHeaderReportNames = {} 
)

Definition at line 246 of file analyticsmanager.cpp.

249 {
250 std::map<std::string, Size> hits = checkReportNames(rpts);
251 for (const auto& rep : rpts) {
252 string analytic = rep.first;
253 for (auto b : rep.second) {
254 string reportName = b.first;
255 QuantLib::ext::shared_ptr<InMemoryReport> report = b.second;
256 string fileName;
257 auto it = hits.find(reportName);
258 QL_REQUIRE(it != hits.end(), "something wrong here");
259 if (it->second == 1) {
260 // The report name is unique, check whether we want to rename it or use the standard name
261 auto it2 = reportNames.find(reportName);
262 fileName = (it2 != reportNames.end() && !it2->second.empty()) ? it2->second : reportName;
263 }
264 else {
265 ALOG("Report " << reportName << " occurs " << it->second << " times, fix report naming");
266 fileName = analytic + "_" + reportName + "_" + to_string(hits[fileName]);
267 }
268
269 // attach a suffix only if it does not have one already
270 string suffix = "";
271 if (!endsWith(fileName,".csv") && !endsWith(fileName, ".txt"))
272 suffix = ".csv";
273 std::string fullFileName = outputPath + "/" + fileName + suffix;
274
275 report->toFile(fullFileName, sep, commentCharacter, quoteChar, nullString,
276 lowerHeaderReportNames.find(reportName) != lowerHeaderReportNames.end());
277 LOG("report " << reportName << " written to " << fullFileName);
278 }
279 }
280}
#define ALOG(text)
bool endsWith(const std::string &name, const std::string &suffix)
std::map< std::string, Size > checkReportNames(const ore::analytics::Analytic::analytic_reports &rpts)
+ Here is the call graph for this function:

Member Data Documentation

◆ analytics_

std::map<std::string, QuantLib::ext::shared_ptr<Analytic> > analytics_
private

Definition at line 71 of file analyticsmanager.hpp.

◆ inputs_

QuantLib::ext::shared_ptr<InputParameters> inputs_
private

Definition at line 72 of file analyticsmanager.hpp.

◆ marketDataLoader_

QuantLib::ext::shared_ptr<MarketDataLoader> marketDataLoader_
private

Definition at line 73 of file analyticsmanager.hpp.

◆ reports_

Analytic::analytic_reports reports_
private

Definition at line 74 of file analyticsmanager.hpp.

◆ validAnalytics_

std::set<std::string> validAnalytics_
private

Definition at line 75 of file analyticsmanager.hpp.