Logo
Reference manual - version orea_version
PostProcess Class Reference

Exposure Aggregation and XVA Calculation. More...

#include <orea/aggregation/postprocess.hpp>

Public Member Functions

 PostProcess (const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< NettingSetManager > &nettingSetManager, const QuantLib::ext::shared_ptr< CollateralBalances > &collateralBalances, const QuantLib::ext::shared_ptr< Market > &market, const std::string &configuration, const QuantLib::ext::shared_ptr< NPVCube > &cube, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData, const map< string, bool > &analytics, const string &baseCurrency, const string &allocationMethod, Real cvaMarginalAllocationLimit, Real quantile=0.95, const string &calculationType="Symmetric", const string &dvaName="", const string &fvaBorrowingCurve="", const string &fvaLendingCurve="", const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > &dimCalculator=QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator >(), const QuantLib::ext::shared_ptr< CubeInterpretation > &cubeInterpretation=QuantLib::ext::shared_ptr< CubeInterpretation >(), bool fullInitialCollateralisation=false, vector< Period > cvaSpreadSensiGrid={6 *Months, 1 *Years, 3 *Years, 5 *Years, 10 *Years}, Real cvaSpreadSensiShiftSize=0.0001, Real kvaCapitalDiscountRate=0.10, Real kvaAlpha=1.4, Real kvaRegAdjustment=12.5, Real kvaCapitalHurdle=0.012, Real kvaOurPdFloor=0.03, Real kvaTheirPdFloor=0.03, Real kvaOurCvaRiskWeight=0.05, Real kvaTheirCvaRiskWeight=0.05, const QuantLib::ext::shared_ptr< NPVCube > &cptyCube_=nullptr, const string &flipViewBorrowingCurvePostfix="_BORROW", const string &flipViewLendingCurvePostfix="_LEND", const QuantLib::ext::shared_ptr< CreditSimulationParameters > &creditSimulationParameters=nullptr, const std::vector< Real > &creditMigrationDistributionGrid={}, const std::vector< Size > &creditMigrationTimeSteps={}, const Matrix &creditStateCorrelationMatrix=Matrix(), bool withMporStickyDate=false, const MporCashFlowMode mporCashFlowMode=MporCashFlowMode::Unspecified, const bool firstMporCollateralAdjustment=false, bool continueOnError=false, bool useDoublePrecisionCubes=false)
 Constructor.
void setDimCalculator (QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator)
const vector< Real > & spreadSensitivityTimes ()
const vector< Period > & spreadSensitivityGrid ()
const std::map< string, Size > tradeIds ()
 Return map of Trade IDs to cube trade indices.
const QuantLib::ext::shared_ptr< Portfolio > portfolio ()
const std::map< string, Size > nettingSetIds ()
 Return map netting set IDs to (net-)cube netting set indices.
const map< string, string > & counterpartyId ()
 Return the map of counterparty Ids.
const vector< Real > & tradeEPE (const string &tradeId)
 Return trade level Expected Positive Exposure evolution.
const vector< Real > & tradeENE (const string &tradeId)
 Return trade level Expected Negative Exposure evolution.
const vector< Real > & tradeEE_B (const string &tradeId)
 Return trade level Basel Expected Exposure evolution.
const Real & tradeEPE_B (const string &tradeId)
 Return trade level Basel Expected Positive Exposure evolution.
const vector< Real > & tradeEEE_B (const string &tradeId)
 Return trade level Effective Expected Exposure evolution.
const Real & tradeEEPE_B (const string &tradeId)
 Return trade level Effective Expected Positive Exposure evolution.
const vector< Real > & tradePFE (const string &tradeId)
 Return trade level Potential Future Exposure evolution.
const vector< Real > & tradeEPE_B_timeWeighted (const string &tradeId)
 Return trade level Expected Positive Exposure evolution.
const vector< Real > & tradeEEPE_B_timeWeighted (const string &tradeId)
 Return trade level Effective Expected Positive Exposure evolution.
const vector< Real > & netEPE (const string &nettingSetId)
 Return Netting Set Expected Positive Exposure evolution.
const vector< Real > & netENE (const string &nettingSetId)
 Return Netting Set Expected Negative Exposure evolution.
const vector< Real > & netEE_B (const string &nettingSetId)
 Return Netting Set Basel Expected Exposure evolution.
