Skip to content

Commit 1ecfd91

Browse files
damienbarkerjenkins
authored andcommitted
Merge remote-tracking branch 'origin/master' into QPR-12100
2 parents 8930666 + 0b70e6d commit 1ecfd91

24 files changed

Lines changed: 299 additions & 251 deletions

Docs/UserGuide/userguide.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,7 @@ \subsubsection{Analytics}\label{sec:analytics}
40374037
<Parameter name="flipViewXVA">N</Parameter>
40384038
<Parameter name="flipViewBorrowingCurvePostfix">_BORROW</Parameter>
40394039
<Parameter name="flipViewLendingCurvePostfix">_LEND</Parameter>
4040+
<Parameter name="mporCashFlowMode">NonePay</Parameter>
40404041
</Analytic>
40414042
</Analytics>
40424043
\end{minted}
@@ -4148,6 +4149,9 @@ \subsubsection{Analytics}\label{sec:analytics}
41484149
\item {\tt flipViewXVA:} If set to {\tt Y}, the perspective in XVA calculations is switched to the cpty view, the npvs and the netting sets being reverted during calculation. In order to get the lending/borrowing curve, the calculation assumes these curves being set up with the cptyname + the postfix given in the next two settings.
41494150
\item {\tt flipViewBorrowingCurvePostfix:} postfix for the borrowing curve, the calculation assumes this is curves being set up with cptyname + postfix given.
41504151
\item {\tt flipViewLendingCurvePostfix:} postfix for the lending curve, the calculation assumes this is curve being set up with cptyname + postfix given.
4152+
\item {\tt mporCashFlowMode:} Assumption about payment of cashflows within mpor period. One of NonePay, BothPay, WePay,
4153+
TheyPay, Unspecified. Defaults to Unspecified, in this case PP will assume NonePay if mpor sticky date is used,
4154+
otherwise to BothPay.
41514155
\end{itemize}
41524156

41534157
The two cube file outputs {\tt rawCubeOutputFile} and {\tt netCubeOutputFile} are provided for interactive analysis and visualisation purposes, see section

OREAnalytics/orea/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ simm/simmbucketmapperbase.cpp
9999
simm/simmcalculator.cpp
100100
simm/simmcalibration.cpp
101101
simm/simmconcentration.cpp
102+
simm/simmconcentrationcalibration.cpp
102103
simm/simmconcentrationisdav1_3.cpp
103104
simm/simmconcentrationisdav1_3_38.cpp
104105
simm/simmconcentrationisdav2_0.cpp
@@ -109,9 +110,9 @@ simm/simmconcentrationisdav2_3_8.cpp
109110
simm/simmconcentrationisdav2_5.cpp
110111
simm/simmconcentrationisdav2_5a.cpp
111112
simm/simmconcentrationisdav2_6.cpp
112-
simm/simmconcentrationcalibration.cpp
113113
simm/simmconfiguration.cpp
114114
simm/simmconfigurationbase.cpp
115+
simm/simmconfigurationcalibration.cpp
115116
simm/simmconfigurationisdav1_0.cpp
116117
simm/simmconfigurationisdav1_3.cpp
117118
simm/simmconfigurationisdav1_3_38.cpp
@@ -123,7 +124,6 @@ simm/simmconfigurationisdav2_3_8.cpp
123124
simm/simmconfigurationisdav2_5.cpp
124125
simm/simmconfigurationisdav2_5a.cpp
125126
simm/simmconfigurationisdav2_6.cpp
126-
simm/simmconfigurationcalibration.cpp
127127
simm/simmresults.cpp
128128
simm/utilities.cpp
129129
simulation/fixingmanager.cpp
@@ -248,6 +248,7 @@ simm/simmbucketmapperbase.hpp
248248
simm/simmcalculator.hpp
249249
simm/simmcalibration.hpp
250250
simm/simmconcentration.hpp
251+
simm/simmconcentrationcalibration.hpp
251252
simm/simmconcentrationisdav1_3.hpp
252253
simm/simmconcentrationisdav1_3_38.hpp
253254
simm/simmconcentrationisdav2_0.hpp
@@ -258,9 +259,9 @@ simm/simmconcentrationisdav2_3_8.hpp
258259
simm/simmconcentrationisdav2_5.hpp
259260
simm/simmconcentrationisdav2_5a.hpp
260261
simm/simmconcentrationisdav2_6.hpp
261-
simm/simmconcentrationcalibration.hpp
262262
simm/simmconfiguration.hpp
263263
simm/simmconfigurationbase.hpp
264+
simm/simmconfigurationcalibration.hpp
264265
simm/simmconfigurationisdav1_0.hpp
265266
simm/simmconfigurationisdav1_3.hpp
266267
simm/simmconfigurationisdav1_3_38.hpp
@@ -272,7 +273,6 @@ simm/simmconfigurationisdav2_3_8.hpp
272273
simm/simmconfigurationisdav2_5.hpp
273274
simm/simmconfigurationisdav2_5a.hpp
274275
simm/simmconfigurationisdav2_6.hpp
275-
simm/simmconfigurationcalibration.hpp
276276
simm/simmnamemapper.hpp
277277
simm/simmresults.hpp
278278
simm/utilities.hpp

