Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
varcalculator.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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*/
21
22namespace ore {
23namespace analytics {
24
25VarReport::VarReport(const std::string& baseCurrency, const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
26 const std::string& portfolioFilter, const vector<Real>& p, boost::optional<ore::data::TimePeriod> period,
27 const QuantLib::ext::shared_ptr<HistoricalScenarioGenerator>& hisScenGen,
28 std::unique_ptr<SensiRunArgs> sensiArgs, std::unique_ptr<FullRevalArgs> fullRevalArgs, const bool breakdown)
29 : MarketRiskReport(baseCurrency, portfolio, portfolioFilter, period, hisScenGen, std::move(sensiArgs), std::move(fullRevalArgs), nullptr, breakdown), p_(p) {
30}
31
32void VarReport::createReports(const ext::shared_ptr<MarketRiskReport::Reports>& reports) {
33 QL_REQUIRE(reports->reports().size() == 1, "We should only report for VAR report");
34 QuantLib::ext::shared_ptr<Report> report = reports->reports().at(0);
35 // prepare report
36 report->addColumn("Portfolio", string()).addColumn("RiskClass", string()).addColumn("RiskType", string());
37 for (Size i = 0; i < p_.size(); ++i)
38 report->addColumn("Quantile_" + std::to_string(p_[i]), double(), 6);
39
41}
42
43void VarReport::writeReports(const ext::shared_ptr<MarketRiskReport::Reports>& reports,
44 const ext::shared_ptr<MarketRiskGroupBase>& riskGroup,
45 const ext::shared_ptr<TradeGroupBase>& tradeGroup) {
46
47 QL_REQUIRE(reports->reports().size() == 1, "We should only report for VAR report");
48 QuantLib::ext::shared_ptr<Report> report = reports->reports().at(0);
49
50 auto rg = ext::dynamic_pointer_cast<MarketRiskGroup>(riskGroup);
51 auto tg = ext::dynamic_pointer_cast<TradeGroup>(tradeGroup);
52
53 std::vector<Real> var;
54 auto quantiles = p();
55 for (auto q : quantiles)
56 var.push_back(varCalculator_->var(q));
57
58 if (!close_enough(QuantExt::detail::absMax(var), 0.0)) {
59 report->next();
60 report->add(tg->portfolioId());
61 report->add(to_string(rg->riskClass()));
62 report->add(to_string(rg->riskType()));
63 for (auto const& v : var)
64 report->add(v);
65 }
66}
67
68} // namespace analytics
69} // namespace ore
QuantLib::ext::shared_ptr< VarCalculator > varCalculator_
void createReports(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &reports) override
std::vector< Real > p_
VarReport(const std::string &baseCurrency, const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const std::string &portfolioFilter, const vector< Real > &p, boost::optional< ore::data::TimePeriod > period, const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > &hisScenGen=nullptr, std::unique_ptr< SensiRunArgs > sensiArgs=nullptr, std::unique_ptr< FullRevalArgs > fullRevalArgs=nullptr, const bool breakdown=false)
const std::vector< Real > & p() const
void writeReports(const QuantLib::ext::shared_ptr< MarketRiskReport::Reports > &report, const QuantLib::ext::shared_ptr< MarketRiskGroupBase > &riskGroup, const QuantLib::ext::shared_ptr< TradeGroupBase > &tradeGroup) override
virtual void createVarCalculator()=0
Real absMax(const A &a)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
std::string to_string(const LocationInfo &l)
Base class for a var calculation.