Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
DynamicCreditXvaCalculator Class Reference

XVA Calculator base with dynamic credit. More...

#include <orea/aggregation/dynamiccreditxvacalculator.hpp>

+ Inheritance diagram for DynamicCreditXvaCalculator:
+ Collaboration diagram for DynamicCreditXvaCalculator:

Public Member Functions

 DynamicCreditXvaCalculator (const QuantLib::ext::shared_ptr< Portfolio > portfolio, const QuantLib::ext::shared_ptr< Market > market, const string &configuration, const string &baseCurrency, const string &dvaName, const string &fvaBorrowingCurve, const string &fvaLendingCurve, const bool applyDynamicInitialMargin, const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator, const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube, const QuantLib::ext::shared_ptr< NPVCube > &cptyCube, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=0, const Size nettingSetEneIndex=1, const Size cptySpIndex=0, const bool flipViewXVA=false, const string &flipViewBorrowingCurvePostfix="_BORROW", const string &flipViewLendingCurvePostfix="_LEND")
 
virtual const Real calculateCvaIncrement (const string &tid, const string &cid, const Date &d0, const Date &d1, const Real &rr) override
 
virtual const Real calculateDvaIncrement (const string &tid, const Date &d0, const Date &d1, const Real &rr) override
 
virtual const Real calculateNettingSetCvaIncrement (const string &nid, const string &cid, const Date &d0, const Date &d1, const Real &rr) override
 
virtual const Real calculateNettingSetDvaIncrement (const string &nid, const Date &d0, const Date &d1, const Real &rr) override
 
virtual const Real calculateFbaIncrement (const string &tid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf) override
 
virtual const Real calculateFcaIncrement (const string &tid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf) override
 
virtual const Real calculateNettingSetFbaIncrement (const string &nid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf) override
 
virtual const Real calculateNettingSetFcaIncrement (const string &nid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf) override
 
virtual const Real calculateNettingSetMvaIncrement (const string &nid, const string &cid, const Date &d0, const Date &d1, const Real &dcf) override
 
- Public Member Functions inherited from ValueAdjustmentCalculator
 ValueAdjustmentCalculator (const QuantLib::ext::shared_ptr< Portfolio > portfolio, const QuantLib::ext::shared_ptr< Market > market, const string &configuration, const string &baseCurrency, const string &dvaName, const string &fvaBorrowingCurve, const string &fvaLendingCurve, const bool applyDynamicInitialMargin, const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator, const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=1, const Size nettingSetEneIndex=2, const bool flipViewXVA=false, const string &flipViewBorrowingCurvePostfix="_BORROW", const string &flipViewLendingCurvePostfix="_LEND")
 
virtual ~ValueAdjustmentCalculator ()
 
virtual void build ()
 Compute cva along all paths and fill result structures. More...
 
virtual const vector< Date > & dates ()
 
virtual const Date asof ()
 
virtual const Real calculateCvaIncrement (const string &tid, const string &cid, const Date &d0, const Date &d1, const Real &rr)=0
 
virtual const Real calculateDvaIncrement (const string &tid, const Date &d0, const Date &d1, const Real &rr)=0
 
