Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
xvacalculator.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/xvacalculator.hpp
20 \brief CVA calculator base class
21 \ingroup analytics
22*/
23
24#pragma once
25
27
30
31#include <ql/time/date.hpp>
32
33#include <ql/shared_ptr.hpp>
34
35namespace ore {
36namespace analytics {
37using namespace QuantLib;
38using namespace QuantExt;
39using namespace data;
40using namespace std;
41
42//! XVA Calculator base class
43/*!
44 Derived classes implement a constructor with the relevant additional input data
45 and a build function that performs the XVA calculations for all netting sets and
46 along all paths.
47*/
49public:
50
52 //! Driving portfolio consistent with the cube below
53 const QuantLib::ext::shared_ptr<Portfolio> portfolio,
54 //! Today's market
55 const QuantLib::ext::shared_ptr<Market> market,
56 //! Market configuration to be used
57 const string& configuration,
58 //! Base currency amounts will be converted to
59 const string& baseCurrency,
60 //! Own party name for DVA calculations
61 const string& dvaName,
62 //! FVA borrowing curve
63 const string& fvaBorrowingCurve,
64 //! FVA lending curve
65 const string& fvaLendingCurve,
66 //! Deactivate initial margin calculation even if active at netting set level
67 const bool applyDynamicInitialMargin,
68 //! Dynamic Initial Margin calculator
69 const QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator,
70 //! Storage ofdefault NPVs, close-out NPVs, cash flows at trade level
71 const QuantLib::ext::shared_ptr<NPVCube> tradeExposureCube,
72 //! Storage of sensitivity vectors at netting set level
73 const QuantLib::ext::shared_ptr<NPVCube> nettingSetExposureCube,
74 //! Index of the trade EPE storage in the internal exposure cube
75 const Size tradeEpeIndex = 0,
76 //! Index of the trade ENE storage in the internal exposure cube
77 const Size tradeEneIndex = 1,
78 //! Index of the netting set EPE storage in the internal exposure cube
79 const Size nettingSetEpeIndex = 1,
80 //! Index of the netting set ENE storage in the internal exposure cube
81 const Size nettingSetEneIndex = 2,
82 //! Flag to indicate flipped xva calculation
83 const bool flipViewXVA = false,
84 //! Postfix for flipView borrowing curve for fva
85 const string& flipViewBorrowingCurvePostfix = "_BORROW",
86 //! Postfix for flipView lending curve for fva
87 const string& flipViewLendingCurvePostfix = "_LEND");
88
90
91 //! Compute cva along all paths and fill result structures
92 virtual void build();
93
94 virtual const vector<Date>& dates() { return tradeExposureCube_->dates(); };
95
96 virtual const Date asof() { return market_->asofDate(); };
97
98 virtual const Real calculateCvaIncrement(const string& tid, const string& cid,
99 const Date& d0, const Date& d1, const Real& rr) = 0;
100 virtual const Real calculateDvaIncrement(const string& tid,
101 const Date& d0, const Date& d1, const Real& rr) = 0;
103 const string& nid, const string& cid, const Date& d0, const Date& d1, const Real& rr) = 0;
105 const string& nid, const Date& d0, const Date& d1, const Real& rr) = 0;
106 virtual const Real calculateFbaIncrement(const string& tid, const string& cid, const string& dvaName,
107 const Date& d0, const Date& d1, const Real& dcf) = 0;
108 virtual const Real calculateFcaIncrement(const string& tid, const string& cid, const string& dvaName,
109 const Date& d0, const Date& d1, const Real& dcf) = 0;
110 virtual const Real calculateNettingSetFbaIncrement(const string& nid, const string& cid, const string& dvaName,
111 const Date& d0, const Date& d1, const Real& dcf) = 0;
112 virtual const Real calculateNettingSetFcaIncrement(const string& nid, const string& cid, const string& dvaName,
113 const Date& d0, const Date& d1, const Real& dcf) = 0;
114 virtual const Real calculateNettingSetMvaIncrement(const string& nid, const string& cid,
115 const Date& d0, const Date& d1, const Real& dcf) = 0;
116
117 //! CVA map for all the trades
118 const map<string, Real>& tradeCva();
119
120 //! DVA map for all the trades
121 const map<string, Real>& tradeDva();
122
123 //! CVA map for all the netting sets
124 const map<string, Real>& nettingSetCva();
125
126 //! DVA map for all the netting sets
127 const map<string, Real>& nettingSetDva();
128
129 //! Sum CVA map for all the netting sets
130 const map<string, Real>& nettingSetSumCva();
131
132 //! Sum DVA map for all the netting sets
133 const map<string, Real>& nettingSetSumDva();
134
135 //! CVA for the specified trade
136 const Real& tradeCva(const string& trade);
137
138 //! DVA for the specified trade
139 const Real& tradeDva(const string& trade);
140
141 //! FBA for the specified trade
142 const Real& tradeFba(const string& trade);
143
144 //! FBA (excl own survival probability) for the specified trade
145 const Real& tradeFba_exOwnSp(const string& trade);
146
147 //! FBA (excl all survival probability) for the specified trade
148 const Real& tradeFba_exAllSp(const string& trade);
149
150 //! FCA for the specified trade
151 const Real& tradeFca(const string& trade);
152
153 //! FCA (excl own survival probability) for the specified trade
154 const Real& tradeFca_exOwnSp(const string& trade);
155
156 //! FCA (excl all survival probability) for the specified trade
157 const Real& tradeFca_exAllSp(const string& trade);
158
159 //! MVA for the specified trade
160 const Real& tradeMva(const string& trade);
161
162 //! Sum of trades' CVA for the specified netting set
163 const Real& nettingSetSumCva(const string& nettingSet);
164
165 //! Sum of trades' DVA for the specified netting set
166 const Real& nettingSetSumDva(const string& nettingSet);
167
168 //! CVA for the specified netting set
169 const Real& nettingSetCva(const string& nettingSet);
170
171 //! DVA for the specified netting set
172 const Real& nettingSetDva(const string& nettingSet);
173
174 //! FBA for the specified netting set
175 const Real& nettingSetFba(const string& nettingSet);
176
177 //! FBA (excl own survival probability) for the specified netting set
178 const Real& nettingSetFba_exOwnSp(const string& nettingSet);
179
180 //! FBA (excl all survival probability) for the specified netting set
181 const Real& nettingSetFba_exAllSp(const string& nettingSet);
182
183 //! FCA for the specified netting set
184 const Real& nettingSetFca(const string& nettingSet);
185
186 //! FCA (excl own survival probability) for the specified netting set
187 const Real& nettingSetFca_exOwnSp(const string& nettingSet);
188
189 //! FCA (excl all survival probability) for the specified netting set
190 const Real& nettingSetFca_exAllSp(const string& nettingSet);
191
192 //! MVA for the specified netting set
193 const Real& nettingSetMva(const string& nettingSet);
194
195protected:
196 QuantLib::ext::shared_ptr<Portfolio> portfolio_;
197 QuantLib::ext::shared_ptr<Market> market_;
200 string dvaName_;
204 QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator_;
205 const QuantLib::ext::shared_ptr<NPVCube> tradeExposureCube_;
206 const QuantLib::ext::shared_ptr<NPVCube> nettingSetExposureCube_;
214
215 map<string, string> nettingSetCpty_;
216 // For each trade: values
217 map<string, Real> tradeCva_;
218 map<string, Real> tradeDva_;
219 map<string, Real> tradeFba_;
220 map<string, Real> tradeFba_exOwnSp_;
221 map<string, Real> tradeFba_exAllSp_;
222 map<string, Real> tradeFca_;
223 map<string, Real> tradeFca_exOwnSp_;
224 map<string, Real> tradeFca_exAllSp_;
225 map<string, Real> tradeMva_; // FIXME: MVA is not computed at trade level yet, remains initialised at 0
226
227 // For each netting: values
228 map<string, Real> nettingSetSumCva_;
229 map<string, Real> nettingSetSumDva_;
230 map<string, Real> nettingSetCva_;
231 map<string, Real> nettingSetDva_;
232 map<string, Real> nettingSetFba_;
233 map<string, Real> nettingSetFba_exOwnSp_;
234 map<string, Real> nettingSetFba_exAllSp_;
235 map<string, Real> nettingSetFca_;
236 map<string, Real> nettingSetFca_exOwnSp_;
237 map<string, Real> nettingSetFca_exAllSp_;
238 map<string, Real> nettingSetMva_;
239};
240
241} // namespace analytics
242} // namespace ore
const map< string, Real > & nettingSetSumDva()
Sum DVA map for all the netting sets.
const Real & tradeFca(const string &trade)
FCA for the specified trade.
QuantLib::ext::shared_ptr< Market > market_
const Real & tradeFca_exAllSp(const string &trade)
FCA (excl all survival probability) for the specified trade.
const map< string, Real > & tradeDva()
DVA map for all the trades.
virtual const Real calculateNettingSetCvaIncrement(const string &nid, const string &cid, const Date &d0, const Date &d1, const Real &rr)=0
const Real & tradeFba_exOwnSp(const string &trade)
FBA (excl own survival probability) for the specified trade.
const Real & nettingSetFba_exOwnSp(const string &nettingSet)
FBA (excl own survival probability) for the specified netting set.
virtual const Real calculateFcaIncrement(const string &tid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf)=0
const Real & tradeFba(const string &trade)
FBA for the specified trade.
virtual const Real calculateDvaIncrement(const string &tid, const Date &d0, const Date &d1, const Real &rr)=0
virtual const Real calculateNettingSetDvaIncrement(const string &nid, const Date &d0, const Date &d1, const Real &rr)=0
const Real & nettingSetFba_exAllSp(const string &nettingSet)
FBA (excl all survival probability) for the specified netting set.
virtual void build()
Compute cva along all paths and fill result structures.
const Real & nettingSetFca(const string &nettingSet)
FCA for the specified netting set.
virtual const Real calculateNettingSetFcaIncrement(const string &nid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf)=0
virtual const Real calculateFbaIncrement(const string &tid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf)=0
virtual const vector< Date > & dates()
const map< string, Real > & tradeCva()
CVA map for all the trades.
const Real & nettingSetFca_exOwnSp(const string &nettingSet)
FCA (excl own survival probability) for the specified netting set.
QuantLib::ext::shared_ptr< Portfolio > portfolio_
const map< string, Real > & nettingSetDva()
DVA map for all the netting sets.
const map< string, Real > & nettingSetSumCva()
Sum CVA map for all the netting sets.
const Real & tradeMva(const string &trade)
MVA for the specified trade.
virtual const Real calculateCvaIncrement(const string &tid, const string &cid, const Date &d0, const Date &d1, const Real &rr)=0
const Real & nettingSetFba(const string &nettingSet)
FBA for the specified netting set.
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator_
virtual const Real calculateNettingSetFbaIncrement(const string &nid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf)=0
const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube_
virtual const Real calculateNettingSetMvaIncrement(const string &nid, const string &cid, const Date &d0, const Date &d1, const Real &dcf)=0
const map< string, Real > & nettingSetCva()
CVA map for all the netting sets.
const Real & nettingSetFca_exAllSp(const string &nettingSet)
FCA (excl all survival probability) for the specified netting set.
const Real & tradeFba_exAllSp(const string &trade)
FBA (excl all survival probability) for the specified trade.
const Real & tradeFca_exOwnSp(const string &trade)
FCA (excl own survival probability) for the specified trade.
const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_
const Real & nettingSetMva(const string &nettingSet)
MVA for the specified netting set.
Dynamic Initial Margin calculator base class.
data