24#include <boost/numeric/ublas/vector.hpp>
38 const QuantLib::ext::shared_ptr<ParSensitivityConverter>& parConverter,
39 const set<RiskFactorKey::KeyType>& typesDisabled,
const bool continueOnError)
44 const QuantLib::ext::shared_ptr<ParSensitivityConverter>& parConverter,
45 const set<RiskFactorKey::KeyType>& typesDisabled,
const bool continueOnError)
46 : zeroCubes_(zeroCubes), parConverter_(parConverter), typesDisabled_(typesDisabled),
47 continueOnError_(continueOnError) {
50 for (
auto const& k : parConverter_->rawKeys()) {
51 factorToIndex_[k] = counter++;
57 DLOG(
"Calculating par deltas for trade index " << tradeIdx);
59 map<RiskFactorKey, Real> result;
62 boost::numeric::ublas::vector<Real> zeroDeltas(
parConverter_->rawKeys().size(), 0.0);
65 "ZeroToParCube::parDeltas(): cubeIdx (" << cubeIdx <<
") out of range 0..." << (
zeroCubes_.size() - 1));
67 const QuantLib::ext::shared_ptr<SensitivityCube>& zeroCube =
zeroCubes_[cubeIdx];
68 const QuantLib::ext::shared_ptr<NPVSensiCube>& sensiCube = zeroCube->npvCube();
70 std::set<RiskFactorKey> rkeys;
71 for (
auto const& kv : sensiCube->getTradeNPVs(tradeIdx)) {
76 for (
auto const& rk : rkeys) {
83 " not found in factorToIndex map")
87 "ZeroToParCube::parDeltas(): par factor " << rk <<
" not found in factorToIndex map");
91 zeroDeltas[it->second] = zeroCube->delta(tradeIdx, rk);
106 for (
const auto& f : rkeys) {
108 Real delta = zeroCube->delta(tradeIdx, f);
109 if (!
close(delta, 0.0)) {
115 DLOG(
"Finished calculating par deltas for cube index " << cubeIdx <<
", trade index " << tradeIdx);
122 DLOG(
"Calculating par deltas for trade " << tradeId);
123 map<RiskFactorKey, Real> result;
126 Size tradeIdx = Null<Size>();
127 for (cubeIdx = 0; cubeIdx <
zeroCubes_.size() && tradeIdx == Null<Size>(); ++cubeIdx) {
129 tradeIdx =
zeroCubes_[cubeIdx]->npvCube()->getTradeIndex(tradeId);
134 QL_REQUIRE(tradeIdx != Null<Size>(),
"ZeroToParCube::parDeltas(): tradeId '"
135 << tradeId <<
"' not found in " <<
zeroCubes_.size() <<
" zero cubes.");
139 DLOG(
"Finished calculating par deltas for trade " << tradeId);
static bool isParType(ore::analytics::RiskFactorKey::KeyType type)
Returns true if risk factor type is applicable for par conversion.
SensitivityCube is a wrapper for an npvCube that gives easier access to the underlying cube elements.
std::map< ore::analytics::RiskFactorKey, Size > factorToIndex_
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...
const bool continueOnError_
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.
std::map< ore::analytics::RiskFactorKey, QuantLib::Real > parDeltas(const std::string &tradeId) const
Return the non-zero par deltas for the given tradeId.
std::vector< QuantLib::ext::shared_ptr< ore::analytics::SensitivityCube > > zeroCubes_
QuantLib::ext::shared_ptr< ParSensitivityConverter > parConverter_
bool close(const Real &t_1, const Real &t_2)
std::string to_string(const LocationInfo &l)
Structured analytics error.
Class for converting zero sensitivities to par sensitivities.