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

#include <orea/engine/parsensitivitycubestream.hpp>

+ Inheritance diagram for ParSensitivityCubeStream:
+ Collaboration diagram for ParSensitivityCubeStream:

Public Member Functions

 ParSensitivityCubeStream (const QuantLib::ext::shared_ptr< ZeroToParCube > &cube, const std::string &currency)
 
ore::analytics::SensitivityRecord next () override
 
void reset () override
 Resets the stream so that SensitivityRecord objects can be streamed again. More...
 
- Public Member Functions inherited from SensitivityStream
virtual ~SensitivityStream ()
 Destructor. More...
 
virtual SensitivityRecord next ()=0
 Returns the next SensitivityRecord in the stream. More...
 
virtual void reset ()=0
 Resets the stream so that SensitivityRecord objects can be streamed again. More...
 

Private Member Functions

void init ()
 Shared initialisation. More...
 

Private Attributes

Size zeroCubeIdx_
 zero cube idx More...
 
QuantLib::ext::shared_ptr< ZeroToParCubecube_
 Handle on the SensitivityCube. More...
 
std::string currency_
 Currency of the sensitivities in the SensitivityCube. More...
 
std::map< std::string, QuantLib::Size >::const_iterator tradeIdx_
 TradeId and index of current trade ID in the underlying cube. More...
 
std::map< ore::analytics::RiskFactorKey, QuantLib::Real > currentDeltas_
 Par deltas for current trade ID. More...
 
std::map< ore::analytics::RiskFactorKey, QuantLib::Real >::iterator itCurrent_
 Iterator to current delta. More...
 

Detailed Description

Class for streaming SensitivityRecords from a par sensitivity cube

Definition at line 35 of file parsensitivitycubestream.hpp.

Constructor & Destructor Documentation

◆ ParSensitivityCubeStream()

ParSensitivityCubeStream ( const QuantLib::ext::shared_ptr< ZeroToParCube > &  cube,
const std::string &  currency 
)

Constructor providing the sensitivity cube and currency of the sensitivities

Definition at line 32 of file parsensitivitycubestream.cpp.

33 : zeroCubeIdx_(0), cube_(cube), currency_(currency), itCurrent_(currentDeltas_.begin()) {
34 QL_REQUIRE(!cube_->zeroCubes().empty(), "ParSensitivityCubeStream: cube contains no zero cubes");
35 tradeIdx_ = cube_->zeroCubes().front()->tradeIdx().begin();
36 init();
37}
QuantLib::ext::shared_ptr< ZeroToParCube > cube_
Handle on the SensitivityCube.
std::string currency_
Currency of the sensitivities in the SensitivityCube.
std::map< std::string, QuantLib::Size >::const_iterator tradeIdx_
TradeId and index of current trade ID in the underlying cube.
std::map< ore::analytics::RiskFactorKey, QuantLib::Real >::iterator itCurrent_
Iterator to current delta.
std::map< ore::analytics::RiskFactorKey, QuantLib::Real > currentDeltas_
Par deltas for current trade ID.
+ Here is the call graph for this function:

Member Function Documentation

◆ next()

SensitivityRecord next ( )
overridevirtual

Returns the next SensitivityRecord in the stream

Warning:
the cube must not change during successive calls to next()!

Implements SensitivityStream.

Definition at line 39 of file parsensitivitycubestream.cpp.

