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

#include <orea/engine/historicalsensipnlcalculator.hpp>

+ Collaboration diagram for CovarianceCalculator:

Public Member Functions

 CovarianceCalculator (ore::data::TimePeriod covariancePeriod)
 
void initialise (const std::set< std::pair< RiskFactorKey, QuantLib::Size > > &keys)
 
void updateAccumulators (const QuantLib::ext::shared_ptr< NPVCube > &shiftCube, QuantLib::Date startDate, QuantLib::Date endDate, QuantLib::Size index)
 
void populateCovariance (const std::set< std::pair< RiskFactorKey, QuantLib::Size > > &keys)
 
const Matrix & covariance () const
 

Private Types

typedef boost::accumulators::accumulator_set< QuantLib::Real, boost::accumulators::stats< boost::accumulators::tag::covariance< QuantLib::Real, boost::accumulators::tag::covariate1 > > > accumulator
 

Private Attributes

std::map< std::pair< QuantLib::Size, QuantLib::Size >, accumulatoraccCov_
 
ore::data::TimePeriod covariancePeriod_
 
QuantLib::Matrix covariance_
 

Detailed Description

Definition at line 86 of file historicalsensipnlcalculator.hpp.

Member Typedef Documentation

◆ accumulator

typedef boost::accumulators::accumulator_set< QuantLib::Real, boost::accumulators::stats<boost::accumulators::tag::covariance<QuantLib::Real, boost::accumulators::tag::covariate1> > > accumulator
private

Definition at line 98 of file historicalsensipnlcalculator.hpp.

Constructor & Destructor Documentation

◆ CovarianceCalculator()

Definition at line 88 of file historicalsensipnlcalculator.hpp.

88: covariancePeriod_(covariancePeriod) {}

Member Function Documentation

◆ initialise()

void initialise ( const std::set< std::pair< RiskFactorKey, QuantLib::Size > > &  keys)

Definition at line 85 of file historicalsensipnlcalculator.cpp.

85 {
86 // Set up the boost accumulators that will calculate the covariance between the time series of historical shifts for
87 // each relevant risk factor key i.e. the risk factor keys in the set keys over the benchmark period
88
89 for (auto ito = keys.begin(); ito != keys.end(); ito++) {
90 accCov_[make_pair(ito->second, ito->second)] = accumulator();
91 for (auto iti = keys.begin(); iti != ito; iti++) {
92 accCov_[make_pair(iti->second, ito->second)] = accumulator();
93 }
94 }
95}
boost::accumulators::accumulator_set< QuantLib::Real, boost::accumulators::stats< boost::accumulators::tag::covariance< QuantLib::Real, boost::accumulators::tag::covariate1 > > > accumulator
std::map< std::pair< QuantLib::Size, QuantLib::Size >, accumulator > accCov_

◆ updateAccumulators()

void updateAccumulators ( const QuantLib::ext::shared_ptr< NPVCube > &  shiftCube,
QuantLib::Date  startDate,
QuantLib::Date  endDate,
QuantLib::Size  index 
)

Definition at line 97 of file historicalsensipnlcalculator.cpp.

97 {
98 TLOG("Updating Covariance accumlators for sensitivity record " << index);
99 if (covariancePeriod_.contains(startDate) &&
100 covariancePeriod_.contains(endDate)) {
101 // Update the covariance accumulators if in benchmark period
102 for (auto it = accCov_.begin(); it != accCov_.end(); it++) {
103 Real oShift = shiftCube->get(it->first.first, 0, index);
104 if (it->first.first == it->first.second) {
105 it->second(oShift, covariate1 = oShift);
106 } else {
107 Real iShift = shiftCube->get(it->first.second, 0, index);
108 it->second(oShift, covariate1 = iShift);
109 }
110 }
111 }
112}
bool contains(const Date &d) const
#define TLOG(text)
+ Here is the call graph for this function:

◆ populateCovariance()

void populateCovariance ( const std::set< std::pair< RiskFactorKey, QuantLib::Size > > &  keys)

Definition at line 114 of file historicalsensipnlcalculator.cpp.

114 {
115 LOG("Populate the covariance matrix with the calculated covariances");
116 covariance_ = Matrix(keys.size(), keys.size());
117 Size i = 0;
118 for (auto ito = keys.begin(); ito != keys.end(); ito++) {
119 covariance_[i][i] = boost::accumulators::covariance(accCov_.at(make_pair(ito->second, ito->second)));
120 Size j = 0;
121 for (auto iti = keys.begin(); iti != ito; iti++) {
122 covariance_[i][j] = covariance_[j][i] =
123 boost::accumulators::covariance(accCov_.at(make_pair(iti->second, ito->second)));
124 j++;
125 }
126 i++;
127 }
128}
#define LOG(text)

◆ covariance()

const Matrix & covariance ( ) const

Definition at line 92 of file historicalsensipnlcalculator.hpp.

92{ return covariance_; }

Member Data Documentation

◆ accCov_

std::map<std::pair<QuantLib::Size, QuantLib::Size>, accumulator> accCov_
private

Definition at line 99 of file historicalsensipnlcalculator.hpp.

◆ covariancePeriod_

ore::data::TimePeriod covariancePeriod_
private

Definition at line 100 of file historicalsensipnlcalculator.hpp.

◆ covariance_

QuantLib::Matrix covariance_
private

Definition at line 101 of file historicalsensipnlcalculator.hpp.