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

#include <orea/engine/parametricvar.hpp>

+ Inheritance diagram for ParametricVarCalculator:
+ Collaboration diagram for ParametricVarCalculator:

Classes

struct  ParametricVarParams
 A container for holding the parametric VAR parameters. More...
 

Public Member Functions

 ParametricVarCalculator (const ParametricVarParams &parametricVarParams, const QuantLib::Matrix &omega, const std::map< RiskFactorKey, QuantLib::Real > &deltas, const std::map< CrossPair, Real > &gammas, const QuantLib::ext::shared_ptr< QuantExt::CovarianceSalvage > &covarianceSalvage, const bool &includeGammaMargin, const bool &includeDeltaMargin)
 
QuantLib::Real var (QuantLib::Real confidence, const bool isCall=true, const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds={}) override
 
- Public Member Functions inherited from VarCalculator
 VarCalculator ()
 
virtual ~VarCalculator ()
 
virtual QuantLib::Real var (QuantLib::Real confidence, const bool isCall=true, const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds={})=0
 

Private Attributes

const ParametricVarParamsparametricVarParams_
 
const QuantLib::Matrix & omega_
 
const std::map< RiskFactorKey, QuantLib::Real > & deltas_
 
const std::map< CrossPair, QuantLib::Real > & gammas_
 
const QuantLib::ext::shared_ptr< QuantExt::CovarianceSalvage > & covarianceSalvage_
 
const boolincludeGammaMargin_
 
const boolincludeDeltaMargin_
 

Detailed Description

Definition at line 51 of file parametricvar.hpp.

Constructor & Destructor Documentation

◆ ParametricVarCalculator()

ParametricVarCalculator ( const ParametricVarParams parametricVarParams,
const QuantLib::Matrix &  omega,
const std::map< RiskFactorKey, QuantLib::Real > &  deltas,
const std::map< CrossPair, Real > &  gammas,
const QuantLib::ext::shared_ptr< QuantExt::CovarianceSalvage > &  covarianceSalvage,
const bool includeGammaMargin,
const bool includeDeltaMargin 
)

Definition at line 71 of file parametricvar.hpp.

74 :
75 parametricVarParams_(parametricVarParams), omega_(omega), deltas_(deltas), gammas_(gammas), covarianceSalvage_(covarianceSalvage),
76 includeGammaMargin_(includeGammaMargin), includeDeltaMargin_(includeDeltaMargin) {}
const QuantLib::ext::shared_ptr< QuantExt::CovarianceSalvage > & covarianceSalvage_
const std::map< CrossPair, QuantLib::Real > & gammas_
const std::map< RiskFactorKey, QuantLib::Real > & deltas_
const ParametricVarParams & parametricVarParams_

Member Function Documentation

◆ var()

Real var ( QuantLib::Real  confidence,
const bool  isCall = true,
const std::set< std::pair< std::string, QuantLib::Size > > &  tradeIds = {} 
)
overridevirtual

Implements VarCalculator.

Definition at line 78 of file parametricvar.cpp.

79 {
80 Real factor = isCall ? 1.0 : -1.0;
81
82 Array delta(deltas_.size(), 0.0);
83 Matrix gamma(deltas_.size(), deltas_.size(), 0.0);
84
86 Size counter = 0;
87 for (auto it = deltas_.begin(); it != deltas_.end(); it++)
88 delta[counter++] = factor * it->second;
89 }
90
92 Size outerIdx = 0;
93 for (auto ito = deltas_.begin(); ito != deltas_.end(); ito++) {
94 Size innerIdx = 0;
95 // Error if no diagonal element
96 gamma[outerIdx][outerIdx] = factor * gammas_.at(std::make_pair(ito->first, ito->first));
97 for (auto iti = deltas_.begin(); iti != ito; iti++) {
98 auto it = gammas_.find(std::make_pair(iti->first, ito->first));
99 if (it != gammas_.end()) {
100 gamma[innerIdx][outerIdx] = factor * it->second;
101 gamma[outerIdx][innerIdx] = factor * it->second;
102 }
103 innerIdx++;
104 }
105 outerIdx++;
106 }
107 }
108
110 return QuantExt::deltaVar(omega_, delta, confidence, *covarianceSalvage_);
111 else if (parametricVarParams_.method ==
113 return QuantExt::deltaGammaVarNormal(omega_, delta, gamma, confidence, *covarianceSalvage_);
115 QL_REQUIRE(parametricVarParams_.samples != Null<Size>(),
116 "ParametricVarCalculator::computeVar(): method MonteCarlo requires mcSamples");
117 QL_REQUIRE(parametricVarParams_.seed != Null<Size>(),
118 "ParametricVarCalculator::computeVar(): method MonteCarlo requires mcSamples");
119 return QuantExt::deltaGammaVarMc<PseudoRandom>(omega_, delta, gamma, confidence, parametricVarParams_.samples,
122 return QuantExt::deltaGammaVarCornishFisher(omega_, delta, gamma, confidence, *covarianceSalvage_);
124 Real res;
125 try {
126 res = QuantExt::deltaGammaVarSaddlepoint(omega_, delta, gamma, confidence, *covarianceSalvage_);
127 } catch (const std::exception& e) {
128 ALOG("Saddlepoint VaR computation exited with an error: " << e.what()
129 << ", falling back on Monte-Carlo");
130 res = QuantExt::deltaGammaVarMc<PseudoRandom>(omega_, delta, gamma, confidence,
132 }
133 return res;
134 } else
135 QL_FAIL("ParametricVarCalculator::computeVar(): method " << parametricVarParams_.method << " not known.");
136}
#define ALOG(text)
Real deltaGammaVarCornishFisher(const Matrix &omega, const Array &delta, const Matrix &gamma, const Real p, const CovarianceSalvage &sal)
Real deltaGammaVarNormal(const Matrix &omega, const Array &delta, const Matrix &gamma, const Real p, const CovarianceSalvage &sal=NoCovarianceSalvage())
Real deltaVar(const Matrix &omega, const Array &delta, const Real p, const CovarianceSalvage &sal=NoCovarianceSalvage())
Real deltaGammaVarSaddlepoint(const Matrix &omega, const Array &delta, const Matrix &gamma, const Real p, const CovarianceSalvage &sal)
+ Here is the call graph for this function:

Member Data Documentation

◆ parametricVarParams_

const ParametricVarParams& parametricVarParams_
private

Definition at line 83 of file parametricvar.hpp.

◆ omega_

const QuantLib::Matrix& omega_
private

Definition at line 84 of file parametricvar.hpp.

◆ deltas_

const std::map<RiskFactorKey, QuantLib::Real>& deltas_
private

Definition at line 85 of file parametricvar.hpp.

◆ gammas_

const std::map<CrossPair, QuantLib::Real>& gammas_
private

Definition at line 86 of file parametricvar.hpp.

◆ covarianceSalvage_

const QuantLib::ext::shared_ptr<QuantExt::CovarianceSalvage>& covarianceSalvage_
private

Definition at line 87 of file parametricvar.hpp.

◆ includeGammaMargin_

const bool& includeGammaMargin_
private

Definition at line 88 of file parametricvar.hpp.

◆ includeDeltaMargin_

const bool& includeDeltaMargin_
private

Definition at line 89 of file parametricvar.hpp.