Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dimregressioncalculator.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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 orea/aggregation/dimregressioncalculator.hpp
20 \brief Dynamic Initial Margin calculator by regression
21 \ingroup analytics
22*/
23
24#pragma once
25
27
28namespace ore {
29namespace analytics {
30using namespace QuantLib;
31using namespace QuantExt;
32using namespace data;
33using namespace std;
34
35//! Dynamic Initial Margin Calculator using polynomial regression
36/*!
37 Dynamic IM is estimated using polynomial and local regression methods applied to the NPV moves over simulation time
38 steps across all paths.
39*/
41public:
43 //! Global input parameters
44 const QuantLib::ext::shared_ptr<InputParameters>& inputs,
45 //! Driving portfolio consistent with the cube below
46 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
47 //! NPV cube resulting from the Monte Carlo simulation loop
48 const QuantLib::ext::shared_ptr<NPVCube>& cube,
49 //! Interpretation of the cube, regular NPV, MPoR grid etc
50 const QuantLib::ext::shared_ptr<CubeInterpretation>& cubeInterpretation,
51 //! Additional output of the MC simulation loop with numeraires, index fixings, FX spots etc
52 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
53 //! VaR quantile expressed as a percentage
54 Real quantile,
55 //! VaR holding period in calendar days
56 Size horizonCalendarDays,
57 //! Polynom order of the regression
58 Size regressionOrder,
59 //! Regressors to be used
60 vector<string> regressors,
61 //! Number of local regression evaluation windows across all paths, up to number of samples
62 Size localRegressionEvaluations = 0,
63 //! Local regression band width in standard deviations of the regression variable
64 Real localRegressionBandWidth = 0,
65 //! Actual t0 IM by netting set used to scale the DIM evolution, no scaling if the argument is omitted
66 const std::map<std::string, Real>& currentIM = std::map<std::string, Real>());
67
68 map<string, Real> unscaledCurrentDIM() override;
69 void build() override;
70 void exportDimEvolution(ore::data::Report& dimEvolutionReport) const override;
71
72 void exportDimRegression(const std::string& nettingSet, const std::vector<Size>& timeSteps,
73 const std::vector<QuantLib::ext::shared_ptr<ore::data::Report>>& dimRegReports);
74
75 const vector<vector<Real>>& localRegressionResults(const string& nettingSet);
76 const vector<Real>& zeroOrderResults(const string& nettingSet);
77 const vector<Real>& simpleResultsUpper(const string& nettingSet);
78 const vector<Real>& simpleResultsLower(const string& nettingSet);
79
80private:
81 //! Compile the array of DIM regressors for the specified netting set, date and sample index
82 Array regressorArray(string nettingSet, Size dateIndex, Size sampleIndex);
83
85 vector<string> regressors_;
88
89 // For each netting set: Array of regressor values by date and sample
90 map<string, vector<vector<Array>>> regressorArray_;
91 // For each netting set: local regression DIM estimate by date and sample
92 map<string, vector<vector<Real>>> nettingSetLocalDIM_;
93 // For each netting set: vector of values by date, aggregated over trades and samples
94 map<string, vector<Real>> nettingSetZeroOrderDIM_;
95 map<string, vector<Real>> nettingSetSimpleDIMh_;
96 map<string, vector<Real>> nettingSetSimpleDIMp_;
97};
98
99inline bool lessThan(const Array& a, const Array& b) {
100 QL_REQUIRE(a.size() > 0, "array a is empty");
101 QL_REQUIRE(b.size() > 0, "array a is empty");
102 return a[0] < b[0];
103}
104
105} // namespace analytics
106} // namespace ore
Dynamic Initial Margin Calculator base class.
const map< string, Real > & currentIM() const
t0 IM by netting set, as provided as an arguments
Dynamic Initial Margin Calculator using polynomial regression.
const vector< Real > & zeroOrderResults(const string &nettingSet)
void exportDimRegression(const std::string &nettingSet, const std::vector< Size > &timeSteps, const std::vector< QuantLib::ext::shared_ptr< ore::data::Report > > &dimRegReports)
void exportDimEvolution(ore::data::Report &dimEvolutionReport) const override
DIM evolution report.
Array regressorArray(string nettingSet, Size dateIndex, Size sampleIndex)
Compile the array of DIM regressors for the specified netting set, date and sample index.
const vector< vector< Real > > & localRegressionResults(const string &nettingSet)
void build() override
Compute dynamic initial margin along all paths and fill result structures.
const vector< Real > & simpleResultsLower(const string &nettingSet)
const vector< Real > & simpleResultsUpper(const string &nettingSet)
map< string, Real > unscaledCurrentDIM() override
Model implied t0 DIM by netting set, does not need a call to build() before.
Dynamic Initial Margin calculator base class.
data
bool lessThan(const string &s1, const string &s2)