Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cubeinterpretation.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file orea/cube/cubeinterpretation.hpp
20 \brief class describing the layout of an npv cube and aggregation scenario data
21 \ingroup cube
22*/
23
24#pragma once
25
26#include <orea/cube/npvcube.hpp>
29
30#include <ql/handle.hpp>
31
32#include <ql/shared_ptr.hpp>
33
34#include <map>
35#include <string>
36
37namespace ore {
38using namespace data;
39namespace analytics {
40
41//! Allow for interpretation of how data is stored within cube and AggregationScenarioData
42/*! \ingroup cube
43 */
45public:
46 CubeInterpretation(const bool storeFlows, const bool withCloseOutLag,
47 const QuantLib::Handle<AggregationScenarioData>& aggregationScenarioData =
48 QuantLib::Handle<AggregationScenarioData>(),
49 const QuantLib::ext::shared_ptr<DateGrid>& dateGrid = nullptr, const Size storeCreditStateNPVs = 0,
50 const bool flipViewXVA = false);
51
52 //! inspectors
53 bool storeFlows() const;
54 bool withCloseOutLag() const;
55 const QuantLib::Handle<AggregationScenarioData>& aggregationScenarioData() const; // might be empty handle
56 const QuantLib::ext::shared_ptr<DateGrid>& dateGrid() const; // might be nullptr
57 Size storeCreditStateNPVs() const;
58 bool flipViewXVA() const;
59
60 //! npv cube depth that is at least required to work with this interpretation
61 Size requiredNpvCubeDepth() const;
62
63 //! indices in depth direction, might be Null<Size>() if not applicable
64 Size defaultDateNpvIndex() const;
65 Size closeOutDateNpvIndex() const;
66 Size mporFlowsIndex() const;
67 Size creditStateNPVsIndex() const;
68
69 //! Retrieve an arbitrary value from the Cube (user needs to know the precise location within depth axis)
70 Real getGenericValue(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size tradeIdx, Size dateIdx, Size sampleIdx,
71 Size depth) const;
72
73 //! Retrieve the default date NPV from the Cube
74 Real getDefaultNpv(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const;
75
76 //! Retrieve the close-out date NPV from the Cube
77 Real getCloseOutNpv(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const;
78
79 //! Retrieve the aggregate value of Margin Period of Risk positive cashflows from the Cube
80 Real getMporPositiveFlows(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size tradeIdx, Size dateIdx,
81 Size sampleIdx) const;
82
83 //! Retrieve the aggregate value of Margin Period of Risk negative cashflows from the Cube
84 Real getMporNegativeFlows(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size tradeIdx, Size dateIdx,
85 Size sampleIdx) const;
86 //! Retrieve the aggregate value of Margin Period of Risk cashflows from the Cube
87 Real getMporFlows(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const;
88
89 //! Retrieve a (default date) simulated risk factor value from AggregationScenarioData
90 Real getDefaultAggregationScenarioData(const AggregationScenarioDataType& dataType, Size dateIdx, Size sampleIdx,
91 const std::string& qualifier = "") const;
92
93 //! Retrieve a (default date) simulated risk factor value from AggregationScenarioData
94 Real getCloseOutAggregationScenarioData(const AggregationScenarioDataType& dataType, Size dateIdx, Size sampleIdx,
95 const std::string& qualifier = "") const;
96
97 //! Number of Calendar Days between a given default date and corresponding close-out date
98 Size getMporCalendarDays(const QuantLib::ext::shared_ptr<NPVCube>& cube, Size dateIdx) const;
99
100private:
103 QuantLib::Handle<AggregationScenarioData> aggregationScenarioData_;
104 QuantLib::ext::shared_ptr<DateGrid> dateGrid_;
107
109 Size defaultDateNpvIndex_ = QuantLib::Null<Size>();
110 Size closeOutDateNpvIndex_ = QuantLib::Null<Size>();
111 Size mporFlowsIndex_ = QuantLib::Null<Size>();
112 Size creditStateNPVsIndex_ = QuantLib::Null<Size>();
113};
114
115} // namespace analytics
116} // namespace ore
this class holds data associated to scenarios
Allow for interpretation of how data is stored within cube and AggregationScenarioData.
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.
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.
const QuantLib::ext::shared_ptr< DateGrid > & dateGrid() const
Size defaultDateNpvIndex() const
indices in depth direction, might be Null<Size>() if not applicable
const QuantLib::Handle< AggregationScenarioData > & aggregationScenarioData() const
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 getDefaultAggregationScenarioData(const AggregationScenarioDataType &dataType, Size dateIdx, Size sampleIdx, const std::string &qualifier="") const
Retrieve a (default date) simulated risk factor value from AggregationScenarioData.
Real getCloseOutAggregationScenarioData(const AggregationScenarioDataType &dataType, Size dateIdx, Size sampleIdx, const std::string &qualifier="") const
Retrieve a (default date) simulated risk factor value from AggregationScenarioData.
Real getDefaultNpv(const QuantLib::ext::shared_ptr< NPVCube > &cube, Size tradeIdx, Size dateIdx, Size sampleIdx) const
Retrieve the default date NPV 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.
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.
QuantLib::ext::shared_ptr< DateGrid > dateGrid_
Size requiredNpvCubeDepth() const
npv cube depth that is at least required to work with this interpretation
QuantLib::Handle< AggregationScenarioData > aggregationScenarioData_
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)
data
The base NPV cube class.