const Real & netEPE_B (const string &nettingSetId)
 Return Netting Set Basel Expected Positive Exposure evolution.
const vector< Real > & netEEE_B (const string &nettingSetId)
 Return Netting Set Effective Expected Exposure evolution.
const Real & netEEPE_B (const string &nettingSetId)
 Return Netting Set Effective Expected Positive Exposure evolution.
const vector< Real > & netPFE (const string &nettingSetId)
 Return Netting Set Potential Future Exposure evolution.
const vector< Real > & netEPE_B_timeWeighted (const string &nettingSetId)
const vector< Real > & netEEPE_B_timeWeighted (const string &nettingSetId)
const vector< Real > & expectedCollateral (const string &nettingSetId)
 Return the netting set's expected collateral evolution.
const vector< Real > & colvaIncrements (const string &nettingSetId)
 Return the netting set's expected COLVA increments through time.
const vector< Real > & collateralFloorIncrements (const string &nettingSetId)
 Return the netting set's expected Collateral Floor increments through time.
const vector< Real > & allocatedTradeEPE (const string &tradeId)
 Return the trade EPE, allocated down from the netting set level.
const vector< Real > & allocatedTradeENE (const string &tradeId)
 Return trade ENE, allocated down from the netting set level.
const std::map< std::string, std::vector< NettedExposureCalculator::TimeAveragedExposure > > & timeAveragedNettedExposure () const
 Return the time-averaged pathwise positive and negative exposures before and after collateral.
vector< Real > netCvaHazardRateSensitivity (const string &nettingSetId)
 Return Netting Set CVA Hazard Rate Sensitivity vector.
vector< Real > netCvaSpreadSensitivity (const string &nettingSetId)
 Return Netting Set CVA Spread Sensitivity vector.
const std::map< std::string, std::vector< QuantLib::Real > > & netCvaSpreadSensitivity () const
 Return Netting Set CVA Spread Sensitivity vector.
Real tradeCVA (const string &tradeId)
 Return trade (stand-alone) CVA.
Real tradeDVA (const string &tradeId)
 Return trade (stand-alone) DVA.
Real tradeMVA (const string &tradeId)
 Return trade (stand-alone) MVA.
Real tradeFBA (const string &tradeId)
 Return trade (stand-alone) FBA (Funding Benefit Adjustment).
Real tradeFCA (const string &tradeId)
 Return trade (stand-alone) FCA (Funding Cost Adjustment).
Real tradeFBA_exOwnSP (const string &tradeId)
 Return trade (stand-alone) FBA (Funding Benefit Adjustment) excluding own survival probability.
Real tradeFCA_exOwnSP (const string &tradeId)
 Return trade (stand-alone) FCA (Funding Cost Adjustment) excluding own survival probability.
Real tradeFBA_exAllSP (const string &tradeId)
 Return trade (stand-alone) FBA (Funding Benefit Adjustment) excluding both survival probabilities.
Real tradeFCA_exAllSP (const string &tradeId)
 Return trade (stand-alone) FCA (Funding Cost Adjustment) excluding both survival probabilities.
Real allocatedTradeCVA (const string &tradeId)
 Return allocated trade CVA (trade CVAs add up to netting set CVA).
Real allocatedTradeDVA (const string &tradeId)
 Return allocated trade DVA (trade DVAs add up to netting set DVA).
Real nettingSetCVA (const string &nettingSetId)
 Return netting set CVA.
Real nettingSetDVA (const string &nettingSetId)
 Return netting set DVA.
Real nettingSetMVA (const string &nettingSetId)
 Return netting set MVA.
Real nettingSetFBA (const string &nettingSetId)
 Return netting set FBA.
Real nettingSetFCA (const string &nettingSetId)
 Return netting set FCA.
Real nettingSetOurKVACCR (const string &nettingSetId)
 Return netting set KVA-CCR.
Real nettingSetTheirKVACCR (const string &nettingSetId)
 Return netting set KVA-CCR from counterparty perspective.
Real nettingSetOurKVACVA (const string &nettingSetId)
 Return netting set KVA-CVA.
Real nettingSetTheirKVACVA (const string &nettingSetId)
 Return netting set KVA-CVA from counterparty perspective.
Real nettingSetFBA_exOwnSP (const string &nettingSetId)
 Return netting set FBA excluding own survival probability.
Real nettingSetFCA_exOwnSP (const string &nettingSetId)
 Return netting set FCA excluding own survival probability.