39 {
40
42
43 while (itCurrent_ == currentDeltas_.end() && tradeIdx_ != cube_->zeroCubes()[zeroCubeIdx_]->tradeIdx().end()) {
44 // Move to next trade
45 tradeIdx_++;
46 // update par deltas
47 if (tradeIdx_ != cube_->zeroCubes()[zeroCubeIdx_]->tradeIdx().end()) {
48 DLOG("Retrieving par deltas for trade " << tradeIdx_->first);
49 currentDeltas_ = cube_->parDeltas(zeroCubeIdx_, tradeIdx_->second);
50 itCurrent_ = currentDeltas_.begin();
51 DLOG("There are " << currentDeltas_.size() << " par deltas for trade " << tradeIdx_->first);
52 }
53 }
54
55 if (tradeIdx_ != cube_->zeroCubes()[zeroCubeIdx_]->tradeIdx().end()) {
56 // Populate current sensitivity record
57 sr.tradeId = tradeIdx_->first;
58 sr.isPar = true;
60 sr.baseNpv = cube_->zeroCubes()[zeroCubeIdx_]->npv(tradeIdx_->second);
61 if (itCurrent_ != currentDeltas_.end()) {
62 DLOG("Processing par delta [" << itCurrent_->first << ", " << itCurrent_->second << "]");
63 sr.key_1 = itCurrent_->first;
64 auto fullDescription = cube_->zeroCubes()[zeroCubeIdx_]->factorDescription(sr.key_1);
65 sr.desc_1 = deconstructFactor(fullDescription).second;
66 sr.shift_1 = cube_->zeroCubes()[zeroCubeIdx_]->targetShiftSize(sr.key_1);
67 sr.delta = itCurrent_->second;
68 sr.gamma = Null<Real>();
69 // Move iterator to next par delta
70 itCurrent_++;
71 }
72 } else if (zeroCubeIdx_ < cube_->zeroCubes().size() - 1) {
74 init();
75 return next();
76 }
77
78 return sr;
79}
ore::analytics::SensitivityRecord next() override
#define DLOG(text)
pair< RiskFactorKey, string > deconstructFactor(const string &factor)
Size size(const ValueType &v)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

void reset ( )
overridevirtual

Resets the stream so that SensitivityRecord objects can be streamed again.

Implements SensitivityStream.

Definition at line 81 of file parsensitivitycubestream.cpp.

81 {
82 // Reset all
83 zeroCubeIdx_ = 0;
84 tradeIdx_ = cube_->zeroCubes()[zeroCubeIdx_]->tradeIdx().begin();
85 currentDeltas_ = {};
86 itCurrent_ = currentDeltas_.begin();
87 // Call init
88 init();
89}
+ Here is the call graph for this function:

◆ init()

void init ( )
private

Shared initialisation.

Definition at line 91 of file parsensitivitycubestream.cpp.

91 {
92 // If we have trade IDs in the underlying cube
93 if (!cube_->zeroCubes()[zeroCubeIdx_]->tradeIdx().empty()) {
94 tradeIdx_ = cube_->zeroCubes()[zeroCubeIdx_]->tradeIdx().begin();
95 DLOG("Retrieving par deltas for trade " << tradeIdx_->first);
96 currentDeltas_ = cube_->parDeltas(zeroCubeIdx_, tradeIdx_->second);
97 itCurrent_ = currentDeltas_.begin();
98 DLOG("There are " << currentDeltas_.size() << " par deltas for trade " << tradeIdx_->first);
99 }
100}
+ Here is the caller graph for this function:

Member Data Documentation

◆ zeroCubeIdx_

Size zeroCubeIdx_
private

zero cube idx

Definition at line 51 of file parsensitivitycubestream.hpp.

◆ cube_

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

Handle on the SensitivityCube.

Definition at line 53 of file parsensitivitycubestream.hpp.

◆ currency_

std::string currency_
private

Currency of the sensitivities in the SensitivityCube.

Definition at line 55 of file parsensitivitycubestream.hpp.

◆ tradeIdx_

std::map<std::string,QuantLib::Size>::const_iterator tradeIdx_
private

TradeId and index of current trade ID in the underlying cube.

Definition at line 57 of file parsensitivitycubestream.hpp.

◆ currentDeltas_

std::map<ore::analytics::RiskFactorKey, QuantLib::Real> currentDeltas_
private

Par deltas for current trade ID.

Definition at line 59 of file parsensitivitycubestream.hpp.

◆ itCurrent_

std::map<ore::analytics::RiskFactorKey,QuantLib::Real>::iterator itCurrent_
private

Iterator to current delta.

Definition at line 61 of file parsensitivitycubestream.hpp.