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

Allow for interpretation of how data is stored within cube and AggregationScenarioData. More...

#include <orea/cube/cubeinterpretation.hpp>

+ Collaboration diagram for CubeInterpretation:

Public Member Functions

 CubeInterpretation (const bool storeFlows, const bool withCloseOutLag, const QuantLib::Handle< AggregationScenarioData > &aggregationScenarioData=QuantLib::Handle< AggregationScenarioData >(), const QuantLib::ext::shared_ptr< DateGrid > &dateGrid=nullptr, const Size storeCreditStateNPVs=0, const bool flipViewXVA=false)
 
bool storeFlows () const
 inspectors More...
 
bool withCloseOutLag () const
 
const QuantLib::Handle< AggregationScenarioData > & aggregationScenarioData () const
 
const QuantLib::ext::shared_ptr< DateGrid > & dateGrid () const
 
Size storeCreditStateNPVs () const
 
bool flipViewXVA () const
 
Size requiredNpvCubeDepth () const
 npv cube depth that is at least required to work with this interpretation More...
 
Size defaultDateNpvIndex () const
 indices in depth direction, might be Null<Size>() if not applicable More...
 
Size closeOutDateNpvIndex () const
 
Size mporFlowsIndex () const
 
Size creditStateNPVsIndex () const
 
Real getGenericValue (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx, Size depth) const
 Retrieve an arbitrary value from the Cube (user needs to know the precise location within depth axis) More...
 