Real nettingSetFBA_exAllSP (const string &nettingSetId)
 Return netting set FBA excluding both survival probabilities.
Real nettingSetFCA_exAllSP (const string &nettingSetId)
 Return netting set FCA excluding both survival probabilities.
Real nettingSetCOLVA (const string &nettingSetId)
 Return netting set COLVA.
Real nettingSetCollateralFloor (const string &nettingSetId)
 Return netting set Collateral Floor value.
const QuantLib::ext::shared_ptr< NPVCube > & cube ()
 Inspector for the input NPV cube (by trade, time, scenario).
const QuantLib::ext::shared_ptr< NPVCube > & cptyCube ()
 Inspector for the input Cpty cube (by name, time, scenario).
const QuantLib::ext::shared_ptr< NPVCube > & netCube ()
 Return the for the input NPV cube after netting and collateral (by netting set, time, scenario).
void exportDimDistribution (ore::data::Report &dimDistributionReport, const Size gridSize=50, const Real coveredStdDevs=Null< Real >())
 Return the dynamic initial margin cube (regression approach).
void exportDimCube (ore::data::Report &dimCubeReport)
 Write DIM cube for all netting sets.
void exportDimEvolution (ore::data::Report &dimEvolutionReport)
 Write average (over samples) DIM evolution through time for all netting sets.
void exportDimRegression (const std::string &nettingSet, const std::vector< Size > &timeSteps, const std::vector< QuantLib::ext::shared_ptr< ore::data::Report > > &dimRegReports)
 Write DIM as a function of sample netting set NPV for a given time step.
QuantLib::Real cvaSpreadSensiShiftSize ()
 get the cvaSpreadSensiShiftSize
const std::vector< Real > & creditMigrationUpperBucketBounds () const
 get the credit migration pnl distributions for each time step
const std::vector< std::vector< Real > > & creditMigrationCdf () const
const std::vector< std::vector< Real > > & creditMigrationPdf () const

Protected Member Functions

QuantLib::ext::shared_ptr< vector< QuantLib::ext::shared_ptr< CollateralAccount > > > collateralPaths (const string &nettingSetId, const QuantLib::ext::shared_ptr< NettingSetManager > &nettingSetManager, const QuantLib::ext::shared_ptr< Market > &market, const std::string &configuration, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData, Size dates, Size samples, const vector< vector< Real > > &nettingSetValue, Real nettingSetValueToday, const Date &nettingSetMaturity)
 Helper function to return the collateral account evolution for a given netting set.
void updateNettingSetKVA ()
void updateNettingSetCvaSensitivity ()

Protected Attributes

QuantLib::ext::shared_ptr< Portfolio > portfolio_
QuantLib::ext::shared_ptr< NettingSetManager > nettingSetManager_
QuantLib::ext::shared_ptr< CollateralBalances > collateralBalances_
QuantLib::ext::shared_ptr< Marketmarket_
const std::string configuration_
QuantLib::ext::shared_ptr< NPVCubecube_
QuantLib::ext::shared_ptr< NPVCubecptyCube_
QuantLib::ext::shared_ptr< AggregationScenarioDatascenarioData_
map< string, bool > analytics_
map< string, vector< Real > > tradeEPE_
map< string, vector< Real > > tradeENE_
map< string, vector< Real > > allocatedTradeEPE_
map< string, vector< Real > > allocatedTradeENE_
map< string, vector< Real > > netEPE_
map< string, vector< Real > > netENE_
map< string, Real > ourNettingSetKVACCR_
map< string, Real > theirNettingSetKVACCR_
map< string, Real > ourNettingSetKVACVA_
map< string, Real > theirNettingSetKVACVA_
map< string, vector< Real > > netCvaSpreadSensi_
map< string, vector< Real > > netCvaHazardRateSensi_
string baseCurrency_
Real quantile_
CollateralExposureHelper::CalculationType calcType_
string dvaName_
string fvaBorrowingCurve_
string fvaLendingCurve_
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculatordimCalculator_
QuantLib::ext::shared_ptr< ExposureCalculatorexposureCalculator_
QuantLib::ext::shared_ptr< NettedExposureCalculatornettedExposureCalculator_
QuantLib::ext::shared_ptr< ValueAdjustmentCalculatorcvaCalculator_
QuantLib::ext::shared_ptr< ValueAdjustmentCalculatorallocatedCvaCalculator_
QuantLib::ext::shared_ptr< CubeInterpretationcubeInterpretation_
bool fullInitialCollateralisation_
vector< Period > cvaSpreadSensiGrid_
vector< Time > cvaSpreadSensiTimes_
Real cvaSpreadSensiShiftSize_
Real kvaCapitalDiscountRate_
Real kvaAlpha_
Real kvaRegAdjustment_
Real kvaCapitalHurdle_
Real kvaOurPdFloor_
Real kvaTheirPdFloor_
Real kvaOurCvaRiskWeight_
Real kvaTheirCvaRiskWeight_
QuantLib::ext::shared_ptr< CreditSimulationParameterscreditSimulationParameters_
std::vector< Real > creditMigrationDistributionGrid_
std::vector< Size > creditMigrationTimeSteps_
Matrix creditStateCorrelationMatrix_
QuantLib::ext::shared_ptr< CreditMigrationCalculatorcreditMigrationCalculator_
std::vector< Real > creditMigrationUpperBucketBounds_
std::vector< std::vector< Real > > creditMigrationCdf_
std::vector< std::vector< Real > > creditMigrationPdf_
bool withMporStickyDate_
MporCashFlowMode mporCashFlowMode_
bool firstMporCollateralAdjustment_
bool continueOnError_
bool useDoublePrecisionCubes_