virtual const Real calculateNettingSetCvaIncrement (const string &nid, const string &cid, 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
 
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 Real calculateFcaIncrement (const string &tid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf)=0
 
virtual const Real calculateNettingSetFbaIncrement (const string &nid, const string &cid, const string &dvaName, const Date &d0, const Date &d1, const Real &dcf)=0
 
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 calculateNettingSetMvaIncrement (const string &nid, const string &cid, const Date &d0, const Date &d1, const Real &dcf)=0
 
const map< string, Real > & tradeCva ()
 CVA map for all the trades. More...
 
const map< string, Real > & tradeDva ()
 DVA map for all the trades. More...
 
const map< string, Real > & nettingSetCva ()
 CVA map for all the netting sets. More...
 
const map< string, Real > & nettingSetDva ()
 DVA map for all the netting sets. More...
 
const map< string, Real > & nettingSetSumCva ()
 Sum CVA map for all the netting sets. More...
 
const map< string, Real > & nettingSetSumDva ()
 Sum DVA map for all the netting sets. More...
 
const Real & tradeCva (const string &trade)
 CVA for the specified trade. More...
 
const Real & tradeDva (const string &trade)
 DVA for the specified trade. More...
 
const Real & tradeFba (const string &trade)
 FBA for the specified trade. More...
 
const Real & tradeFba_exOwnSp (const string &trade)
 FBA (excl own survival probability) for the specified trade. More...
 
const Real & tradeFba_exAllSp (const string &trade)
 FBA (excl all survival probability) for the specified trade. More...
 
const Real & tradeFca (const string &trade)
 FCA for the specified trade. More...
 
const Real & tradeFca_exOwnSp (const string &trade)
 FCA (excl own survival probability) for the specified trade. More...
 
const Real & tradeFca_exAllSp (const string &trade)
 FCA (excl all survival probability) for the specified trade. More...
 
const Real & tradeMva (const string &trade)
 MVA for the specified trade. More...
 
const Real & nettingSetSumCva (const string &nettingSet)
 Sum of trades' CVA for the specified netting set. More...
 
const Real & nettingSetSumDva (const string &nettingSet)
 Sum of trades' DVA for the specified netting set. More...
 
const Real & nettingSetCva (const string &nettingSet)
 CVA for the specified netting set. More...
 
const Real & nettingSetDva (const string &nettingSet)
 DVA for the specified netting set. More...
 
const Real & nettingSetFba (const string &nettingSet)
 FBA for the specified netting set. More...
 
const Real & nettingSetFba_exOwnSp (const string &nettingSet)
 FBA (excl own survival probability) for the specified netting set. More...
 
const Real & nettingSetFba_exAllSp (const string &nettingSet)
 FBA (excl all survival probability) for the specified netting set. More...
 
const Real & nettingSetFca (const string &nettingSet)
 FCA for the specified netting set. More...
 
const Real & nettingSetFca_exOwnSp (const string &nettingSet)
 FCA (excl own survival probability) for the specified netting set. More...
 
const Real & nettingSetFca_exAllSp (const string &nettingSet)
 FCA (excl all survival probability) for the specified netting set. More...
 
const Real & nettingSetMva (const string &nettingSet)
 MVA for the specified netting set. More...
 

Protected Attributes

const QuantLib::ext::shared_ptr< NPVCube > & cptyCube_
 
Size cptySpIndex_
 
- Protected Attributes inherited from ValueAdjustmentCalculator
QuantLib::ext::shared_ptr< Portfolioportfolio_
 
QuantLib::ext::shared_ptr< Marketmarket_
 
string configuration_
 
string baseCurrency_
 
string dvaName_
 
string fvaBorrowingCurve_
 
string fvaLendingCurve_
 
bool applyDynamicInitialMargin_
 
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculatordimCalculator_
 
const QuantLib::ext::shared_ptr< NPVCubetradeExposureCube_
 
const QuantLib::ext::shared_ptr< NPVCubenettingSetExposureCube_
 
Size tradeEpeIndex_
 
Size tradeEneIndex_
 
Size nettingSetEpeIndex_
 
Size nettingSetEneIndex_
 
bool flipViewXVA_
 
string flipViewBorrowingCurvePostfix_
 
string flipViewLendingCurvePostfix_
 
map< string, string > nettingSetCpty_
 
map< string, Real > tradeCva_
 
map< string, Real > tradeDva_
 
map< string, Real > tradeFba_
 
map< string, Real > tradeFba_exOwnSp_
 
map< string, Real > tradeFba_exAllSp_
 
map< string, Real > tradeFca_
 
map< string, Real > tradeFca_exOwnSp_
 
map< string, Real > tradeFca_exAllSp_
 
map< string, Real > tradeMva_
 
map< string, Real > nettingSetSumCva_
 
map< string, Real > nettingSetSumDva_
 
map< string, Real > nettingSetCva_
 
map< string, Real > nettingSetDva_
 
map< string, Real > nettingSetFba_
 
map< string, Real > nettingSetFba_exOwnSp_
 
map< string, Real > nettingSetFba_exAllSp_
 
map< string, Real > nettingSetFca_
 
map< string, Real > nettingSetFca_exOwnSp_
 
map< string, Real > nettingSetFca_exAllSp_
 
map< string, Real > nettingSetMva_
 

Detailed Description

XVA Calculator base with dynamic credit.

XVA is calculated using survival probability from each path

Definition at line 39 of file dynamiccreditxvacalculator.hpp.

Constructor & Destructor Documentation

◆ DynamicCreditXvaCalculator()

DynamicCreditXvaCalculator ( const QuantLib::ext::shared_ptr< Portfolio portfolio,
const QuantLib::ext::shared_ptr< Market market,
const string &  configuration,
const string &  baseCurrency,
const string &  dvaName,
const string &  fvaBorrowingCurve,
const string &  fvaLendingCurve,
const bool  applyDynamicInitialMargin,
const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator dimCalculator,
const QuantLib::ext::shared_ptr< NPVCube tradeExposureCube,
const QuantLib::ext::shared_ptr< NPVCube nettingSetExposureCube,
const QuantLib::ext::shared_ptr< NPVCube > &  cptyCube,
const Size  tradeEpeIndex = 0,
const Size  tradeEneIndex = 1,
const Size  nettingSetEpeIndex = 0,
const Size  nettingSetEneIndex = 1,
const Size  cptySpIndex = 0,
const bool  flipViewXVA = false,
const string &  flipViewBorrowingCurvePostfix = "_BORROW",
const string &  flipViewLendingCurvePostfix = "_LEND" 
)
Parameters
portfolioDriving portfolio consistent with the cube below
marketToday's market
configurationMarket configuration to be used
baseCurrencyBase currency amounts will be converted to
dvaNameOwn party name for DVA calculations
fvaBorrowingCurveFVA borrowing curve
fvaLendingCurveFVA lending curve
applyDynamicInitialMarginDeactivate initial margin calculation even if active at netting set level
dimCalculatorDynamic Initial Margin calculator
tradeExposureCubeStorage ofdefault NPVs, close-out NPVs, cash flows at trade level
nettingSetExposureCubeStorage of sensitivity vectors at netting set level
cptyCubeStorage for counterparty survival probabilities
tradeEpeIndexIndex of the trade EPE storage in the internal exposure cube
tradeEneIndexIndex of the trade ENE storage in the internal exposure cube
nettingSetEpeIndexIndex of the netting set EPE storage in the internal exposure cube
nettingSetEneIndexIndex of the netting set ENE storage in the internal exposure cube
cptySpIndexIndex of the counterparty survivalprobability storage
flipViewXVAFlag to indicate flipped xva calculation
flipViewBorrowingCurvePostfixPostfix for flipView borrowing curves for fva
flipViewLendingCurvePostfixPostfix for flipView lending curves for fva

Definition at line 34 of file dynamiccreditxvacalculator.cpp.

47 : ValueAdjustmentCalculator(portfolio, market, configuration, baseCurrency, dvaName,
48 fvaBorrowingCurve, fvaLendingCurve, applyDynamicInitialMargin,
49 dimCalculator, tradeExposureCube, nettingSetExposureCube, tradeEpeIndex, tradeEneIndex,
50 nettingSetEpeIndex, nettingSetEneIndex,
51 flipViewXVA, flipViewBorrowingCurvePostfix, flipViewLendingCurvePostfix),
52 cptyCube_(cptyCube), cptySpIndex_(cptySpIndex) {
53 // check consistency of input
54
55 QL_REQUIRE(tradeExposureCube_->numDates() == cptyCube->numDates(),
56 "number of dates in tradeExposureCube and cptyCube mismatch ("
57 << tradeExposureCube_->numDates() << " vs " << cptyCube->numDates() << ")");
58
59 QL_REQUIRE(cptySpIndex < cptyCube->depth(), "cptySpIndex("
60 << cptySpIndex << ") exceeds depth of cptyCube("
61 << cptyCube->depth() << ")");
62
63 for (Size i = 0; i < tradeExposureCube_->numDates(); i++) {
64 QL_REQUIRE(tradeExposureCube_->dates()[i] == cptyCube->dates()[i],
65 "date at " << i << " in tradeExposureCube and cptyCube mismatch ("
66 << tradeExposureCube_->dates()[i] << " vs " << cptyCube->dates()[i] << ")");
67 }
68}
const QuantLib::ext::shared_ptr< NPVCube > & cptyCube_
ValueAdjustmentCalculator(const QuantLib::ext::shared_ptr< Portfolio > portfolio, const QuantLib::ext::shared_ptr< Market > market, const string &configuration, const string &baseCurrency, const string &dvaName, const string &fvaBorrowingCurve, const string &fvaLendingCurve, const bool applyDynamicInitialMargin, const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator, const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube, const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube, const Size tradeEpeIndex=0, const Size tradeEneIndex=1, const Size nettingSetEpeIndex=1, const Size nettingSetEneIndex=2, const bool flipViewXVA=false, const string &flipViewBorrowingCurvePostfix="_BORROW", const string &flipViewLendingCurvePostfix="_LEND")
const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_

Member Function Documentation

◆ calculateCvaIncrement()

const Real calculateCvaIncrement ( const string &  tid,
const string &  cid,
const Date &  d0,
const Date &  d1,
const Real &  rr 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 71 of file dynamiccreditxvacalculator.cpp.

72 {
73 Real increment = 0.0;
74 for (Size k = 0; k < tradeExposureCube_->samples(); ++k) {
75 Real s0 = d0 == asof() ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
76 Real s1 = cptyCube_->get(cid, d1, k, cptySpIndex_);
77 Real epe = tradeExposureCube_->get(tid, d1, k, tradeEpeIndex_);
78 increment += (s0 - s1) * epe;
79 }
80 return (1.0 - rr) * increment / tradeExposureCube_->samples();
81}
+ Here is the call graph for this function:

◆ calculateDvaIncrement()

const Real calculateDvaIncrement ( const string &  tid,
const Date &  d0,
const Date &  d1,
const Real &  rr 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 83 of file dynamiccreditxvacalculator.cpp.

84 {
85 Real increment = 0.0;
86 for (Size k = 0; k < tradeExposureCube_->samples(); ++k) {
87 Real s0 = d0 == asof() ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
88 Real s1 = cptyCube_->get(dvaName_, d1, k, cptySpIndex_);
89 Real ene = tradeExposureCube_->get(tid, d1, k, tradeEneIndex_);
90 increment += (s0 - s1) * ene;
91 }
92 return (1.0 - rr) * increment / tradeExposureCube_->samples();
93}
+ Here is the call graph for this function:

◆ calculateNettingSetCvaIncrement()

const Real calculateNettingSetCvaIncrement ( const string &  nid,
const string &  cid,
const Date &  d0,
const Date &  d1,
const Real &  rr 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 95 of file dynamiccreditxvacalculator.cpp.

96 {
97 Real increment = 0.0;
98 for (Size k = 0; k < nettingSetExposureCube_->samples(); ++k) {
99 Real s0 = d0 == asof() ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
100 Real s1 = cptyCube_->get(cid, d1, k, cptySpIndex_);
101 Real epe = nettingSetExposureCube_->get(nid, d1, k, nettingSetEpeIndex_);
102 increment += (s0 - s1) * epe;
103 }
104 return (1.0 - rr) * increment / nettingSetExposureCube_->samples();
105}
const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube_
+ Here is the call graph for this function:

◆ calculateNettingSetDvaIncrement()

const Real calculateNettingSetDvaIncrement ( const string &  nid,
const Date &  d0,
const Date &  d1,
const Real &  rr 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 107 of file dynamiccreditxvacalculator.cpp.

108 {
109 Real increment = 0.0;
110 for (Size k = 0; k < nettingSetExposureCube_->samples(); ++k) {
111 Real s0 = d0 == asof() ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
112 Real s1 = cptyCube_->get(dvaName_, d1, k, cptySpIndex_);
113 Real ene = nettingSetExposureCube_->get(nid, d1, k, nettingSetEneIndex_);
114 increment += (s0 - s1) * ene;
115 }
116 return (1.0 - rr) * increment / nettingSetExposureCube_->samples();
117}
+ Here is the call graph for this function:

◆ calculateFbaIncrement()

const Real calculateFbaIncrement ( const string &  tid,
const string &  cid,
const string &  dvaName,
const Date &  d0,
const Date &  d1,
const Real &  dcf 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 119 of file dynamiccreditxvacalculator.cpp.

121 {
122 Real increment = 0.0;
123 for (Size k = 0; k < tradeExposureCube_->samples(); ++k) {
124 Real s0 = (d0 == asof() || cid == "") ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
125 Real s1 = (d0 == asof() || dvaName == "") ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
126 Real ene = tradeExposureCube_->get(tid, d1, k, tradeEneIndex_);
127 increment += s0 * s1 * ene;
128 }
129 return increment * dcf / tradeExposureCube_->samples();
130}
+ Here is the call graph for this function:

◆ calculateFcaIncrement()

const Real calculateFcaIncrement ( const string &  tid,
const string &  cid,
const string &  dvaName,
const Date &  d0,
const Date &  d1,
const Real &  dcf 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 132 of file dynamiccreditxvacalculator.cpp.

134 {
135 Real increment = 0.0;
136 for (Size k = 0; k < tradeExposureCube_->samples(); ++k) {
137 Real s0 = (d0 == asof() || cid == "") ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
138 Real s1 = (d0 == asof() || dvaName == "") ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
139 Real epe = tradeExposureCube_->get(tid, d1, k, tradeEpeIndex_);
140 increment += s0 * s1 * epe;
141 }
142 return increment * dcf / tradeExposureCube_->samples();
143}
+ Here is the call graph for this function:

◆ calculateNettingSetFbaIncrement()

const Real calculateNettingSetFbaIncrement ( const string &  nid,
const string &  cid,
const string &  dvaName,
const Date &  d0,
const Date &  d1,
const Real &  dcf 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 145 of file dynamiccreditxvacalculator.cpp.

147 {
148 Real increment = 0.0;
149 for (Size k = 0; k < nettingSetExposureCube_->samples(); ++k) {
150 Real s0 = (d0 == asof() || cid == "") ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
151 Real s1 = (d0 == asof() || dvaName == "") ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
152 Real ene = nettingSetExposureCube_->get(nid, d1, k, nettingSetEneIndex_);
153 increment += s0 * s1 * ene;
154 }
155 return increment * dcf / nettingSetExposureCube_->samples();
156}
+ Here is the call graph for this function:

◆ calculateNettingSetFcaIncrement()

const Real calculateNettingSetFcaIncrement ( const string &  nid,
const string &  cid,
const string &  dvaName,
const Date &  d0,
const Date &  d1,
const Real &  dcf 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 158 of file dynamiccreditxvacalculator.cpp.

160 {
161 Real increment = 0.0;
162 for (Size k = 0; k < nettingSetExposureCube_->samples(); ++k) {
163 Real s0 = (d0 == asof() || cid == "") ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
164 Real s1 = (d0 == asof() || dvaName == "") ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
165 Real epe = nettingSetExposureCube_->get(nid, d1, k, nettingSetEpeIndex_);
166 increment += s0 * s1 * epe;
167 }
168 return increment * dcf / nettingSetExposureCube_->samples();
169}
+ Here is the call graph for this function:

◆ calculateNettingSetMvaIncrement()

const Real calculateNettingSetMvaIncrement ( const string &  nid,
const string &  cid,
const Date &  d0,
const Date &  d1,
const Real &  dcf 
)
overridevirtual

Implements ValueAdjustmentCalculator.

Definition at line 171 of file dynamiccreditxvacalculator.cpp.

172 {
173
174 Real increment = 0.0;
175 for (Size k = 0; k < nettingSetExposureCube_->samples(); ++k) {
176 Real s0 = (d0 == asof() || cid == "") ? 1.0 : cptyCube_->get(cid, d0, k, cptySpIndex_);
177 Real s1 = (d0 == asof() || dvaName_ == "") ? 1.0 : cptyCube_->get(dvaName_, d0, k, cptySpIndex_);
178 Real im = dimCalculator_->dimCube()->get(nid, d1, k);
179 increment += s0 * s1 * im;
180 }
181 return increment * dcf / nettingSetExposureCube_->samples();
182}
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator_
+ Here is the call graph for this function:

Member Data Documentation

◆ cptyCube_

const QuantLib::ext::shared_ptr<NPVCube>& cptyCube_
protected

Definition at line 103 of file dynamiccreditxvacalculator.hpp.

◆ cptySpIndex_

Size cptySpIndex_
protected

Definition at line 104 of file dynamiccreditxvacalculator.hpp.