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

ZeroToParCube class. More...

#include <orea/engine/zerotoparcube.hpp>

+ Collaboration diagram for ZeroToParCube:

Public Member Functions

 ZeroToParCube (const QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > &zeroCube, const QuantLib::ext::shared_ptr< ParSensitivityConverter > &parConverter, const std::set< ore::analytics::RiskFactorKey::KeyType > &typesDisabled={}, const bool continueOnError=false)
 Constructor. More...
 
 ZeroToParCube (const std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > &zeroCubes, const QuantLib::ext::shared_ptr< ParSensitivityConverter > &parConverter, const std::set< ore::analytics::RiskFactorKey::KeyType > &typesDisabled={}, const bool continueOnError=false)
 Another Constructor! More...
 
const std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > & zeroCubes () const
 Inspectors. More...
 
const QuantLib::ext::shared_ptr< ParSensitivityConverter > & parConverter () const
 Par converter object. More...
 
const std::set< ore::analytics::RiskFactorKey::KeyType > & typesDisabled () const
 The par risk factor types that are disabled for this instance of ZeroToParCube. More...
 
std::map< ore::analytics::RiskFactorKey, QuantLib::Real > parDeltas (const std::string &tradeId) const
 Return the non-zero par deltas for the given tradeId. More...
 
std::map< ore::analytics::RiskFactorKey, QuantLib::Real > parDeltas (QuantLib::Size cubeIdx, QuantLib::Size tradeIdx) const
 Return the non-zero par deltas for the given cube and trade index. More...
 

Private Attributes

std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > zeroCubes_
 
QuantLib::ext::shared_ptr< ParSensitivityConverterparConverter_
 
std::map< ore::analytics::RiskFactorKey, Size > factorToIndex_
 
std::set< ore::analytics::RiskFactorKey::KeyTypetypesDisabled_
 Set of risk factor types available for par conversion but that are disabled for this instance of ZeroToParCube. More...
 
const bool continueOnError_
 

Detailed Description

ZeroToParCube class.

Takes a cube of zero sensitivities, a par sensitivity converter and can return the par deltas for a given trade ID from the cube.

Definition at line 38 of file zerotoparcube.hpp.

Constructor & Destructor Documentation

◆ ZeroToParCube() [1/2]

ZeroToParCube ( const QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > &  zeroCube,
const QuantLib::ext::shared_ptr< ParSensitivityConverter > &  parConverter,
const std::set< ore::analytics::RiskFactorKey::KeyType > &  typesDisabled = {},
const bool  continueOnError = false 
)

Constructor.

◆ ZeroToParCube() [2/2]

ZeroToParCube ( const std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > &  zeroCubes,
const QuantLib::ext::shared_ptr< ParSensitivityConverter > &  parConverter,
const std::set< ore::analytics::RiskFactorKey::KeyType > &  typesDisabled = {},
const bool  continueOnError = false 
)

Another Constructor!

Member Function Documentation

◆ zeroCubes()

const std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > & zeroCubes ( ) const

Inspectors.

Underlying zero sensitivity cubes

Definition at line 54 of file zerotoparcube.hpp.

54{ return zeroCubes_; }
std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > zeroCubes_

◆ parConverter()

const QuantLib::ext::shared_ptr< ParSensitivityConverter > & parConverter ( ) const

Par converter object.

Definition at line 56 of file zerotoparcube.hpp.

56{ return parConverter_; }
QuantLib::ext::shared_ptr< ParSensitivityConverter > parConverter_

◆ typesDisabled()

const std::set< ore::analytics::RiskFactorKey::KeyType > & typesDisabled ( ) const

The par risk factor types that are disabled for this instance of ZeroToParCube.

Definition at line 58 of file zerotoparcube.hpp.

58{ return typesDisabled_; }
std::set< ore::analytics::RiskFactorKey::KeyType > typesDisabled_
Set of risk factor types available for par conversion but that are disabled for this instance of Zero...

◆ parDeltas() [1/2]

map< RiskFactorKey, Real > parDeltas ( const std::string &  tradeId) const

Return the non-zero par deltas for the given tradeId.

Definition at line 120 of file zerotoparcube.cpp.

120 {
121
122 DLOG("Calculating par deltas for trade " << tradeId);
123 map<RiskFactorKey, Real> result;
124
125 Size cubeIdx;
126 Size tradeIdx = Null<Size>();
127 for (cubeIdx = 0; cubeIdx < zeroCubes_.size() && tradeIdx == Null<Size>(); ++cubeIdx) {
128 try {
129 tradeIdx = zeroCubes_[cubeIdx]->npvCube()->getTradeIndex(tradeId);
130 break;
131 } catch (...) {
132 }
133 }
134 QL_REQUIRE(tradeIdx != Null<Size>(), "ZeroToParCube::parDeltas(): tradeId '"
135 << tradeId << "' not found in " << zeroCubes_.size() << " zero cubes.");
136
137 result = parDeltas(cubeIdx, tradeIdx);
138
139 DLOG("Finished calculating par deltas for trade " << tradeId);
140
141 return result;
142}
std::map< ore::analytics::RiskFactorKey, QuantLib::Real > parDeltas(const std::string &tradeId) const
Return the non-zero par deltas for the given tradeId.
#define DLOG(text)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parDeltas() [2/2]