Detailed Description

Exposure Aggregation and XVA Calculation.

This class aggregates NPV cube data, computes exposure statistics and various XVAs, all at trade and netting set level:

1) Exposures

  • Expected Positive Exposure, EPE: E[max(NPV(t),0) / N(t)]
  • Expected Negative Exposure, ENE: E[max(-NPV(t),0) / N(t)]
  • Basel Expected Exposure, EE_B: EPE(t)/P(t)
  • Basel Expected Positive Exposure, EPE_B
  • Basel Effective Expected Exposure, EEE_B: max( EEE_B(t-1), EE_B(t))
  • Basel Effective Expected Positive Exposure, EEPE_B
  • Potential Future Exposure, PFE: q-Quantile of the distribution of
  • Time-Weighted Exposure (only on netting set level): 1 / T SUM_i=0^T EPE(t) \DELTA(t)

2) Dynamic Initial Margin via regression

3) XVAs:

  • Credit Value Adjustment, CVA
  • Debit Value Adjustment, DVA
  • Funding Value Adjustment, FVA
  • Collateral Value Adjustment, COLVA
  • Margin Value Adjustment, MVA

4) Allocation from netting set to trade level such that allocated contributions add up to the netting set

  • CVA and DVA
  • EPE and ENE

All analytics are precomputed when the class constructor is called. A number of inspectors described below then return the individual analytics results.

Note:

  • exposures are discounted at the numeraire N(t) used in the Monte Carlo simulation which produces the NPV cube.
  • NPVs take collateral into account, depending on CSA settings

Constructor & Destructor Documentation

◆ PostProcess()

PostProcess ( const QuantLib::ext::shared_ptr< Portfolio > & portfolio,
const QuantLib::ext::shared_ptr< NettingSetManager > & nettingSetManager,
const QuantLib::ext::shared_ptr< CollateralBalances > & collateralBalances,
const QuantLib::ext::shared_ptr< Market > & market,
const std::string & configuration,
const QuantLib::ext::shared_ptr< NPVCube > & cube,
const QuantLib::ext::shared_ptr< AggregationScenarioData > & scenarioData,
const map< string, bool > & analytics,
const string & baseCurrency,
const string & allocationMethod,
Real cvaMarginalAllocationLimit,
Real quantile = 0.95,
const string & calculationType = "Symmetric",
const string & dvaName = "",
const string & fvaBorrowingCurve = "",
const string & fvaLendingCurve = "",
const QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > & dimCalculator = QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator >(),
const QuantLib::ext::shared_ptr< CubeInterpretation > & cubeInterpretation = QuantLib::ext::shared_ptr< CubeInterpretation >(),
bool fullInitialCollateralisation = false,
vector< Period > cvaSpreadSensiGrid = {6 *Months, 1 *Years, 3 *Years, 5 *Years, 10 *Years},
Real cvaSpreadSensiShiftSize = 0.0001,
Real kvaCapitalDiscountRate = 0.10,
Real kvaAlpha = 1.4,
Real kvaRegAdjustment = 12.5,
Real kvaCapitalHurdle = 0.012,
Real kvaOurPdFloor = 0.03,
Real kvaTheirPdFloor = 0.03,
Real kvaOurCvaRiskWeight = 0.05,
Real kvaTheirCvaRiskWeight = 0.05,
const QuantLib::ext::shared_ptr< NPVCube > & cptyCube_ = nullptr,
const string & flipViewBorrowingCurvePostfix = "_BORROW",
const string & flipViewLendingCurvePostfix = "_LEND",
const QuantLib::ext::shared_ptr< CreditSimulationParameters > & creditSimulationParameters = nullptr,
const std::vector< Real > & creditMigrationDistributionGrid = {},
const std::vector< Size > & creditMigrationTimeSteps = {},
const Matrix & creditStateCorrelationMatrix = Matrix(),
bool withMporStickyDate = false,
const MporCashFlowMode mporCashFlowMode = MporCashFlowMode::Unspecified,
const bool firstMporCollateralAdjustment = false,
bool continueOnError = false,
bool useDoublePrecisionCubes = false )

