Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
parametricvar.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file engine/parametricvar.hpp
20 \brief Perform parametric var calculation for a given portfolio
21 \ingroup engine
22*/
23
24#pragma once
25
32
35
37
38#include <ql/math/array.hpp>
39#include <ql/math/matrix.hpp>
40
41#include <map>
42#include <set>
43
44namespace ore {
45namespace analytics {
46using QuantLib::Array;
47using QuantLib::Matrix;
48
49typedef std::pair<RiskFactorKey, RiskFactorKey> CrossPair;
50
52public:
53 //! A container for holding the parametric VAR parameters
55 enum class Method {
56 Delta,
61 };
62
64 ParametricVarParams(const std::string& m, QuantLib::Size samples, QuantLib::Size seed);
65
67 QuantLib::Size samples = QuantLib::Null<QuantLib::Size>();
68 QuantLib::Size seed = QuantLib::Null<QuantLib::Size>();
69 };
70
71 ParametricVarCalculator(const ParametricVarParams& parametricVarParams, const QuantLib::Matrix& omega,
72 const std::map<RiskFactorKey, QuantLib::Real>& deltas,
73 const std::map<CrossPair, Real>& gammas, const QuantLib::ext::shared_ptr<QuantExt::CovarianceSalvage>& covarianceSalvage,
74 const bool& includeGammaMargin, const bool& includeDeltaMargin) :
75 parametricVarParams_(parametricVarParams), omega_(omega), deltas_(deltas), gammas_(gammas), covarianceSalvage_(covarianceSalvage),
76 includeGammaMargin_(includeGammaMargin), includeDeltaMargin_(includeDeltaMargin) {}
77
78
79 QuantLib::Real var(QuantLib::Real confidence, const bool isCall = true,
80 const std::set<std::pair<std::string, QuantLib::Size>>& tradeIds = {}) override;
81
82private:
84 const QuantLib::Matrix& omega_;
85 const std::map<RiskFactorKey, QuantLib::Real>& deltas_;
86 const std::map<CrossPair, QuantLib::Real>& gammas_;
87 const QuantLib::ext::shared_ptr<QuantExt::CovarianceSalvage>& covarianceSalvage_;
90};
91
92//! Parametric VaR Calculator
93/*! This class takes sensitivity data and a covariance matrix as an input and computes a parametric value at risk. The
94 * output can be broken down by portfolios, risk classes (IR, FX, EQ, ...) and risk types (delta-gamma, vega, ...). */
96public:
99 const std::string& baseCurrency,
100 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
101 const std::string& portfolioFilter,
102 const std::vector<QuantLib::Real>& p,
103 const ParametricVarCalculator::ParametricVarParams& parametricVarParams,
104 const bool salvageCovarianceMatrix, boost::optional<ore::data::TimePeriod> period,
105 std::unique_ptr<SensiRunArgs> sensiArgs = nullptr, const bool breakdown = false);
106
108 const std::string& baseCurrency,
109 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
110 const std::string& portfolioFilter,
111 const QuantLib::ext::shared_ptr<HistoricalScenarioGenerator>& hisScenGen,
112 const std::vector<QuantLib::Real>& p,
113 const ParametricVarCalculator::ParametricVarParams& parametricVarParams,
114 const bool salvageCovarianceMatrix, boost::optional<ore::data::TimePeriod> period,
115 std::unique_ptr<SensiRunArgs> sensiArgs = nullptr, const bool breakdown = false);
116
117 void createVarCalculator() override;
118
119 typedef std::pair<RiskFactorKey, RiskFactorKey> CrossPair;
120
121protected:
122 const QuantLib::ext::shared_ptr<SensitivityScenarioData> sensitivityConfig_;
123 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters> simMarketConfig_;
124
125 //! The parameters to use for calculating the parametric VAR benchmark
128};
129
131std::ostream& operator<<(std::ostream& out, const ParametricVarCalculator::ParametricVarParams::Method& method);
132
133} // namespace analytics
134} // namespace ore
QuantLib::Real var(QuantLib::Real confidence, const bool isCall=true, const std::set< std::pair< std::string, QuantLib::Size > > &tradeIds={}) override
const QuantLib::ext::shared_ptr< QuantExt::CovarianceSalvage > & covarianceSalvage_
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)
const std::map< CrossPair, QuantLib::Real > & gammas_
const std::map< RiskFactorKey, QuantLib::Real > & deltas_
const ParametricVarParams & parametricVarParams_
Parametric VaR Calculator.
const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketConfig_
ParametricVarCalculator::ParametricVarParams parametricVarParams_
The parameters to use for calculating the parametric VAR benchmark.
const QuantLib::ext::shared_ptr< SensitivityScenarioData > sensitivityConfig_
ParametricVarReport(const std::string &baseCurrency, const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const std::string &portfolioFilter, const std::vector< QuantLib::Real > &p, const ParametricVarCalculator::ParametricVarParams &parametricVarParams, const bool salvageCovarianceMatrix, boost::optional< ore::data::TimePeriod > period, std::unique_ptr< SensiRunArgs > sensiArgs=nullptr, const bool breakdown=false)
ParametricVarReport(const std::string &baseCurrency, const QuantLib::ext::shared_ptr< Portfolio > &portfolio, const std::string &portfolioFilter, const QuantLib::ext::shared_ptr< HistoricalScenarioGenerator > &hisScenGen, const std::vector< QuantLib::Real > &p, const ParametricVarCalculator::ParametricVarParams &parametricVarParams, const bool salvageCovarianceMatrix, boost::optional< ore::data::TimePeriod > period, std::unique_ptr< SensiRunArgs > sensiArgs=nullptr, const bool breakdown=false)
std::pair< RiskFactorKey, RiskFactorKey > CrossPair
const std::vector< Real > & p() const
scenario generator that builds from historical shifts
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
ParametricVarCalculator::ParametricVarParams::Method parseParametricVarMethod(const string &s)
std::pair< RiskFactorKey, RiskFactorKey > CrossPair
A class to hold Scenario parameters for scenarioSimMarket.
Class for aggregating SensitivityRecords.
A class to hold the parametrisation for building sensitivity scenarios.
Base class for sensitivity record streamer.
A container for holding the parametric VAR parameters.
ParametricVarParams(const std::string &m, QuantLib::Size samples, QuantLib::Size seed)
Base class for a var calculation.