Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dimcalculator.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/dimcalculator.hpp
20 \brief Dynamic Initial Margin calculator base class
21 \ingroup analytics
22*/
23
24#pragma once
25
31
35
36#include <ql/time/date.hpp>
37
38#include <ql/shared_ptr.hpp>
39
40namespace ore {
41namespace analytics {
42using namespace QuantLib;
43using namespace QuantExt;
44using namespace data;
45using namespace std;
46
47//! Dynamic Initial Margin Calculator base class
48/*!
49 Derived classes implement a constructor with the relevant additional input data
50 and a build function that performs the DIM calculations for all netting sets and
51 along all paths.
52*/
54public:
56 //! Global input parameters
57 const QuantLib::ext::shared_ptr<InputParameters>& inputs,
58 //! Driving portfolio consistent with the cube below
59 const QuantLib::ext::shared_ptr<Portfolio>& portfolio,
60 //! NPV cube resulting from the Monte Carlo simulation loop
61 const QuantLib::ext::shared_ptr<NPVCube>& cube,
62 //! Interpretation of the cube, regular NPV, MPoR grid etc
63 const QuantLib::ext::shared_ptr<CubeInterpretation>& cubeInterpretation,
64 //! Additional output of the MC simulation loop with numeraires, index fixings, FX spots etc
65 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
66 //! VaR quantile, e.g. 0.99 for 99%
67 Real quantile = 0.99,
68 //! VaR holding period in calendar days
69 Size horizonCalendarDays = 14,
70 //! Actual t0 IM by netting set used to scale the DIM evolution, no scaling if the argument is omitted
71 const std::map<std::string, Real>& currentIM = std::map<std::string, Real>());
72
74
75 //! Model implied t0 DIM by netting set, does not need a call to build() before
76 virtual map<string, Real> unscaledCurrentDIM() = 0;
77
78 //! t0 IM by netting set, as provided as an arguments
79 const map<string, Real>& currentIM() const { return currentIM_; }
80
81 //! Compute dynamic initial margin along all paths and fill result structures
82 virtual void build() = 0;
83
84 //! DIM evolution report
85 virtual void exportDimEvolution(ore::data::Report& dimEvolutionReport) const;
86
87 //! DIM by nettingSet, date, sample returned as a regular NPV cube
88 const QuantLib::ext::shared_ptr<NPVCube>& dimCube() { return dimCube_; }
89
90 //! DIM matrix by date and sample index for the specified netting set
91 const vector<vector<Real>>& dynamicIM(const string& nettingSet);
92
93 //! Cash flow matrix by date and sample index for the specified netting set
94 const vector<vector<Real>>& cashFlow(const string& nettingSet);
95
96 //! Expected DIM vector by date for the specified netting set
97 const vector<Real>& expectedIM(const string& nettingSet);
98
99 //! Get the implied netting set specific scaling factors
100 const std::map<std::string, Real>& getInitialMarginScaling() { return nettingSetScaling_; }
101
102protected:
103 QuantLib::ext::shared_ptr<InputParameters> inputs_;
104 QuantLib::ext::shared_ptr<Portfolio> portfolio_;
105 QuantLib::ext::shared_ptr<NPVCube> cube_, dimCube_;
106 QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpretation_;
107 QuantLib::ext::shared_ptr<AggregationScenarioData> scenarioData_;
110 map<string, Real> currentIM_;
111
114 std::set<string> nettingSetIds_;
115 map<string, Real> nettingSetScaling_;
116
117 // For each netting set: matrix of values by date and sample, aggregated over trades
118 map<string, vector<vector<Real>>> nettingSetNPV_;
119 map<string, vector<vector<Real>>> nettingSetCloseOutNPV_;
120 map<string, vector<vector<Real>>> nettingSetFLOW_;
121 map<string, vector<vector<Real>>> nettingSetDeltaNPV_;
122 map<string, vector<vector<Real>>> nettingSetDIM_;
123
124 // For each netting set: vector of values by date, aggregated over trades and samples
125 map<string, vector<Real>> nettingSetExpectedDIM_;
126};
127
128} // namespace analytics
129} // namespace ore
this class holds data associated to scenarios
Dynamic Initial Margin Calculator base class.
map< string, vector< vector< Real > > > nettingSetNPV_
virtual map< string, Real > unscaledCurrentDIM()=0
Model implied t0 DIM by netting set, does not need a call to build() before.
const vector< vector< Real > > & dynamicIM(const string &nettingSet)
DIM matrix by date and sample index for the specified netting set.
const map< string, Real > & currentIM() const
t0 IM by netting set, as provided as an arguments
virtual void build()=0
Compute dynamic initial margin along all paths and fill result structures.
const QuantLib::ext::shared_ptr< NPVCube > & dimCube()
DIM by nettingSet, date, sample returned as a regular NPV cube.
map< string, vector< vector< Real > > > nettingSetCloseOutNPV_
map< string, vector< vector< Real > > > nettingSetDeltaNPV_
map< string, vector< Real > > nettingSetExpectedDIM_
QuantLib::ext::shared_ptr< Portfolio > portfolio_
virtual void exportDimEvolution(ore::data::Report &dimEvolutionReport) const
DIM evolution report.
QuantLib::ext::shared_ptr< AggregationScenarioData > scenarioData_
const std::map< std::string, Real > & getInitialMarginScaling()
Get the implied netting set specific scaling factors.
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpretation_
QuantLib::ext::shared_ptr< NPVCube > dimCube_
map< string, vector< vector< Real > > > nettingSetFLOW_
const vector< Real > & expectedIM(const string &nettingSet)
Expected DIM vector by date for the specified netting set.
QuantLib::ext::shared_ptr< InputParameters > inputs_
map< string, vector< vector< Real > > > nettingSetDIM_
QuantLib::ext::shared_ptr< NPVCube > cube_
const vector< vector< Real > > & cashFlow(const string &nettingSet)
Cash flow matrix by date and sample index for the specified netting set.
Collateral Exposure Helper Functions (stored in base currency)
class describing the layout of an npv cube and aggregation scenario data
A cube implementation that stores the cube in memory.
Input Parameters.
data