Real getDefaultNpv (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
 Retrieve the default date NPV from the Cube. More...
 
Real getCloseOutNpv (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
 Retrieve the close-out date NPV from the Cube. More...
 
Real getMporPositiveFlows (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
 Retrieve the aggregate value of Margin Period of Risk positive cashflows from the Cube. More...
 
Real getMporNegativeFlows (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
 Retrieve the aggregate value of Margin Period of Risk negative cashflows from the Cube. More...
 
Real getMporFlows (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
 Retrieve the aggregate value of Margin Period of Risk cashflows from the Cube. More...
 
Real getDefaultAggregationScenarioData (const AggregationScenarioDataType &dataType, Size dateIdx, Size sampleIdx, const std::string &qualifier="") const
 Retrieve a (default date) simulated risk factor value from AggregationScenarioData. More...
 
Real getCloseOutAggregationScenarioData (const AggregationScenarioDataType &dataType, Size dateIdx, Size sampleIdx, const std::string &qualifier="") const
 Retrieve a (default date) simulated risk factor value from AggregationScenarioData. More...
 
Size getMporCalendarDays (const QuantLib::ext::shared_ptr< NPVCube > &cube, Size dateIdx) const
 Number of Calendar Days between a given default date and corresponding close-out date. More...
 

Private Attributes

bool storeFlows_
 
bool withCloseOutLag_
 
QuantLib::Handle< AggregationScenarioDataaggregationScenarioData_
 
QuantLib::ext::shared_ptr< DateGriddateGrid_
 
Size storeCreditStateNPVs_
 
bool flipViewXVA_
 
Size requiredCubeDepth_
 
Size defaultDateNpvIndex_ = QuantLib::Null<Size>()
 
Size closeOutDateNpvIndex_ = QuantLib::Null<Size>()
 
Size mporFlowsIndex_ = QuantLib::Null<Size>()
 
Size creditStateNPVsIndex_ = QuantLib::Null<Size>()
 

Detailed Description

Allow for interpretation of how data is stored within cube and AggregationScenarioData.

Definition at line 44 of file cubeinterpretation.hpp.

Constructor & Destructor Documentation

◆ CubeInterpretation()

CubeInterpretation ( const bool  storeFlows,
const bool  withCloseOutLag,
const QuantLib::Handle< AggregationScenarioData > &  aggregationScenarioData = QuantLib::Handle<AggregationScenarioData>(),
const QuantLib::ext::shared_ptr< DateGrid > &  dateGrid = nullptr,
const Size  storeCreditStateNPVs = 0,
const bool  flipViewXVA = false 
)

Definition at line 26 of file cubeinterpretation.cpp.

32
33 // determine required cube depth and layout
34
37
38 if (withCloseOutLag_) {
40 QL_REQUIRE(dateGrid_ != nullptr, "CubeInterpretation: dateGrid is required when withCloseOutLag is true");
41 }
42
43 if (storeFlows_) {
46 }
47
48 if (storeCreditStateNPVs_ > 0) {
51 }
52}
const QuantLib::ext::shared_ptr< DateGrid > & dateGrid() const
const QuantLib::Handle< AggregationScenarioData > & aggregationScenarioData() const
QuantLib::ext::shared_ptr< DateGrid > dateGrid_
QuantLib::Handle< AggregationScenarioData > aggregationScenarioData_

Member Function Documentation

◆ storeFlows()

bool storeFlows ( ) const

inspectors

Definition at line 54 of file cubeinterpretation.cpp.

54{ return storeFlows_; }

◆ withCloseOutLag()

bool withCloseOutLag ( ) const

Definition at line 56 of file cubeinterpretation.cpp.

56{ return withCloseOutLag_; }

◆ aggregationScenarioData()

const QuantLib::Handle< AggregationScenarioData > & aggregationScenarioData ( ) const

Definition at line 60 of file cubeinterpretation.cpp.

60 {
62}

◆ dateGrid()

const QuantLib::ext::shared_ptr< DateGrid > & dateGrid ( ) const

Definition at line 64 of file cubeinterpretation.cpp.

64{ return dateGrid_; }

◆ storeCreditStateNPVs()

Size storeCreditStateNPVs ( ) const

Definition at line 58 of file cubeinterpretation.cpp.

58{ return storeCreditStateNPVs_; }

◆ flipViewXVA()

bool flipViewXVA ( ) const

Definition at line 66 of file cubeinterpretation.cpp.

66{ return flipViewXVA_; }

◆ requiredNpvCubeDepth()

Size requiredNpvCubeDepth ( ) const

npv cube depth that is at least required to work with this interpretation

Definition at line 68 of file cubeinterpretation.cpp.

68{ return requiredCubeDepth_; }

◆ defaultDateNpvIndex()

Size defaultDateNpvIndex ( ) const

indices in depth direction, might be Null<Size>() if not applicable

Definition at line 70 of file cubeinterpretation.cpp.

70{ return defaultDateNpvIndex_; }

◆ closeOutDateNpvIndex()

Size closeOutDateNpvIndex ( ) const

Definition at line 71 of file cubeinterpretation.cpp.

71{ return closeOutDateNpvIndex_; }

◆ mporFlowsIndex()

Size mporFlowsIndex ( ) const

Definition at line 72 of file cubeinterpretation.cpp.

72{ return mporFlowsIndex_; }

◆ creditStateNPVsIndex()

Size creditStateNPVsIndex ( ) const

Definition at line 73 of file cubeinterpretation.cpp.

73{ return creditStateNPVsIndex_; }

◆ getGenericValue()

Real getGenericValue ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  tradeIdx,
Size  dateIdx,
Size  sampleIdx,
Size  depth 
) const

Retrieve an arbitrary value from the Cube (user needs to know the precise location within depth axis)

Definition at line 75 of file cubeinterpretation.cpp.

76 {
77 if (flipViewXVA_) {
78 return -cube->get(tradeIdx, dateIdx, sampleIdx, depth);
79 } else {
80 return cube->get(tradeIdx, dateIdx, sampleIdx, depth);
81 }
82}
+ Here is the caller graph for this function:

◆ getDefaultNpv()

Real getDefaultNpv ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  tradeIdx,
Size  dateIdx,
Size  sampleIdx 
) const

Retrieve the default date NPV from the Cube.

Definition at line 84 of file cubeinterpretation.cpp.

85 {
86 return getGenericValue(cube, tradeIdx, dateIdx, sampleIdx, defaultDateNpvIndex_);
87}
Real getGenericValue(const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx, Size depth) const
Retrieve an arbitrary value from the Cube (user needs to know the precise location within depth axis)
+ Here is the call graph for this function:

◆ getCloseOutNpv()

Real getCloseOutNpv ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  tradeIdx,
Size  dateIdx,
Size  sampleIdx 
) const

Retrieve the close-out date NPV from the Cube.

Definition at line 89 of file cubeinterpretation.cpp.

90 {
92 return getGenericValue(cube, tradeIdx, dateIdx, sampleIdx, closeOutDateNpvIndex_) /
94 else
95 return getGenericValue(cube, tradeIdx, dateIdx + 1, sampleIdx, defaultDateNpvIndex_);
96}
Real getCloseOutAggregationScenarioData(const AggregationScenarioDataType &dataType, Size dateIdx, Size sampleIdx, const std::string &qualifier="") const
Retrieve a (default date) simulated risk factor value from AggregationScenarioData.
+ Here is the call graph for this function:

◆ getMporPositiveFlows()

Real getMporPositiveFlows ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  tradeIdx,
Size  dateIdx,
Size  sampleIdx 
) const

