40#include <ql/errors.hpp>
43using namespace boost::filesystem;
50 const QuantLib::ext::shared_ptr<MarketDataLoader>& marketDataLoader)
51 : inputs_(inputs), marketDataLoader_(marketDataLoader) {
53 for (
const auto& a :
inputs_->analytics()) {
54 auto ap = AnalyticFactory::instance().build(a,
inputs);
61 LOG(
"AnalyticsManager: Remove all analytics currently registered");
69 LOG(
"register analytic with label '" << label <<
"' and sub-analytics " <<
to_string(analytic->analyticTypes()));
78 const std::set<std::string>&
types = a.second->analyticTypes();
91 return va.find(type) != va.end();
96 const std::set<std::string>&
types = a.second->analyticTypes();
100 QL_FAIL(
"analytic type " << type <<
" not found, check validAnalytics()");
104 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> tmps;
106 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> atmps = a.second->todaysMarketParams();
107 tmps.insert(end(tmps), begin(atmps), end(atmps));
116 std::vector<QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>> tmps =
todaysMarketParams();
117 std::set<Date> marketDates;
119 auto mdates = a.second->marketDates();
120 marketDates.insert(mdates.begin(), mdates.end());
124 bool requireMarketData =
false;
125 for (
const auto& tmp : tmps) {
127 requireMarketData =
true;
130 LOG(
"AnalyticsManager::runAnalytics: requireMarketData " << (requireMarketData ?
"Y" :
"N"));
132 if (requireMarketData) {
134 if (tmps.size() > 0) {
135 LOG(
"AnalyticsManager::runAnalytics: populate loader for dates: " <<
to_string(marketDates));
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>();
152 reports_[
"MARKETDATA"][
"marketdata"] = mdReport;
153 reports_[
"FIXINGS"][
"fixings"] = fixingReport;
154 reports_[
"DIVIDENDS"][
"dividends"] = dividendReport;
159 LOG(
"run analytic with label '" << a.first <<
"'");
161 LOG(
"run analytic with label '" << a.first <<
"' finished.");
163 if (marketCalibrationReport)
164 a.second->marketCalibration(marketCalibrationReport);
168 auto pricingStatsReport = QuantLib::ext::make_shared<InMemoryReport>();
171 reports_[
"STATS"][
"pricingstats"] = pricingStatsReport;
174 if (marketCalibrationReport) {
175 auto report = marketCalibrationReport->outputCalibrationReport();
177 if (
auto rpt = QuantLib::ext::dynamic_pointer_cast<InMemoryReport>(report))
178 reports_[
"MARKET"][
"todaysmarketcalibration"] = rpt;
188 auto rs = a.second->reports();
189 reports.insert(rs.begin(), rs.end());
197 auto rs = a.second->npvCubes();
198 results.insert(rs.begin(), rs.end());
206 auto rs = a.second->mktCubes();
207 results.insert(rs.begin(), rs.end());
215 auto rs = a.second->stressTests();
216 results.insert(rs.begin(), rs.end());
222 std::map<std::string, Size> m;
223 for (
const auto& rep : rpts) {
224 for (
auto b : rep.second) {
225 string reportName = b.first;
226 auto it = m.find(reportName);
234 LOG(
"report name " << r.first <<
" occurs " << r.second <<
" times");
239bool endsWith(
const std::string& name,
const std::string& suffix) {
240 if (suffix.size() >
name.size())
243 return std::equal(suffix.rbegin(), suffix.rend(),
name.rbegin());
247 const std::map<std::string, std::string>& reportNames,
const char sep,
248 const bool commentCharacter,
char quoteChar,
const string& nullString,
249 const std::set<std::string>& lowerHeaderReportNames) {
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;
257 auto it = hits.find(reportName);
258 QL_REQUIRE(it != hits.end(),
"something wrong here");
259 if (it->second == 1) {
261 auto it2 = reportNames.find(reportName);
262 fileName = (it2 != reportNames.end() && !it2->second.empty()) ? it2->second : reportName;
265 ALOG(
"Report " << reportName <<
" occurs " << it->second <<
" times, fix report naming");
266 fileName = analytic +
"_" + reportName +
"_" +
to_string(hits[fileName]);
273 std::string fullFileName = outputPath +
"/" + fileName + suffix;
275 report->toFile(fullFileName, sep, commentCharacter, quoteChar, nullString,
276 lowerHeaderReportNames.find(reportName) != lowerHeaderReportNames.end());
277 LOG(
"report " << reportName <<
" written to " << fullFileName);
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< AggregationScenarioData > > > analytic_mktcubes
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< ore::data::InMemoryReport > > > analytic_reports
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< StressTestScenarioData > > > analytic_stresstests
std::map< std::string, std::map< std::string, QuantLib::ext::shared_ptr< NPVCube > > > analytic_npvcubes
Analytic::analytic_stresstests const stressTests()
const std::set< std::string > & validAnalytics()
const QuantLib::ext::shared_ptr< InputParameters > & inputs()
AnalyticsManager(const QuantLib::ext::shared_ptr< InputParameters > &inputs, const QuantLib::ext::shared_ptr< MarketDataLoader > &marketDataLoader)
bool hasAnalytic(const std::string &type)
Valid analytics in the analytics manager are the union of analytics types provided by analytics_ map.
const std::set< std::string > & requestedAnalytics()
std::map< std::string, QuantLib::ext::shared_ptr< Analytic > > analytics_
Analytic::analytic_npvcubes const npvCubes()
std::set< std::string > validAnalytics_
QuantLib::ext::shared_ptr< MarketDataLoader > marketDataLoader_
void addAnalytic(const std::string &label, const QuantLib::ext::shared_ptr< Analytic > &analytic)
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={})
const QuantLib::ext::shared_ptr< Analytic > & getAnalytic(const std::string &type) const
Analytic::analytic_reports const reports()
void runAnalytics(const QuantLib::ext::shared_ptr< MarketCalibrationReportBase > &marketCalibrationReport=nullptr)
std::vector< QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > > todaysMarketParams()
QuantLib::ext::shared_ptr< InputParameters > inputs_
Analytic::analytic_reports reports_
Analytic::analytic_mktcubes const mktCubes()
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 > "eNames, 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)
virtual void writePricingStats(ore::data::Report &report, const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
ORE IM Schedule Analytic.
bool endsWith(const std::string &name, const std::string &suffix)
std::map< std::string, Size > checkReportNames(const ore::analytics::Analytic::analytic_reports &rpts)
std::string to_string(const LocationInfo &l)
boost::bimap< std::string, TRS::FundingData::NotionalType > types
ORE Par-Stresstest-Conversion Analytic.
A Class to write ORE outputs to reports.
ORE Scenario Statistics Analytics.
Structured analytics error.