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

Credit Migration Calculator. More...

#include <orea/aggregation/creditmigrationcalculator.hpp>

+ Collaboration diagram for CreditMigrationCalculator:

Public Member Functions

 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)
 
void build ()
 
const std::vector< Real > upperBucketBounds () const
 
const std::vector< std::vector< Real > > cdf () const
 
const std::vector< std::vector< Real > > pdf () const
 

Private Attributes

QuantLib::ext::shared_ptr< Portfolioportfolio_
 
QuantLib::ext::shared_ptr< CreditSimulationParameterscreditSimulationParameters_
 
QuantLib::ext::shared_ptr< NPVCubecube_
 
QuantLib::ext::shared_ptr< CubeInterpretationcubeInterpretation_
 
QuantLib::ext::shared_ptr< NPVCubenettedCube_
 
QuantLib::ext::shared_ptr< AggregationScenarioDataaggregationScenarioData_
 
std::vector< Real > creditMigrationDistributionGrid_
 
std::vector< Size > creditMigrationTimeSteps_
 
Matrix creditStateCorrelationMatrix_
 
std::string baseCurrency_
 
std::vector< Real > upperBucketBounds_
 
std::vector< std::vector< Real > > cdf_
 
std::vector< std::vector< Real > > pdf_
 

Detailed Description

Credit Migration Calculator.

Definition at line 42 of file creditmigrationcalculator.hpp.

Constructor & Destructor Documentation

◆ CreditMigrationCalculator()

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 
)

Definition at line 25 of file creditmigrationcalculator.cpp.

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) {}
QuantLib::ext::shared_ptr< NPVCube > nettedCube_
QuantLib::ext::shared_ptr< AggregationScenarioData > aggregationScenarioData_
QuantLib::ext::shared_ptr< Portfolio > portfolio_
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation_
QuantLib::ext::shared_ptr< CreditSimulationParameters > creditSimulationParameters_
QuantLib::ext::shared_ptr< NPVCube > cube_

Member Function Documentation

◆ build()

void build ( )

Definition at line 40 of file creditmigrationcalculator.cpp.

40 {
41
42 LOG("Credit migration computation started.");
43
44 // checks
45
46 QL_REQUIRE(portfolio_ != nullptr, "CreditMigrationCalculator::build(): portfolio is null");
47 QL_REQUIRE(creditSimulationParameters_ != nullptr,
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");
52 QL_REQUIRE(aggregationScenarioData_ != nullptr,
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 ("
57 << creditStateCorrelationMatrix_.rows() << " x " << creditStateCorrelationMatrix_.columns() << ")");
58 QL_REQUIRE(
60 "CreditMigrationCalculator::build(): credit migration distribution grid spec must consist of 3 numbers (got "
61 << creditMigrationDistributionGrid_.size() << ")");
62
63 // create helper
64
66 cubeInterpretation_->mporFlowsIndex(), cubeInterpretation_->creditStateNPVsIndex(),
70
71 hlp.build(portfolio_->trades());
72
73 // compute output
74
75 upperBucketBounds_ = hlp.upperBucketBound();
76 if (!upperBucketBounds_.empty())
77 upperBucketBounds_.pop_back();
78 cdf_.clear();
79 pdf_.clear();
80
81 for (Size i = 0; i < creditMigrationTimeSteps_.size(); ++i) {
82 DLOG("Generating pnl distribution for timestep " << creditMigrationTimeSteps_[i]);
83 cdf_.push_back({});
84 pdf_.push_back({});
85 Array dist = hlp.pnlDistribution(creditMigrationTimeSteps_[i]);
86 Real mean = 0.0, stdev = 0.0;
87 Real sum = 0.0;
88 for (Size j = 1; j < hlp.upperBucketBound().size() - 1; ++j) {
89 Real pnl = 0.5 * (hlp.upperBucketBound()[j] + hlp.upperBucketBound()[j - 1]);
90 mean += pnl * dist[j];
91 stdev += pnl * pnl * dist[j];
92 sum += dist[j];
93 }
94 stdev = sqrt(stdev - mean * mean);
95 TLOG("Total PnL at time step " << creditMigrationTimeSteps_[i] << ": Mean " << std::fixed << mean << " StdDev "
96 << stdev << " Prob " << std::scientific << sum << " Left " << dist[0]
97 << " Right " << dist[hlp.upperBucketBound().size() - 1]);
98 Real p = 0.0;
99 for (Size j = 0; j < hlp.upperBucketBound().size() - 1; ++j) {
100 p += dist[j];
101 cdf_.back().push_back(p);
102 pdf_.back().push_back(dist[j]);
103 }
104 }
105
106 LOG("Credit migration computation finished.");
107}
#define LOG(text)
#define DLOG(text)
#define TLOG(text)
RandomVariable sqrt(RandomVariable x)
Real sum(const Cash &c, const Cash &d)
Size size(const ValueType &v)
+ Here is the call graph for this function:

◆ upperBucketBounds()

const std::vector< Real > upperBucketBounds ( ) const

Definition at line 56 of file creditmigrationcalculator.hpp.

56{ return upperBucketBounds_; }

◆ cdf()

const std::vector< std::vector< Real > > cdf ( ) const

Definition at line 57 of file creditmigrationcalculator.hpp.

57{ return cdf_; }

◆ pdf()

const std::vector< std::vector< Real > > pdf ( ) const

Definition at line 58 of file creditmigrationcalculator.hpp.

58{ return pdf_; }

Member Data Documentation

◆ portfolio_

QuantLib::ext::shared_ptr<Portfolio> portfolio_
private

Definition at line 61 of file creditmigrationcalculator.hpp.

◆ creditSimulationParameters_

QuantLib::ext::shared_ptr<CreditSimulationParameters> creditSimulationParameters_
private

Definition at line 62 of file creditmigrationcalculator.hpp.

◆ cube_

QuantLib::ext::shared_ptr<NPVCube> cube_
private

Definition at line 63 of file creditmigrationcalculator.hpp.

◆ cubeInterpretation_

QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation_
private

Definition at line 64 of file creditmigrationcalculator.hpp.

◆ nettedCube_

QuantLib::ext::shared_ptr<NPVCube> nettedCube_
private

Definition at line 65 of file creditmigrationcalculator.hpp.

◆ aggregationScenarioData_

QuantLib::ext::shared_ptr<AggregationScenarioData> aggregationScenarioData_
private

Definition at line 66 of file creditmigrationcalculator.hpp.

◆ creditMigrationDistributionGrid_

std::vector<Real> creditMigrationDistributionGrid_
private

Definition at line 67 of file creditmigrationcalculator.hpp.

◆ creditMigrationTimeSteps_

std::vector<Size> creditMigrationTimeSteps_
private

Definition at line 68 of file creditmigrationcalculator.hpp.

◆ creditStateCorrelationMatrix_

Matrix creditStateCorrelationMatrix_
private

Definition at line 69 of file creditmigrationcalculator.hpp.

◆ baseCurrency_

std::string baseCurrency_
private

Definition at line 70 of file creditmigrationcalculator.hpp.

◆ upperBucketBounds_

std::vector<Real> upperBucketBounds_
private

Definition at line 72 of file creditmigrationcalculator.hpp.

◆ cdf_

std::vector<std::vector<Real> > cdf_
private

Definition at line 73 of file creditmigrationcalculator.hpp.

◆ pdf_

std::vector<std::vector<Real> > pdf_
private

Definition at line 74 of file creditmigrationcalculator.hpp.