Retrieve the aggregate value of Margin Period of Risk positive cashflows from the Cube.

Definition at line 98 of file cubeinterpretation.cpp.

99 {
100 if (mporFlowsIndex_ == QuantLib::Null<Size>())
101 return 0.0;
102 Real aggMporFlowsVal = 0.0;
103 try {
104 aggMporFlowsVal = getGenericValue(cube, tradeIdx, dateIdx, sampleIdx, mporFlowsIndex_);
105 } catch (std::exception& e) {
106 DLOG("Unable to retrieve MPOR flows for trade " << tradeIdx << ", date " << dateIdx << ", sample " << sampleIdx
107 << "; " << e.what());
108 }
109 return aggMporFlowsVal;
110}
#define DLOG(text)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMporNegativeFlows()

Real getMporNegativeFlows ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  tradeIdx,
Size  dateIdx,
Size  sampleIdx 
) const

Retrieve the aggregate value of Margin Period of Risk negative cashflows from the Cube.

Definition at line 112 of file cubeinterpretation.cpp.

113 {
114 if (mporFlowsIndex_ == QuantLib::Null<Size>())
115 return 0.0;
116 Real aggMporFlowsVal = 0.0;
117 try {
118 aggMporFlowsVal = getGenericValue(cube, tradeIdx, dateIdx, sampleIdx, mporFlowsIndex_ + 1);
119 } catch (std::exception& e) {
120 DLOG("Unable to retrieve MPOR flows for trade " << tradeIdx << ", date " << dateIdx << ", sample " << sampleIdx
121 << "; " << e.what());
122 }
123 return aggMporFlowsVal;
124}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMporFlows()

Real getMporFlows ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  tradeIdx,
Size  dateIdx,
Size  sampleIdx 
) const

Retrieve the aggregate value of Margin Period of Risk cashflows from the Cube.

Definition at line 126 of file cubeinterpretation.cpp.

