26 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
27 const QuantLib::ext::shared_ptr<CreditSimulationParameters>& creditSimulationParameters,
28 const QuantLib::ext::shared_ptr<NPVCube>& cube,
const QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation,
29 const QuantLib::ext::shared_ptr<NPVCube>& nettedCube,
30 const QuantLib::ext::shared_ptr<AggregationScenarioData>& aggregationScenarioData,
31 const std::vector<Real>& creditMigrationDistributionGrid,
const std::vector<Size>& creditMigrationTimeSteps,
32 const Matrix& creditStateCorrelationMatrix,
const std::string baseCurrency)
33 : portfolio_(portfolio), creditSimulationParameters_(creditSimulationParameters), cube_(cube),
34 cubeInterpretation_(cubeInterpretation), nettedCube_(nettedCube),
35 aggregationScenarioData_(aggregationScenarioData),
36 creditMigrationDistributionGrid_(creditMigrationDistributionGrid),
37 creditMigrationTimeSteps_(creditMigrationTimeSteps), creditStateCorrelationMatrix_(creditStateCorrelationMatrix),
38 baseCurrency_(baseCurrency) {}
42 LOG(
"Credit migration computation started.");
46 QL_REQUIRE(
portfolio_ !=
nullptr,
"CreditMigrationCalculator::build(): portfolio is null");
48 "CreditMigrationCalculator::build(): creditSimulationParameters is null");
49 QL_REQUIRE(
cube_ !=
nullptr,
"CreditMigrationCalculator::build(): cube is null");
50 QL_REQUIRE(
cubeInterpretation_ !=
nullptr,
"CreditMigrationCalculator::build(): cube interpretation is null");
51 QL_REQUIRE(
nettedCube_ !=
nullptr,
"CreditMigrationCalculator::build(): netted cube is null");
53 "CreditMigrationCalculator::build(): aggregation scenario data is null");
54 QL_REQUIRE(!
baseCurrency_.empty(),
"CreditMigrationCalculator::build(): base currency is empty");
56 "CreditMigrationCalculator::build(): credit state correlation matrix is not square ("
60 "CreditMigrationCalculator::build(): credit migration distribution grid spec must consist of 3 numbers (got "
86 Real mean = 0.0, stdev = 0.0;
90 mean += pnl * dist[j];
91 stdev += pnl * pnl * dist[j];
94 stdev =
sqrt(stdev - mean * mean);
96 << stdev <<
" Prob " << std::scientific <<
sum <<
" Left " << dist[0]
101 cdf_.back().push_back(p);
102 pdf_.back().push_back(dist[j]);
106 LOG(
"Credit migration computation finished.");
CreditMigrationCalculator(const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const QuantLib::ext::shared_ptr< CreditSimulationParameters > &creditSimulationParameters, const QuantLib::ext::shared_ptr< NPVCube > &cube, const QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation, const QuantLib::ext::shared_ptr< NPVCube > &nettedcube, const QuantLib::ext::shared_ptr< AggregationScenarioData > &aggregationScenarioData, const std::vector< Real > &creditMigrationDistributionGrid, const std::vector< Size > &creditMigrationTimeSteps, const Matrix &creditStateCorrelationMatrix, const std::string baseCurrency)
std::vector< std::vector< Real > > pdf_
std::vector< std::vector< Real > > cdf_
std::string baseCurrency_
QuantLib::ext::shared_ptr< NPVCube > nettedCube_
QuantLib::ext::shared_ptr< AggregationScenarioData > aggregationScenarioData_
QuantLib::ext::shared_ptr< Portfolio > portfolio_
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation_
std::vector< Size > creditMigrationTimeSteps_
QuantLib::ext::shared_ptr< CreditSimulationParameters > creditSimulationParameters_
Matrix creditStateCorrelationMatrix_
std::vector< Real > creditMigrationDistributionGrid_
std::vector< Real > upperBucketBounds_
QuantLib::ext::shared_ptr< NPVCube > cube_
void build(const std::map< std::string, QuantLib::ext::shared_ptr< Trade > > &trades)
builds the helper for a specific subset of trades stored in the cube
Array pnlDistribution(const Size date)
const std::vector< Real > & upperBucketBound() const
Credit migration helper class.
RandomVariable sqrt(RandomVariable x)
Real sum(const Cash &c, const Cash &d)
Size size(const ValueType &v)