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

XVA Calculator base with static credit. More...

#include <orea/aggregation/staticcreditxvacalculator.hpp>

+ Inheritance diagram for StaticCreditXvaCalculator:
+ Collaboration diagram for StaticCreditXvaCalculator:

Public Member Functions

 StaticCreditXvaCalculator (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 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

map< Date, Size > dateIndexMap_
 
- 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 static credit.

XVA is calculated using survival probability from market

Definition at line 39 of file staticcreditxvacalculator.hpp.

Constructor & Destructor Documentation

◆ StaticCreditXvaCalculator()

StaticCreditXvaCalculator ( 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" 
)
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
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
flipViewXVAFlag to indicate flipped xva calculation
flipViewBorrowingCurvePostfixPostfix for flipView borrowing curve for fva
flipViewLendingCurvePostfixPostfix for flipView lending curve for fva

Definition at line 34 of file staticcreditxvacalculator.cpp.

45 : ValueAdjustmentCalculator(portfolio, market, configuration, baseCurrency, dvaName,
46 fvaBorrowingCurve, fvaLendingCurve, applyDynamicInitialMargin,
47 dimCalculator, tradeExposureCube, nettingSetExposureCube, tradeEpeIndex, tradeEneIndex,
48 nettingSetEpeIndex, nettingSetEneIndex,
49 flipViewXVA, flipViewBorrowingCurvePostfix, flipViewLendingCurvePostfix) {
50 for (Size i = 0; i < dates().size(); i++) {
51 dateIndexMap_.emplace(dates()[i], i);
52 }
53}
virtual const vector< Date > & dates()
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")
+ Here is the call graph for this function:

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 56 of file staticcreditxvacalculator.cpp.

57 {
58 Handle<DefaultProbabilityTermStructure> dts = market_->defaultCurve(cid, configuration_)->curve();
59 QL_REQUIRE(!dts.empty(), "Default curve missing for counterparty " << cid);
60 Real increment = 0.0;
61 Real s0 = dts->survivalProbability(d0);
62 Real s1 = dts->survivalProbability(d1);
63 Real epe = tradeExposureCube_->get(tid, d1, 0, tradeEpeIndex_);
64 increment = (1.0 - rr) * (s0 - s1) * epe;
65 return increment;
66}
QuantLib::ext::shared_ptr< Market > market_
const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_

◆ calculateDvaIncrement()

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

Implements ValueAdjustmentCalculator.

Definition at line 68 of file staticcreditxvacalculator.cpp.

69 {
70 Handle<DefaultProbabilityTermStructure> dts = market_->defaultCurve(dvaName_, configuration_)->curve();
71 QL_REQUIRE(!dts.empty(), "Default curve missing for dvaName " << dvaName_);
72 Real increment = 0.0;
73 Real s0 = dts->survivalProbability(d0);
74 Real s1 = dts->survivalProbability(d1);
75 Real ene = tradeExposureCube_->get(tid, d1, 0, tradeEneIndex_);
76 increment = (1.0 - rr) * (s0 - s1) * ene;
77 return increment;
78}

◆ 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 80 of file staticcreditxvacalculator.cpp.

81 {
82 Handle<DefaultProbabilityTermStructure> dts = market_->defaultCurve(cid, configuration_)->curve();
83 QL_REQUIRE(!dts.empty(), "Default curve missing for counterparty " << cid);
84 Real increment = 0.0;
85 Real s0 = dts->survivalProbability(d0);
86 Real s1 = dts->survivalProbability(d1);
87 Real epe = nettingSetExposureCube_->get(nid, d1, 0, nettingSetEpeIndex_);
88 increment = (1.0 - rr) * (s0 - s1) * epe;
89 return increment;
90}
const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube_

◆ calculateNettingSetDvaIncrement()

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

Implements ValueAdjustmentCalculator.

Definition at line 92 of file staticcreditxvacalculator.cpp.

93 {
94 Handle<DefaultProbabilityTermStructure> dts = market_->defaultCurve(dvaName_, configuration_)->curve();
95 QL_REQUIRE(!dts.empty(), "Default curve missing for dvaName " << dvaName_);
96 Real increment = 0.0;
97 Real s0 = dts->survivalProbability(d0);
98 Real s1 = dts->survivalProbability(d1);
99 Real ene = nettingSetExposureCube_->get(nid, d1, 0, nettingSetEneIndex_);
100 increment = (1.0 - rr) * (s0 - s1) * ene;
101 return increment;
102}

◆ 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 104 of file staticcreditxvacalculator.cpp.

106 {
107 Handle<DefaultProbabilityTermStructure> dts_cid;
108 Handle<DefaultProbabilityTermStructure> dts_dvaName;
109 if (cid != "") {
110 dts_cid = market_->defaultCurve(cid, configuration_)->curve();
111 QL_REQUIRE(!dts_cid.empty(), "Default curve missing for counterparty " << cid);
112 }
113 if (dvaName != "") {
114 dts_dvaName = market_->defaultCurve(dvaName, configuration_)->curve();
115 QL_REQUIRE(!dts_dvaName.empty(), "Default curve missing for dvaName " << dvaName);
116 }
117
118 Real increment = 0.0;
119 Real s0 = cid == "" ? 1.0 : dts_cid->survivalProbability(d0);
120 Real s1 = dvaName == "" ? 1.0 : dts_dvaName->survivalProbability(d0);
121 Real ene = tradeExposureCube_->get(tid, d1, 0, tradeEneIndex_);
122 increment = s0 * s1 * ene * dcf;
123 return increment;
124}

◆ 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 126 of file staticcreditxvacalculator.cpp.

128 {
129 Handle<DefaultProbabilityTermStructure> dts_cid;
130 Handle<DefaultProbabilityTermStructure> dts_dvaName;
131 if (cid != "") {
132 dts_cid = market_->defaultCurve(cid, configuration_)->curve();
133 QL_REQUIRE(!dts_cid.empty(), "Default curve missing for counterparty " << cid);
134 }
135 if (dvaName != "") {
136 dts_dvaName = market_->defaultCurve(dvaName, configuration_)->curve();
137 QL_REQUIRE(!dts_dvaName.empty(), "Default curve missing for dvaName " << dvaName);
138 }
139
140 Real increment = 0.0;
141 Real s0 = cid == "" ? 1.0 : dts_cid->survivalProbability(d0);
142 Real s1 = dvaName == "" ? 1.0 : dts_dvaName->survivalProbability(d0);
143 Real epe = tradeExposureCube_->get(tid, d1, 0, tradeEpeIndex_);
144 increment = s0 * s1 * epe * dcf;
145 return increment;
146}

◆ 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 148 of file staticcreditxvacalculator.cpp.

150 {
151 Handle<DefaultProbabilityTermStructure> dts_cid;
152 Handle<DefaultProbabilityTermStructure> dts_dvaName;
153 if (cid != "") {
154 dts_cid = market_->defaultCurve(cid, configuration_)->curve();
155 QL_REQUIRE(!dts_cid.empty(), "Default curve missing for counterparty " << cid);
156 }
157 if (dvaName != "") {
158 dts_dvaName = market_->defaultCurve(dvaName, configuration_)->curve();
159 QL_REQUIRE(!dts_dvaName.empty(), "Default curve missing for dvaName " << dvaName);
160 }
161
162 Real increment = 0.0;
163 Real s0 = cid == "" ? 1.0 : dts_cid->survivalProbability(d0);
164 Real s1 = dvaName == "" ? 1.0 : dts_dvaName->survivalProbability(d0);
165 Real ene = nettingSetExposureCube_->get(nid, d1, 0, nettingSetEneIndex_);
166 increment = s0 * s1 * ene * dcf;
167 return increment;
168}

◆ 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 170 of file staticcreditxvacalculator.cpp.

172 {
173 Handle<DefaultProbabilityTermStructure> dts_cid;
174 Handle<DefaultProbabilityTermStructure> dts_dvaName;
175 if (cid != "") {
176 dts_cid = market_->defaultCurve(cid, configuration_)->curve();
177 QL_REQUIRE(!dts_cid.empty(), "Default curve missing for counterparty " << cid);
178 }
179 if (dvaName != "") {
180 dts_dvaName = market_->defaultCurve(dvaName, configuration_)->curve();
181 QL_REQUIRE(!dts_dvaName.empty(), "Default curve missing for dvaName " << dvaName);
182 }
183
184 Real increment = 0.0;
185 Real s0 = cid == "" ? 1.0 : dts_cid->survivalProbability(d0);
186 Real s1 = dvaName == "" ? 1.0 : dts_dvaName->survivalProbability(d0);
187 Real epe = nettingSetExposureCube_->get(nid, d1, 0, nettingSetEpeIndex_);
188 increment = s0 * s1 * epe * dcf;
189 return increment;
190}

◆ 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 192 of file staticcreditxvacalculator.cpp.

193 {
194 Handle<DefaultProbabilityTermStructure> dts_cid = market_->defaultCurve(cid, configuration_)->curve();
195 QL_REQUIRE(cid == "" || !dts_cid.empty(), "Default curve missing for counterparty " << cid);
196 Handle<DefaultProbabilityTermStructure> dts_dvaName = market_->defaultCurve(dvaName_, configuration_)->curve();
197 QL_REQUIRE(dvaName_ == "" || !dts_dvaName.empty(), "Default curve missing for dvaName " << dvaName_);
198
199 Real increment = 0.0;
200 Real s0 = cid == "" ? 1.0 : dts_cid->survivalProbability(d0);
201 Real s1 = dvaName_ == "" ? 1.0 : dts_dvaName->survivalProbability(d0);
202 increment = s0 * s1 * dimCalculator_->expectedIM(nid)[dateIndexMap_[d1]] * dcf;
203 return increment;
204}
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator_

Member Data Documentation

◆ dateIndexMap_

map<Date, Size> dateIndexMap_
protected

Definition at line 99 of file staticcreditxvacalculator.hpp.