127 {
128 return getMporPositiveFlows(cube, tradeIdx, dateIdx, sampleIdx) + getMporNegativeFlows(cube, tradeIdx, dateIdx, sampleIdx) ;
129}
Real getMporPositiveFlows(const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
Retrieve the aggregate value of Margin Period of Risk positive cashflows from the Cube.
Real getMporNegativeFlows(const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
Retrieve the aggregate value of Margin Period of Risk negative cashflows from the Cube.
+ Here is the call graph for this function:

◆ getDefaultAggregationScenarioData()

Real getDefaultAggregationScenarioData ( const AggregationScenarioDataType dataType,
Size  dateIdx,
Size  sampleIdx,
const std::string &  qualifier = "" 
) const

Retrieve a (default date) simulated risk factor value from AggregationScenarioData.

Definition at line 131 of file cubeinterpretation.cpp.

132 {
133 QL_REQUIRE(!aggregationScenarioData_.empty(),
134 "CubeInterpretation::getDefaultAggregationScenarioData(): no aggregation scenario data given");
135 return aggregationScenarioData_->get(dateIdx, sampleIdx, dataType, qualifier);
136}
+ Here is the caller graph for this function:

◆ getCloseOutAggregationScenarioData()

Real getCloseOutAggregationScenarioData ( const AggregationScenarioDataType dataType,
Size  dateIdx,
Size  sampleIdx,
const std::string &  qualifier = "" 
) const

Retrieve a (default date) simulated risk factor value from AggregationScenarioData.

Definition at line 138 of file cubeinterpretation.cpp.

139 {
140 if (withCloseOutLag_) {
141 QL_REQUIRE(dataType == AggregationScenarioDataType::Numeraire,
142 "close out aggr scen data only available for numeraire");
143 // this is an approximation
144 return getDefaultAggregationScenarioData(dataType, dateIdx, sampleIdx, qualifier);
145 } else {
146 QL_REQUIRE(!aggregationScenarioData_.empty(), "CubeInterpretation::getCloseOutAggregationScenarioData(): no "
147 "aggregation scenario data given");
148 return aggregationScenarioData_->get(dateIdx + 1, sampleIdx, dataType, qualifier);
149 }
150}
Real getDefaultAggregationScenarioData(const AggregationScenarioDataType &dataType, Size dateIdx, Size sampleIdx, const std::string &qualifier="") const
Retrieve a (default date) simulated risk factor value from AggregationScenarioData.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMporCalendarDays()

Size getMporCalendarDays ( const QuantLib::ext::shared_ptr< NPVCube > &  cube,
Size  dateIdx 
) const

Number of Calendar Days between a given default date and corresponding close-out date.

Definition at line 152 of file cubeinterpretation.cpp.

152 {
153 if (withCloseOutLag_) {
154 QuantLib::Date dd = dateGrid_->valuationDates()[dateIdx];
155 QuantLib::Date cd = dateGrid_->closeOutDates()[dateIdx];
156 QL_REQUIRE(cd > dd, "close-out date (" << cd << ") must be greater than default date (" << dd << ") at index "
157 << dateIdx);
158 return (cd - dd);
159 } else {
160 return cube->dates()[dateIdx + 1] - cube->dates()[dateIdx];
161 }
162}

Member Data Documentation

◆ storeFlows_

bool storeFlows_
private

Definition at line 101 of file cubeinterpretation.hpp.

◆ withCloseOutLag_

bool withCloseOutLag_
private

Definition at line 102 of file cubeinterpretation.hpp.

◆ aggregationScenarioData_

QuantLib::Handle<AggregationScenarioData> aggregationScenarioData_
private

Definition at line 103 of file cubeinterpretation.hpp.

◆ dateGrid_

QuantLib::ext::shared_ptr<DateGrid> dateGrid_
private

Definition at line 104 of file cubeinterpretation.hpp.

◆ storeCreditStateNPVs_

Size storeCreditStateNPVs_
private

Definition at line 105 of file cubeinterpretation.hpp.

◆ flipViewXVA_

bool flipViewXVA_
private

Definition at line 106 of file cubeinterpretation.hpp.

◆ requiredCubeDepth_

Size requiredCubeDepth_
private

Definition at line 108 of file cubeinterpretation.hpp.

◆ defaultDateNpvIndex_

Size defaultDateNpvIndex_ = QuantLib::Null<Size>()
private

Definition at line 109 of file cubeinterpretation.hpp.

◆ closeOutDateNpvIndex_

Size closeOutDateNpvIndex_ = QuantLib::Null<Size>()
private

Definition at line 110 of file cubeinterpretation.hpp.

◆ mporFlowsIndex_

Size mporFlowsIndex_ = QuantLib::Null<Size>()
private

Definition at line 111 of file cubeinterpretation.hpp.

◆ creditStateNPVsIndex_

Size creditStateNPVsIndex_ = QuantLib::Null<Size>()
private

Definition at line 112 of file cubeinterpretation.hpp.