Constructor.

Parameters
portfolioTrade portfolio to identify e.g. netting set, maturity, break dates for each trade
nettingSetManagerNetting set manager to access CSA details for each netting set
collateralBalancesCollateral balances (VM, IM, IA)
marketMarket data object to access e.g. discounting and funding curves
configurationMarket configuration to use
cubeInput NPV Cube
scenarioDataSubset of simulated market data, index fixings and FX spot rates, associated with the NPV cube
analyticsSelection of analytics to be produced
baseCurrencyExpression currency for all results
allocationMethodMethod to be used for Exposure/XVA allocation down to trade level
cvaMarginalAllocationLimitCutoff parameter for the marginal allocation method below which we switch to equal distribution
quantileQuantile for Potential Future Exposure output
calculationTypeCollateral calculation type to be used, see class CollateralExposureHelper
dvaNameCredit curve name to be used for "our" credit risk in DVA calculations
fvaBorrowingCurveBorrowing curve name to be used in FVA calculations
fvaLendingCurveLending curve name to be used in FVA calculations
dimCalculatorDynamic Initial Margin Calculator
cubeInterpretationInterpreter for cube storage (where to find which data items)
fullInitialCollateralisationAssume t=0 collateral balance equals NPV (set to 0 if false)
cvaSpreadSensiGridCVA spread sensitivity grid
cvaSpreadSensiShiftSizeCVA spread sensitivity shift size
kvaCapitalDiscountRateown capital discounting rate for discounting expected capital for KVA
kvaAlphaalpha to adjust EEPE to give EAD for risk capital
kvaRegAdjustmentregulatory adjustment, 1/min cap requirement
kvaCapitalHurdleCost of Capital for KVA = regulatory adjustment x capital hurdle
kvaOurPdFloorOur KVA PD floor
kvaTheirPdFloorTheir KVA PD floor
kvaOurCvaRiskWeightOur KVA CVA Risk Weight
kvaTheirCvaRiskWeightTheir KVA CVA Risk Weight,
cptyCube_Input Counterparty Cube
flipViewBorrowingCurvePostfixPostfix for flipView borrowing curve for fva
flipViewLendingCurvePostfixPostfix for flipView lending curve for fva
creditSimulationParametersCredit simulation parameters
creditMigrationDistributionGridCredit simulation distribution grid
creditMigrationTimeStepsCredit simulation time steps
creditStateCorrelationMatrixCredit State correlation matrix
withMporStickyDateIf set to true, cash flows in the margin period of risk are ignored in the collateral modelling
mporCashFlowModeTreatment of cash flows over the margin period of risk
firstMporCollateralAdjustmentTreatment of the initial difference between vm collateral balance and mtm if true, it keeps an under-collateralisation for in case of a negative mtm constant and vice-versa for over-collateralisation in case of positive mtm
continueOnErrorContinue with the calculation if possible when there is an error
useDoublePrecisionCubesuse double precision cubes

Member Function Documentation

◆ exportDimDistribution()

void exportDimDistribution ( ore::data::Report & dimDistributionReport,
const Size gridSize = 50,
const Real coveredStdDevs = Null< Real >() )

Return the dynamic initial margin cube (regression approach).

Write DIM distributions through time for all netting sets