OREAnalytics/orea/aggregation/nettedexposurecalculator.cpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,29 @@ namespace analytics {
3131

3232
NettedExposureCalculator::NettedExposureCalculator(
3333
const boost::shared_ptr<Portfolio>& portfolio, const boost::shared_ptr<Market>& market,
34-
const boost::shared_ptr<NPVCube>& cube,
35-
const string& baseCurrency, const string& configuration, const Real quantile,
36-
const CollateralExposureHelper::CalculationType calcType, const bool multiPath,
34+
const boost::shared_ptr<NPVCube>& cube, const string& baseCurrency, const string& configuration,
35+
const Real quantile, const CollateralExposureHelper::CalculationType calcType, const bool multiPath,
3736
const boost::shared_ptr<NettingSetManager>& nettingSetManager,
3837
const map<string, vector<vector<Real>>>& nettingSetDefaultValue,
3938
const map<string, vector<vector<Real>>>& nettingSetCloseOutValue,
4039
const map<string, vector<vector<Real>>>& nettingSetMporPositiveFlow,
4140
const map<string, vector<vector<Real>>>& nettingSetMporNegativeFlow,
4241
const boost::shared_ptr<AggregationScenarioData>& scenarioData,
43-
const boost::shared_ptr<CubeInterpretation> cubeInterpretation,
44-
const bool applyInitialMargin,
45-
const boost::shared_ptr<DynamicInitialMarginCalculator>& dimCalculator,
46-
const bool fullInitialCollateralisation,
47-
const bool marginalAllocation,
48-
const Real marginalAllocationLimit,
49-
const boost::shared_ptr<NPVCube>& tradeExposureCube,
50-
const Size allocatedEpeIndex,
51-
const Size allocatedEneIndex,
52-
const bool flipViewXVA,
53-
const bool withMporStickyDate,
54-
const ScenarioGeneratorData::MporCashFlowMode& mporCashFlowMode)
55-
: portfolio_(portfolio), market_(market), cube_(cube),
56-
baseCurrency_(baseCurrency), configuration_(configuration),
57-
quantile_(quantile), calcType_(calcType),
58-
multiPath_(multiPath), nettingSetManager_(nettingSetManager),
59-
nettingSetDefaultValue_(nettingSetDefaultValue),
60-
nettingSetCloseOutValue_(nettingSetCloseOutValue),
61-
nettingSetMporPositiveFlow_(nettingSetMporPositiveFlow),
62-
nettingSetMporNegativeFlow_(nettingSetMporNegativeFlow),
63-
scenarioData_(scenarioData), cubeInterpretation_(cubeInterpretation),
64-
applyInitialMargin_(applyInitialMargin), dimCalculator_(dimCalculator),
65-
fullInitialCollateralisation_(fullInitialCollateralisation),
66-
marginalAllocation_(marginalAllocation),
67-
marginalAllocationLimit_(marginalAllocationLimit),
42+
const boost::shared_ptr<CubeInterpretation> cubeInterpretation, const bool applyInitialMargin,
43+
const boost::shared_ptr<DynamicInitialMarginCalculator>& dimCalculator, const bool fullInitialCollateralisation,
44+
const bool marginalAllocation, const Real marginalAllocationLimit,
45+
const boost::shared_ptr<NPVCube>& tradeExposureCube, const Size allocatedEpeIndex, const Size allocatedEneIndex,
46+
const bool flipViewXVA, const bool withMporStickyDate, const MporCashFlowMode mporCashFlowMode)
47+
: portfolio_(portfolio), market_(market), cube_(cube), baseCurrency_(baseCurrency), configuration_(configuration),
48+
quantile_(quantile), calcType_(calcType), multiPath_(multiPath), nettingSetManager_(nettingSetManager),
49+
nettingSetDefaultValue_(nettingSetDefaultValue), nettingSetCloseOutValue_(nettingSetCloseOutValue),
50+
nettingSetMporPositiveFlow_(nettingSetMporPositiveFlow), nettingSetMporNegativeFlow_(nettingSetMporNegativeFlow),
51+
scenarioData_(scenarioData), cubeInterpretation_(cubeInterpretation), applyInitialMargin_(applyInitialMargin),
52+
dimCalculator_(dimCalculator), fullInitialCollateralisation_(fullInitialCollateralisation),
53+
marginalAllocation_(marginalAllocation), marginalAllocationLimit_(marginalAllocationLimit),
6854
tradeExposureCube_(tradeExposureCube), allocatedEpeIndex_(allocatedEpeIndex),
69-
allocatedEneIndex_(allocatedEneIndex), flipViewXVA_(flipViewXVA), withMporStickyDate_(withMporStickyDate), mporCashFlowMode_(mporCashFlowMode) {
55+
allocatedEneIndex_(allocatedEneIndex), flipViewXVA_(flipViewXVA), withMporStickyDate_(withMporStickyDate),
56+
mporCashFlowMode_(mporCashFlowMode) {
7057

7158
set<string> nettingSetIds;
7259
for (auto nettingSet : nettingSetDefaultValue) {
@@ -242,15 +229,26 @@ void NettedExposureCalculator::build() {
242229
Real mporCashFlow = 0;
243230
// If ActualDate is active, then the cash flows over mpor can be configured.
244231
// Otherwise (StickyDate is active), it is assumed that no cash flow over mpor is paid out.
245-
if (!withMporStickyDate_){
246-
if (mporCashFlowMode_ == ScenarioGeneratorData::MporCashFlowMode::BothPay) // in cube generation -actual date- the (+/-) cashflows over mpor are payed out, i.e. are not part of the exposure .
247-
mporCashFlow = 0;
248-
else if (mporCashFlowMode_ == ScenarioGeneratorData::MporCashFlowMode::NonePay) // +/- cashflows is to be incorporated in the exposure
232+
if (!withMporStickyDate_) {
233+
if (mporCashFlowMode_ == MporCashFlowMode::BothPay) {
234+
// in cube generation -actual date- the (+/-) cashflows over mpor are
235+
// payed out, i.e. are not part of the exposure .
236+
mporCashFlow = 0;
237+
} else if (mporCashFlowMode_ == MporCashFlowMode::NonePay) {
238+
// +/- cashflows is to be incorporated in the exposure
249239
mporCashFlow = (nettingSetMporPositiveFlow[j][k] + nettingSetMporNegativeFlow[j][k]);
250-
else if (mporCashFlowMode_ == ScenarioGeneratorData::MporCashFlowMode::WePay) // only positive cash flows (i.e. cp's cashflows) is to be incorporated in the exposure, since cp does not pay out cash flows
240+
} else if (mporCashFlowMode_ ==
241+
MporCashFlowMode::WePay) {
242+
// only positive cash flows (i.e. cp's cashflows) is to be
243+
// incorporated in the exposure, since cp does not pay out cash
244+
// flows
251245
mporCashFlow = nettingSetMporPositiveFlow[j][k];
252-
else if (mporCashFlowMode_ == ScenarioGeneratorData::MporCashFlowMode::TheyPay) // onyl negative cash flows (i.e. our cashflows) is to be incorporated in the exposure, ince we do not pay out cash flows
246+
} else if (mporCashFlowMode_ ==
247+
MporCashFlowMode::TheyPay) { // onyl negative cash flows (i.e. our cashflows) is to be
248+
// incorporated in the exposure, ince we do not pay out cash
249+
// flows
253250
mporCashFlow = nettingSetMporNegativeFlow[j][k];
251+
}
254252
}
255253
Real exposure = data[j][k] - balance + mporCashFlow;
256254
Real dim = 0.0;

OREAnalytics/orea/aggregation/nettedexposurecalculator.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,20 @@ class NettedExposureCalculator {
4646
public:
4747
NettedExposureCalculator(
4848
const boost::shared_ptr<Portfolio>& portfolio, const boost::shared_ptr<Market>& market,
49-
const boost::shared_ptr<NPVCube>& cube,
50-
const string& baseCurrency, const string& configuration, const Real quantile,
51-
const CollateralExposureHelper::CalculationType calcType, const bool multiPath,
49+
const boost::shared_ptr<NPVCube>& cube, const string& baseCurrency, const string& configuration,
50+
const Real quantile, const CollateralExposureHelper::CalculationType calcType, const bool multiPath,
5251
const boost::shared_ptr<NettingSetManager>& nettingSetManager,
5352
const map<string, vector<vector<Real>>>& nettingSetDefaultValue,
5453
const map<string, vector<vector<Real>>>& nettingSetCloseOutValue,
5554
const map<string, vector<vector<Real>>>& nettingSetMporPositiveFlow,
5655
const map<string, vector<vector<Real>>>& nettingSetMporNegativeFlow,
5756
const boost::shared_ptr<AggregationScenarioData>& scenarioData,
58-
const boost::shared_ptr<CubeInterpretation> cubeInterpretation,
59-
const bool applyInitialMargin,
60-
const boost::shared_ptr<DynamicInitialMarginCalculator>& dimCalculator,
61-
const bool fullInitialCollateralisation,
57+
const boost::shared_ptr<CubeInterpretation> cubeInterpretation, const bool applyInitialMargin,
58+
const boost::shared_ptr<DynamicInitialMarginCalculator>& dimCalculator, const bool fullInitialCollateralisation,
6259
// Marginal Allocation
63-
const bool marginalAllocation,
64-
const Real marginalAllocationLimit,
65-
const boost::shared_ptr<NPVCube>& tradeExposureCube,
66-
const Size allocatedEpeIndex,
67-
const Size allocatedEneIndex,
68-
const bool flipViewXVA,
69-
const bool withMporStickyDate,
70-
const ScenarioGeneratorData::MporCashFlowMode& mporCashFlowMode);
60+
const bool marginalAllocation, const Real marginalAllocationLimit,
61+
const boost::shared_ptr<NPVCube>& tradeExposureCube, const Size allocatedEpeIndex, const Size allocatedEneIndex,
62+
const bool flipViewXVA, const bool withMporStickyDate, const MporCashFlowMode mporCashFlowMode);
7163

7264
virtual ~NettedExposureCalculator() {}
7365
const boost::shared_ptr<NPVCube>& exposureCube() { return exposureCube_; }
@@ -150,7 +142,7 @@ class NettedExposureCalculator {
150142
const Date& nettingSetMaturity);
151143

152144
bool withMporStickyDate_;
153-
ScenarioGeneratorData::MporCashFlowMode mporCashFlowMode_;
145+
MporCashFlowMode mporCashFlowMode_;
154146
};
155147

156148
} // namespace analytics

OREAnalytics/orea/aggregation/postprocess.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ PostProcess::PostProcess(
6767
const string& flipViewLendingCurvePostfix,
6868
const boost::shared_ptr<CreditSimulationParameters>& creditSimulationParameters,
6969
const std::vector<Real>& creditMigrationDistributionGrid, const std::vector<Size>& creditMigrationTimeSteps,
70-
const Matrix& creditStateCorrelationMatrix,
71-
bool withMporStickyDate, ScenarioGeneratorData::MporCashFlowMode mporCashFlowMode)
70+
const Matrix& creditStateCorrelationMatrix, bool withMporStickyDate, MporCashFlowMode mporCashFlowMode)
7271
: portfolio_(portfolio), nettingSetManager_(nettingSetManager), market_(market), configuration_(configuration),
7372
cube_(cube), cptyCube_(cptyCube), scenarioData_(scenarioData), analytics_(analytics), baseCurrency_(baseCurrency),
7473
quantile_(quantile), calcType_(parseCollateralCalculationType(calculationType)), dvaName_(dvaName),
@@ -84,6 +83,18 @@ PostProcess::PostProcess(
8483
withMporStickyDate_(withMporStickyDate), mporCashFlowMode_(mporCashFlowMode) {
8584

8685
QL_REQUIRE(cubeInterpretation_ != nullptr, "PostProcess: cubeInterpretation is not given.");
86+
87+
if (mporCashFlowMode_ == MporCashFlowMode::Unspecified) {
88+
mporCashFlowMode_ = withMporStickyDate_ ? MporCashFlowMode::NonePay : MporCashFlowMode::BothPay;
89+
}
90+
91+
QL_REQUIRE(!withMporStickyDate_ || mporCashFlowMode_ == MporCashFlowMode::NonePay,
92+
"PostProcess: MporMode StickyDate supports only MporCashFlowMode NonePay");
93+
QL_REQUIRE(cubeInterpretation_->storeFlows() || withMporStickyDate || mporCashFlowMode_ == MporCashFlowMode::BothPay,
94+
"PostProcess: If cube does not hold any mpor flows and MporMode is set to ActualDate, then "
95+
"MporCashFlowMode must "
96+
"be set to BothPay");
97+
8798
bool isRegularCubeStorage = !cubeInterpretation_->withCloseOutLag();
8899

89100
LOG("cube storage is regular: " << isRegularCubeStorage);
@@ -180,20 +191,15 @@ PostProcess::PostProcess(
180191
* Michael Pykhtin & Dan Rosen, Pricing Counterparty Risk
181192
* at the Trade Level and CVA Allocations, October 2010
182193
*/
183-
nettedExposureCalculator_ =
184-
boost::make_shared<NettedExposureCalculator>(
185-
portfolio_, market_, cube_, baseCurrency, configuration_, quantile_,
186-
calcType_, analytics_["dynamicCredit"], nettingSetManager_,
187-
exposureCalculator_->nettingSetDefaultValue(),
188-
exposureCalculator_->nettingSetCloseOutValue(),
189-
exposureCalculator_->nettingSetMporPositiveFlow(),
190-
exposureCalculator_->nettingSetMporNegativeFlow(),
191-
scenarioData_, cubeInterpretation_, analytics_["dim"],
192-
dimCalculator_, fullInitialCollateralisation_,
193-
allocationMethod == ExposureAllocator::AllocationMethod::Marginal, marginalAllocationLimit,
194-
exposureCalculator_->exposureCube(), ExposureCalculator::allocatedEPE, ExposureCalculator::allocatedENE,
195-
analytics_["flipViewXVA"], withMporStickyDate_, mporCashFlowMode_
196-
);
194+
nettedExposureCalculator_ = boost::make_shared<NettedExposureCalculator>(
195+
portfolio_, market_, cube_, baseCurrency, configuration_, quantile_, calcType_, analytics_["dynamicCredit"],
196+
nettingSetManager_, exposureCalculator_->nettingSetDefaultValue(),
197+
exposureCalculator_->nettingSetCloseOutValue(), exposureCalculator_->nettingSetMporPositiveFlow(),
198+
exposureCalculator_->nettingSetMporNegativeFlow(), scenarioData_, cubeInterpretation_, analytics_["dim"],
199+
dimCalculator_, fullInitialCollateralisation_,
200+
allocationMethod == ExposureAllocator::AllocationMethod::Marginal, marginalAllocationLimit,
201+
exposureCalculator_->exposureCube(), ExposureCalculator::allocatedEPE, ExposureCalculator::allocatedENE,
202+
analytics_["flipViewXVA"], withMporStickyDate_, mporCashFlowMode_);
197203
nettedExposureCalculator_->build();
198204

199205
/********************************************************

OREAnalytics/orea/aggregation/postprocess.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class PostProcess {
167167
//! If set to true, cash flows in the margin period of risk are ignored in the collateral modelling
168168
bool withMporStickyDate = false,
169169
//! Treatment of cash flows over the margin period of risk
170-
ScenarioGeneratorData::MporCashFlowMode mporCashFlowMode = ScenarioGeneratorData::MporCashFlowMode::NonePay);
170+
const MporCashFlowMode mporCashFlowMode = MporCashFlowMode::Unspecified);
171171

172172
void setDimCalculator(boost::shared_ptr<DynamicInitialMarginCalculator> dimCalculator) {
173173
dimCalculator_ = dimCalculator;
@@ -377,7 +377,7 @@ class PostProcess {
377377
std::vector<std::vector<Real>> creditMigrationCdf_;
378378
std::vector<std::vector<Real>> creditMigrationPdf_;
379379
bool withMporStickyDate_;
380-
ScenarioGeneratorData::MporCashFlowMode mporCashFlowMode_;
380+
MporCashFlowMode mporCashFlowMode_;
381381
};
382382

383383
} // namespace analytics

OREAnalytics/orea/app/analytics/xvaanalytic.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,21 +564,15 @@ void XvaAnalyticImpl::runPostProcessor() {
564564

565565
LOG("baseCurrency " << baseCurrency);
566566

567-
bool withMporStickyDate = analytic()->configurations().scenarioGeneratorData->withMporStickyDate();
568-
ScenarioGeneratorData::MporCashFlowMode mporCashFlowMode = analytic()->configurations().scenarioGeneratorData->mporCashFlowMode();
569-
if (withMporStickyDate)
570-
QL_REQUIRE(mporCashFlowMode == ScenarioGeneratorData::MporCashFlowMode::NonePay, "MporMode StickyDate supports only MporCashFlowMode NonePay");
571-
if (!inputs_->storeFlows() && !withMporStickyDate)
572-
QL_REQUIRE(mporCashFlowMode == ScenarioGeneratorData::MporCashFlowMode::BothPay, "If cube does not hold any mpor flows and MporMode is set to ActualDate, then MporCashFlowMode must be set to BothPay");
573-
574567
postProcess_ = boost::make_shared<PostProcess>(
575568
analytic()->portfolio(), netting, analytic()->market(), marketConfiguration, cube_, *scenarioData_, analytics,
576569
baseCurrency, allocationMethod, marginalAllocationLimit, quantile, calculationType, dvaName, fvaBorrowingCurve,
577570
fvaLendingCurve, dimCalculator_, cubeInterpreter_, fullInitialCollateralisation, cvaSensiGrid,
578571
cvaSensiShiftSize, kvaCapitalDiscountRate, kvaAlpha, kvaRegAdjustment, kvaCapitalHurdle, kvaOurPdFloor,
579572
kvaTheirPdFloor, kvaOurCvaRiskWeight, kvaTheirCvaRiskWeight, cptyCube_, flipViewBorrowingCurvePostfix,
580573
flipViewLendingCurvePostfix, inputs_->creditSimulationParameters(), inputs_->creditMigrationDistributionGrid(),
581-
inputs_->creditMigrationTimeSteps(), creditStateCorrelationMatrix(), withMporStickyDate, mporCashFlowMode);
574+
inputs_->creditMigrationTimeSteps(), creditStateCorrelationMatrix(),
575+
analytic()->configurations().scenarioGeneratorData->withMporStickyDate(), inputs_->mporCashFlowMode());
582576
LOG("post done");
583577
}
584578

0 commit comments

Comments
 (0)