Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
nettedexposurecalculator.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/nettedexposurecalculator.hpp
20 \brief Exposure calculator
21 \ingroup analytics
22*/
23
24#pragma once
25
29
31
32namespace ore {
33namespace analytics {
34using namespace QuantLib;
35using namespace QuantExt;
36using namespace data;
37using namespace std;
38
39//! XVA Calculator base class
40/*!
41 Derived classes implement a constructor with the relevant additional input data
42 and a build function that performs the XVA calculations for all netting sets and
43 along all paths.
44*/
46public:
48 const QuantLib::ext::shared_ptr<Portfolio>& portfolio, const QuantLib::ext::shared_ptr<Market>& market,
49 const QuantLib::ext::shared_ptr<NPVCube>& cube, const string& baseCurrency, const string& configuration,
50 const Real quantile, const CollateralExposureHelper::CalculationType calcType, const bool multiPath,
51 const QuantLib::ext::shared_ptr<NettingSetManager>& nettingSetManager,
52 const QuantLib::ext::shared_ptr<CollateralBalances>& collateralBalances,
53 const map<string, vector<vector<Real>>>& nettingSetDefaultValue,
54 const map<string, vector<vector<Real>>>& nettingSetCloseOutValue,
55 const map<string, vector<vector<Real>>>& nettingSetMporPositiveFlow,
56 const map<string, vector<vector<Real>>>& nettingSetMporNegativeFlow,
57 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
58 const QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation, const bool applyInitialMargin,
59 const QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator>& dimCalculator, const bool fullInitialCollateralisation,
60 // Marginal Allocation
61 const bool marginalAllocation, const Real marginalAllocationLimit,
62 const QuantLib::ext::shared_ptr<NPVCube>& tradeExposureCube, const Size allocatedEpeIndex, const Size allocatedEneIndex,
63 const bool flipViewXVA, const bool withMporStickyDate, const MporCashFlowMode mporCashFlowMode);
64
66 const QuantLib::ext::shared_ptr<NPVCube>& exposureCube() { return exposureCube_; }
67 const QuantLib::ext::shared_ptr<NPVCube>& nettedCube() { return nettedCube_; }
68 //! Compute exposures along all paths and fill result structures
69 virtual void build();
70
73 ENE
74 };
75 const Size EXPOSURE_CUBE_DEPTH = 3;
76
77 vector<Real> epe(const string& nid) { return getMeanExposure(nid, ExposureIndex::EPE); }
78 vector<Real> ene(const string& nid) { return getMeanExposure(nid, ExposureIndex::ENE); }
79 vector<Real>& ee_b(const string& nid) { return ee_b_[nid]; }
80 vector<Real>& eee_b(const string& nid) { return eee_b_[nid]; }
81 vector<Real>& pfe(const string& nid) { return pfe_[nid]; }
82 vector<Real>& expectedCollateral(const string& nid) { return expectedCollateral_[nid]; }
83 vector<Real>& colvaIncrements(const string& nid) { return colvaInc_[nid]; }
84 vector<Real>& collateralFloorIncrements(const string& nid) { return eoniaFloorInc_[nid]; }
85 Real& epe_b(const string& nid) { return epe_b_[nid]; }
86 Real& eepe_b(const string& nid) { return eepe_b_[nid]; }
87 Real& colva(const string& nid) { return colva_[nid]; }
88 Real& collateralFloor(const string& nid) { return collateralFloor_[nid]; }
89
90 const string& counterparty(const string nettingSetId);
91 const map<string, string>& counterpartyMap() { return counterpartyMap_; }
92 map<string, vector<vector<Real>>> nettingSetCloseOutValue() { return nettingSetCloseOutValue_; }
93 map<string, vector<vector<Real>>> nettingSetDefaultValue() { return nettingSetDefaultValue_; }
94 map<string, vector<vector<Real>>> nettingSetMporPositiveFlow() { return nettingSetMporPositiveFlow_; }
95 map<string, vector<vector<Real>>> nettingSetMporNegativeFlow() { return nettingSetMporNegativeFlow_; }
96protected:
97 QuantLib::ext::shared_ptr<Portfolio> portfolio_;
98 QuantLib::ext::shared_ptr<Market> market_;
99 QuantLib::ext::shared_ptr<NPVCube> cube_;
105 const QuantLib::ext::shared_ptr<NettingSetManager> nettingSetManager_;
106 const QuantLib::ext::shared_ptr<CollateralBalances> collateralBalances_;
107 map<string, vector<vector<Real>>> nettingSetDefaultValue_;
108 map<string, vector<vector<Real>>> nettingSetCloseOutValue_;
109 map<string, vector<vector<Real>>> nettingSetMporPositiveFlow_;
110 map<string, vector<vector<Real>>> nettingSetMporNegativeFlow_;
111 const QuantLib::ext::shared_ptr<AggregationScenarioData> scenarioData_;
112 QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation_;
114 const QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator_;
116 // Marginal Allocation
119 QuantLib::ext::shared_ptr<NPVCube> tradeExposureCube_;
122 const bool flipViewXVA_;
123
124 // Output
125 QuantLib::ext::shared_ptr<NPVCube> nettedCube_;
126 QuantLib::ext::shared_ptr<NPVCube> exposureCube_;
127 map<string, string> counterpartyMap_; // map netting set id to counterparty name
128 map<string, std::vector<Real>> ee_b_;
129 map<string, std::vector<Real>> eee_b_;
130 map<string, std::vector<Real>> pfe_;
131 map<string, std::vector<Real>> expectedCollateral_;
132 map<string, std::vector<Real>> colvaInc_;
133 map<string, std::vector<Real>> eoniaFloorInc_;
134 map<string, Real> epe_b_;
135 map<string, Real> eepe_b_;
136 map<string, Real> colva_;
137 map<string, Real> collateralFloor_;
138 vector<Real> getMeanExposure(const string& tid, ExposureIndex index);
139
140 QuantLib::ext::shared_ptr<vector<QuantLib::ext::shared_ptr<CollateralAccount>>>
141 collateralPaths(const string& nettingSetId,
142 const Real& nettingSetValueToday,
143 const vector<vector<Real>>& nettingSetValue,
144 const Date& nettingSetMaturity);
145
148};
149
150} // namespace analytics
151} // namespace ore
QuantLib::ext::shared_ptr< Market > market_
map< string, vector< vector< Real > > > nettingSetDefaultValue()
vector< Real > & expectedCollateral(const string &nid)
QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_
map< string, vector< vector< Real > > > nettingSetDefaultValue_
const QuantLib::ext::shared_ptr< NPVCube > & exposureCube()
map< string, vector< vector< Real > > > nettingSetMporPositiveFlow_
const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator_
const QuantLib::ext::shared_ptr< CollateralBalances > collateralBalances_
vector< Real > & colvaIncrements(const string &nid)
vector< Real > getMeanExposure(const string &tid, ExposureIndex index)
QuantLib::ext::shared_ptr< NPVCube > nettedCube_
vector< Real > & eee_b(const string &nid)
QuantLib::ext::shared_ptr< NPVCube > exposureCube_
vector< Real > & pfe(const string &nid)
virtual void build()
Compute exposures along all paths and fill result structures.
map< string, vector< vector< Real > > > nettingSetMporPositiveFlow()
QuantLib::ext::shared_ptr< Portfolio > portfolio_
const QuantLib::ext::shared_ptr< AggregationScenarioData > scenarioData_
map< string, vector< vector< Real > > > nettingSetMporNegativeFlow_
const string & counterparty(const string nettingSetId)
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation_
map< string, std::vector< Real > > eoniaFloorInc_
map< string, vector< vector< Real > > > nettingSetCloseOutValue()
map< string, vector< vector< Real > > > nettingSetCloseOutValue_
CollateralExposureHelper::CalculationType calcType_
map< string, std::vector< Real > > colvaInc_
const map< string, string > & counterpartyMap()
const QuantLib::ext::shared_ptr< NPVCube > & nettedCube()
QuantLib::ext::shared_ptr< vector< QuantLib::ext::shared_ptr< CollateralAccount > > > collateralPaths(const string &nettingSetId, const Real &nettingSetValueToday, const vector< vector< Real > > &nettingSetValue, const Date &nettingSetMaturity)
vector< Real > & ee_b(const string &nid)
map< string, std::vector< Real > > expectedCollateral_
map< string, vector< vector< Real > > > nettingSetMporNegativeFlow()
const QuantLib::ext::shared_ptr< NettingSetManager > nettingSetManager_
QuantLib::ext::shared_ptr< NPVCube > cube_
vector< Real > & collateralFloorIncrements(const string &nid)
Collateral Exposure Helper Functions (stored in base currency)
Dynamic Initial Margin calculator base class.
Exposure calculator.
data