Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
exposurecalculator.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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/aggregation/exposurecalculator.hpp
20 \brief Exposure calculator
21 \ingroup analytics
22*/
23
24#pragma once
25
28#include <orea/cube/npvcube.hpp>
30
31#include <ql/shared_ptr.hpp>
32
33namespace ore {
34namespace analytics {
35using namespace QuantLib;
36using namespace QuantExt;
37using namespace data;
38using namespace std;
39
40//! XVA Calculator base class
41/*!
42 Derived classes implement a constructor with the relevant additional input data
43 and a build function that performs the XVA calculations for all netting sets and
44 along all paths.
45*/
47public:
49 //! Driving portfolio consistent with the cube below
50 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
51 //! NPV cube resulting from the Monte Carlo simulation loop
52 const QuantLib::ext::shared_ptr<NPVCube>& cube,
53 //! Interpreter for cube storage (where to find which data items)
54 const QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation,
55 //! Market data object to access e.g. discounting and funding curves
56 const QuantLib::ext::shared_ptr<Market>& market,
57 //! Flag to indicate exposure termination at the next break date
58 const bool exerciseNextBreak,
59 //! Expression currency for all results
60 const string& baseCurrency,
61 //! Market configuration to use
62 const string& configuration,
63 //! Quantile for Potential Future Exposure output
64 const Real quantile,
65 //! Collateral calculation type to be used, see class %CollateralExposureHelper
67 //! Flag to indicate exposure evaluation with dynamic credit
68 const bool multiPath,
69 //! Flag to indicate flipped xva calculation
70 const bool flipViewXVA
71 );
72
74
75 //! Compute exposures along all paths and fill result structures
76 virtual void build();
77
79 EPE = 0,
83 };
84 const Size EXPOSURE_CUBE_DEPTH = 4;
85
86 QuantLib::ext::shared_ptr<Portfolio> portfolio() { return portfolio_; }
87 QuantLib::ext::shared_ptr<NPVCube> npvCube() { return cube_; }
88 QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation() { return cubeInterpretation_; }
89 QuantLib::ext::shared_ptr<Market> market() { return market_; }
91 string baseCurrency() { return baseCurrency_; }
92 string configuration() { return configuration_; }
93 Real quantile() { return quantile_; }
96 bool multiPath() { return multiPath_; }
97
98 vector<Date> dates() { return dates_; }
99 Date today() { return today_; }
100 DayCounter dc() { return dc_; }
101 vector<string> nettingSetIds() { return nettingSetIds_; }
102 map<string, Real> nettingSetValueToday() { return nettingSetValueToday_; }
103 map<string, Date> nettingSetMaturity() { return nettingSetMaturity_; }
104 vector<Real> times() { return times_; };
105
106 const QuantLib::ext::shared_ptr<NPVCube>& exposureCube() { return exposureCube_; }
107 const map<string, vector<vector<Real>>>& nettingSetDefaultValue() { return nettingSetDefaultValue_; }
108 const map<string, vector<vector<Real>>>& nettingSetCloseOutValue() { return nettingSetCloseOutValue_; }
109 const map<string, vector<vector<Real>>>& nettingSetMporPositiveFlow() { return nettingSetMporPositiveFlow_; }
110 const map<string, vector<vector<Real>>>& nettingSetMporNegativeFlow() { return nettingSetMporNegativeFlow_; }
111
112 vector<Real> epe(const string& tid) { return getMeanExposure(tid, ExposureIndex::EPE); }
113 vector<Real> ene(const string& tid) { return getMeanExposure(tid, ExposureIndex::ENE); }
114 vector<Real> allocatedEpe(const string& tid) { return getMeanExposure(tid, ExposureIndex::allocatedEPE); }
115 vector<Real> allocatedEne(const string& tid) { return getMeanExposure(tid, ExposureIndex::allocatedENE); }
116 vector<Real>& ee_b(const string& tid) { return ee_b_[tid]; }
117 vector<Real>& eee_b(const string& tid) { return eee_b_[tid]; }
118 vector<Real>& pfe(const string& tid) { return pfe_[tid]; }
119 Real& epe_b(const string& tid) { return epe_b_[tid]; }
120 Real& eepe_b(const string& tid) { return eepe_b_[tid]; }
121
122protected:
123 const QuantLib::ext::shared_ptr<Portfolio> portfolio_;
124 const QuantLib::ext::shared_ptr<NPVCube> cube_;
125 const QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation_;
126 const QuantLib::ext::shared_ptr<Market> market_;
128 const string baseCurrency_;
129 const string configuration_;
130 const Real quantile_;
132 const bool multiPath_;
134
135 vector<Date> dates_;
136 const Date today_;
137 const DayCounter dc_;
138 vector<string> nettingSetIds_;
139 map<string, Real> nettingSetValueToday_;
140 map<string, Date> nettingSetMaturity_;
141 vector<Real> times_;
142
143 QuantLib::ext::shared_ptr<NPVCube> exposureCube_;
144 map<string, vector<vector<Real>>> nettingSetDefaultValue_, nettingSetCloseOutValue_;
146
147 map<string, std::vector<Real>> ee_b_;
148 map<string, std::vector<Real>> eee_b_;
149 map<string, std::vector<Real>> pfe_;
150 map<string, Real> epe_b_;
151 map<string, Real> eepe_b_;
152 vector<Real> getMeanExposure(const string& tid, ExposureIndex index);
154};
155
156} // namespace analytics
157} // namespace ore
map< string, std::vector< Real > > pfe_
const QuantLib::ext::shared_ptr< Portfolio > portfolio_
map< string, vector< vector< Real > > > nettingSetDefaultValue_
const QuantLib::ext::shared_ptr< NPVCube > & exposureCube()
map< string, vector< vector< Real > > > nettingSetMporPositiveFlow_
const QuantLib::ext::shared_ptr< NPVCube > cube_
vector< Real > epe(const string &tid)
const map< string, vector< vector< Real > > > & nettingSetDefaultValue()
vector< Real > getMeanExposure(const string &tid, ExposureIndex index)
QuantLib::ext::shared_ptr< Market > market()
QuantLib::ext::shared_ptr< NPVCube > exposureCube_
const map< string, vector< vector< Real > > > & nettingSetCloseOutValue()
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation()
virtual void build()
Compute exposures along all paths and fill result structures.
vector< Real > & pfe(const string &tid)
map< string, vector< vector< Real > > > nettingSetMporNegativeFlow_
vector< Real > & eee_b(const string &tid)
map< string, std::vector< Real > > eee_b_
const map< string, vector< vector< Real > > > & nettingSetMporPositiveFlow()
const CollateralExposureHelper::CalculationType calcType_
const map< string, vector< vector< Real > > > & nettingSetMporNegativeFlow()
map< string, vector< vector< Real > > > nettingSetCloseOutValue_
CollateralExposureHelper::CalculationType calcType()
QuantLib::ext::shared_ptr< Portfolio > portfolio()
const QuantLib::ext::shared_ptr< Market > market_
vector< Real > allocatedEne(const string &tid)
map< string, std::vector< Real > > ee_b_
vector< Real > & ee_b(const string &tid)
QuantLib::ext::shared_ptr< NPVCube > npvCube()
vector< Real > allocatedEpe(const string &tid)
const QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation_
vector< Real > ene(const string &tid)
Collateral Exposure Helper Functions (stored in base currency)
class describing the layout of an npv cube and aggregation scenario data
data
The base NPV cube class.