21#include <boost/accumulators/accumulators.hpp>
22#include <boost/accumulators/statistics/error_of_mean.hpp>
23#include <boost/accumulators/statistics/mean.hpp>
24#include <boost/accumulators/statistics/stats.hpp>
29using namespace boost::accumulators;
36 const QuantLib::ext::shared_ptr<Portfolio> portfolio,
const QuantLib::ext::shared_ptr<Market> market,
37 const string& configuration,
const string& baseCurrency,
const string& dvaName,
38 const string& fvaBorrowingCurve,
const string& fvaLendingCurve,
39 const bool applyDynamicInitialMargin,
40 const QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator,
41 const QuantLib::ext::shared_ptr<NPVCube> tradeExposureCube,
42 const QuantLib::ext::shared_ptr<NPVCube> nettingSetExposureCube,
43 const QuantLib::ext::shared_ptr<NPVCube>& cptyCube,
44 const Size tradeEpeIndex,
const Size tradeEneIndex,
45 const Size nettingSetEpeIndex,
const Size nettingSetEneIndex,
const Size cptySpIndex,
46 const bool flipViewXVA,
const string& flipViewBorrowingCurvePostfix,
const string& flipViewLendingCurvePostfix)
48 fvaBorrowingCurve, fvaLendingCurve, applyDynamicInitialMargin,
49 dimCalculator, tradeExposureCube, nettingSetExposureCube, tradeEpeIndex, tradeEneIndex,
50 nettingSetEpeIndex, nettingSetEneIndex,
51 flipViewXVA, flipViewBorrowingCurvePostfix, flipViewLendingCurvePostfix),
52 cptyCube_(cptyCube), cptySpIndex_(cptySpIndex) {
56 "number of dates in tradeExposureCube and cptyCube mismatch ("
59 QL_REQUIRE(cptySpIndex < cptyCube->depth(),
"cptySpIndex("
60 << cptySpIndex <<
") exceeds depth of cptyCube("
61 << cptyCube->depth() <<
")");
65 "date at " << i <<
" in tradeExposureCube and cptyCube mismatch ("
72 const string& tid,
const string& cid,
const Date& d0,
const Date& d1,
const Real& rr) {
78 increment += (s0 - s1) * epe;
84 const string& tid,
const Date& d0,
const Date& d1,
const Real& rr) {
90 increment += (s0 - s1) * ene;
96 const string& nid,
const string& cid,
const Date& d0,
const Date& d1,
const Real& rr) {
102 increment += (s0 - s1) * epe;
108 const string& nid,
const Date& d0,
const Date& d1,
const Real& rr) {
109 Real increment = 0.0;
114 increment += (s0 - s1) * ene;
120 const string& tid,
const string& cid,
const string& dvaName,
121 const Date& d0,
const Date& d1,
const Real& dcf) {
122 Real increment = 0.0;
127 increment += s0 * s1 * ene;
133 const string& tid,
const string& cid,
const string& dvaName,
134 const Date& d0,
const Date& d1,
const Real& dcf) {
135 Real increment = 0.0;
140 increment += s0 * s1 * epe;
146 const string& nid,
const string& cid,
const string& dvaName,
147 const Date& d0,
const Date& d1,
const Real& dcf) {
148 Real increment = 0.0;
153 increment += s0 * s1 * ene;
159 const string& nid,
const string& cid,
const string& dvaName,
160 const Date& d0,
const Date& d1,
const Real& dcf) {
161 Real increment = 0.0;
166 increment += s0 * s1 * epe;
172 const string& nid,
const string& cid,
const Date& d0,
const Date& d1,
const Real& dcf) {
174 Real increment = 0.0;
179 increment += s0 * s1 * im;
virtual const Real calculateNettingSetDvaIncrement(const string &nid, const Date &d0, const Date &d1, const Real &rr) override
const QuantLib::ext::shared_ptr< NPVCube > & cptyCube_
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 calculateFbaIncrement(const string &tid, 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
virtual const Real calculateCvaIncrement(const string &tid, const string &cid, const Date &d0, const Date &d1, const Real &rr) override
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 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 calculateNettingSetFbaIncrement(const string &nid, 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
XVA Calculator base class.
virtual const Date asof()
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator_
const QuantLib::ext::shared_ptr< NPVCube > nettingSetExposureCube_
const QuantLib::ext::shared_ptr< NPVCube > tradeExposureCube_
XVA calculator with dynamic credit.