map< RiskFactorKey, Real > parDeltas ( QuantLib::Size  cubeIdx,
QuantLib::Size  tradeIdx 
) const

Return the non-zero par deltas for the given cube and trade index.

Definition at line 55 of file zerotoparcube.cpp.

55 {
56
57 DLOG("Calculating par deltas for trade index " << tradeIdx);
58
59 map<RiskFactorKey, Real> result;
60
61 // Get the "par-convertible" zero deltas
62 boost::numeric::ublas::vector<Real> zeroDeltas(parConverter_->rawKeys().size(), 0.0);
63
64 QL_REQUIRE(cubeIdx < zeroCubes_.size(),
65 "ZeroToParCube::parDeltas(): cubeIdx (" << cubeIdx << ") out of range 0..." << (zeroCubes_.size() - 1));
66
67 const QuantLib::ext::shared_ptr<SensitivityCube>& zeroCube = zeroCubes_[cubeIdx];
68 const QuantLib::ext::shared_ptr<NPVSensiCube>& sensiCube = zeroCube->npvCube();
69
70 std::set<RiskFactorKey> rkeys;
71 for (auto const& kv : sensiCube->getTradeNPVs(tradeIdx)) {
72 if (auto k = zeroCube->upDownFactor(kv.first); k.keytype != RiskFactorKey::KeyType::None)
73 rkeys.insert(k);
74 }
75
76 for (auto const& rk : rkeys) {
77 auto it = factorToIndex_.find(rk);
78 if (it == factorToIndex_.end()) {
79 if (ParSensitivityAnalysis::isParType(rk.keytype) && typesDisabled_.count(rk.keytype) != 1) {
80 if (continueOnError_) {
81 StructuredAnalyticsErrorMessage("Par conversion", "",
82 "Par factor " + ore::data::to_string(rk) +
83 " not found in factorToIndex map")
84 .log();
85 } else {
86 QL_REQUIRE(!ParSensitivityAnalysis::isParType(rk.keytype) || typesDisabled_.count(rk.keytype) == 1,
87 "ZeroToParCube::parDeltas(): par factor " << rk << " not found in factorToIndex map");
88 }
89 }
90 } else {
91 zeroDeltas[it->second] = zeroCube->delta(tradeIdx, rk);
92 }
93 }
94
95 // Convert the zero deltas to par deltas
96 boost::numeric::ublas::vector<Real> parDeltas = parConverter_->convertSensitivity(zeroDeltas);
97 Size counter = 0;
98 for (const auto& key : parConverter_->parKeys()) {
99 if (!close(parDeltas[counter], 0.0)) {
100 result[key] = parDeltas[counter];
101 }
102 counter++;
103 }
104
105 // Add non-zero deltas that do not need to be converted from underlying zero cube
106 for (const auto& f : rkeys) {
107 if (!ParSensitivityAnalysis::isParType(f.keytype) || typesDisabled_.count(f.keytype) == 1) {
108 Real delta = zeroCube->delta(tradeIdx, f);
109 if (!close(delta, 0.0)) {
110 result[f] = delta;
111 }
112 }
113 }
114
115 DLOG("Finished calculating par deltas for cube index " << cubeIdx << ", trade index " << tradeIdx);
116
117 return result;
118}
static bool isParType(ore::analytics::RiskFactorKey::KeyType type)
Returns true if risk factor type is applicable for par conversion.
std::map< ore::analytics::RiskFactorKey, Size > factorToIndex_
bool close(const Real &t_1, const Real &t_2)
std::string to_string(const LocationInfo &l)
+ Here is the call graph for this function:

Member Data Documentation

◆ zeroCubes_

std::vector<QuantLib::ext::shared_ptr<ore::analytics::SensitivityCube> > zeroCubes_
private

Definition at line 69 of file zerotoparcube.hpp.

◆ parConverter_

QuantLib::ext::shared_ptr<ParSensitivityConverter> parConverter_
private

Definition at line 70 of file zerotoparcube.hpp.

◆ factorToIndex_

std::map<ore::analytics::RiskFactorKey, Size> factorToIndex_
private

Definition at line 71 of file zerotoparcube.hpp.

◆ typesDisabled_

std::set<ore::analytics::RiskFactorKey::KeyType> typesDisabled_
private

Set of risk factor types available for par conversion but that are disabled for this instance of ZeroToParCube.

Definition at line 74 of file zerotoparcube.hpp.

◆ continueOnError_

const bool continueOnError_
private

Definition at line 75 of file zerotoparcube.hpp.