Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
xvarunner.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/app/xvarunner.hpp
20 \brief A class to run the xva analysis
21 \ingroup app
22*/
23#pragma once
24
33
34#include <boost/optional.hpp>
35
36namespace ore {
37namespace analytics {
38
39class XvaRunner {
40public:
41 virtual ~XvaRunner() {}
42
43 XvaRunner(const QuantLib::ext::shared_ptr<InputParameters>& inputs,
44 QuantLib::Date asof, const std::string& baseCurrency,
45 const QuantLib::ext::shared_ptr<ore::data::Portfolio>& portfolio,
46 const QuantLib::ext::shared_ptr<ore::data::NettingSetManager>& netting,
47 const QuantLib::ext::shared_ptr<ore::data::CollateralBalances>& collateralBalances,
48 const QuantLib::ext::shared_ptr<ore::data::EngineData>& engineData,
49 const QuantLib::ext::shared_ptr<ore::data::CurveConfigurations>& curveConfigs,
50 const QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters>& todaysMarketParams,
51 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& simMarketData,
52 const QuantLib::ext::shared_ptr<ScenarioGeneratorData>& scenarioGeneratorData,
53 const QuantLib::ext::shared_ptr<ore::data::CrossAssetModelData>& crossAssetModelData,
54 const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceData = nullptr,
55 const IborFallbackConfig& iborFallbackConfig = IborFallbackConfig::defaultConfig(),
56 QuantLib::Real dimQuantile = 0.99, QuantLib::Size dimHorizonCalendarDays = 14,
57 map<string, bool> analytics = {}, string calculationType = "Symmetric", string dvaName = "",
58 string fvaBorrowingCurve = "", string fvaLendingCurve = "", bool fullInitialCollateralisation = true,
59 bool storeFlows = false);
60
61 // run xva on full portfolio and build post processor
62 void runXva(const QuantLib::ext::shared_ptr<ore::data::Market>& market, bool continueOnErr = true,
63 const std::map<std::string, QuantLib::Real>& currentIM = std::map<std::string, QuantLib::Real>());
64
65 // get post processor, this requires a previous runXva() or generatePostProcessor() call
66 const QuantLib::ext::shared_ptr<PostProcess>& postProcess() { return postProcess_; }
67
68 // step 1: build cam model
69 void buildCamModel(const QuantLib::ext::shared_ptr<ore::data::Market>& market, bool continueOnErr = true);
70
71 // optional step 2: buffer simulation paths, this is required, if a currency filter is used
73
74 // build sim market, optionally on filtered currencies
75 virtual void buildSimMarket(const QuantLib::ext::shared_ptr<ore::data::Market>& market,
76 const boost::optional<std::set<std::string>>& currencyFilter = boost::none,
77 const bool continueOnErr = true);
78
79 // step 5: build npv, netting cube (optionally filtered on trades) and generate scenario data
80 void buildCube(const boost::optional<std::set<std::string>>& tradeIds, bool continueOnErr = true);
81
82 // get generated trade cube from step 5
83 QuantLib::ext::shared_ptr<NPVCube> npvCube() const { return cube_; }
84
85 // get generated netting set cube from step 5
86 QuantLib::ext::shared_ptr<NPVCube> nettingCube() const { return nettingCube_; }
87
88 // get aggregation scenario data from step 5
89 QuantLib::Handle<AggregationScenarioData> aggregationScenarioData() { return scenarioData_; }
90
91 // partial step 3: build post processor on given cubes / agg scen data (requires runXva() or buildCamModel() call)
93 const QuantLib::ext::shared_ptr<Market>& market, const QuantLib::ext::shared_ptr<NPVCube>& npvCube,
94 const QuantLib::ext::shared_ptr<NPVCube>& nettingCube, const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
95 const bool continueOnErr = true,
96 const std::map<std::string, QuantLib::Real>& currentIM = std::map<std::string, QuantLib::Real>());
97
98 // get a vector of netting set ids for the given portfolio sorted in alphabetical order, if no portfolio
99 // is given here, the netting sets for the global portfolio set in the ctor are returned
100 std::set<std::string> getNettingSetIds(const QuantLib::ext::shared_ptr<Portfolio>& portfolio = nullptr) const;
101
102protected:
103 virtual QuantLib::ext::shared_ptr<NPVCube>
104 getNettingSetCube(std::vector<QuantLib::ext::shared_ptr<ValuationCalculator>>& calculators,
105 const QuantLib::ext::shared_ptr<Portfolio>& portfolio) {
106 return nullptr;
107 };
108
109 virtual QuantLib::ext::shared_ptr<NPVCube> getNpvCube(const Date& asof, const std::set<std::string>& ids,
110 const std::vector<Date>& dates, const Size samples,
111 const Size depth) const;
112
113 virtual QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator>
114 getDimCalculator(const QuantLib::ext::shared_ptr<NPVCube>& cube,
115 const QuantLib::ext::shared_ptr<CubeInterpretation>& cubeInterpreter,
116 const QuantLib::ext::shared_ptr<AggregationScenarioData>& scenarioData,
117 const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel>& model = nullptr,
118 const QuantLib::ext::shared_ptr<NPVCube>& nettingCube = nullptr,
119 const std::map<std::string, QuantLib::Real>& currentIM = std::map<std::string, QuantLib::Real>());
120
121 virtual QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters>
122 projectSsmData(const std::set<std::string>& currencyFilter) const;
123
124 virtual QuantLib::ext::shared_ptr<ore::analytics::ScenarioGenerator> getProjectedScenarioGenerator(
125 const boost::optional<std::set<std::string>>& currencyFilter, const QuantLib::ext::shared_ptr<Market>& market,
126 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& projectedSsmData,
127 const QuantLib::ext::shared_ptr<ScenarioFactory>& scenarioFactory, const bool continueOnErr) const;
128
129 QuantLib::ext::shared_ptr<InputParameters> inputs_;
130 QuantLib::Date asof_;
131 std::string baseCurrency_;
132 QuantLib::ext::shared_ptr<ore::data::Portfolio> portfolio_;
133 QuantLib::ext::shared_ptr<ore::data::NettingSetManager> netting_;
134 QuantLib::ext::shared_ptr<ore::data::CollateralBalances> collateralBalances_;
135 QuantLib::ext::shared_ptr<ore::data::EngineData> engineData_;
136 QuantLib::ext::shared_ptr<ore::data::CurveConfigurations> curveConfigs_;
137 QuantLib::ext::shared_ptr<ore::data::TodaysMarketParameters> todaysMarketParams_;
138 QuantLib::ext::shared_ptr<ScenarioSimMarketParameters> simMarketData_;
139 QuantLib::ext::shared_ptr<ScenarioGeneratorData> scenarioGeneratorData_;
140 QuantLib::ext::shared_ptr<ore::data::CrossAssetModelData> crossAssetModelData_;
141 QuantLib::ext::shared_ptr<ReferenceDataManager> referenceData_;
143 QuantLib::Real dimQuantile_;
145 map<string, bool> analytics_;
147 string dvaName_;
152
153 // generated data
154 QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel> model_;
155 QuantLib::ext::shared_ptr<ScenarioSimMarket> simMarket_;
156 QuantLib::ext::shared_ptr<EngineFactory> simFactory_;
157 QuantLib::RelinkableHandle<AggregationScenarioData> scenarioData_;
158 QuantLib::ext::shared_ptr<NPVCube> cube_, nettingCube_;
159 QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpreter_;
160 std::string calculationType_;
161 QuantLib::ext::shared_ptr<PostProcess> postProcess_;
162
163 QuantLib::ext::shared_ptr<std::vector<std::vector<QuantLib::Path>>> bufferedPaths_;
164};
165
166} // namespace analytics
167} // namespace ore
QuantLib::ext::shared_ptr< ore::data::CurveConfigurations > curveConfigs_
Definition: xvarunner.hpp:136
QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > model_
Definition: xvarunner.hpp:154
QuantLib::ext::shared_ptr< ore::data::TodaysMarketParameters > todaysMarketParams_
Definition: xvarunner.hpp:137
QuantLib::Size dimHorizonCalendarDays_
Definition: xvarunner.hpp:144
std::string calculationType_
Definition: xvarunner.hpp:160
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpreter_
Definition: xvarunner.hpp:159
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
Definition: xvarunner.hpp:155
QuantLib::ext::shared_ptr< std::vector< std::vector< QuantLib::Path > > > bufferedPaths_
Definition: xvarunner.hpp:163
QuantLib::RelinkableHandle< AggregationScenarioData > scenarioData_
Definition: xvarunner.hpp:157
void runXva(const QuantLib::ext::shared_ptr< ore::data::Market > &market, bool continueOnErr=true, const std::map< std::string, QuantLib::Real > &currentIM=std::map< std::string, QuantLib::Real >())
Definition: xvarunner.cpp:249
virtual QuantLib::ext::shared_ptr< NPVCube > getNpvCube(const Date &asof, const std::set< std::string > &ids, const std::vector< Date > &dates, const Size samples, const Size depth) const
Definition: xvarunner.cpp:287
void buildCamModel(const QuantLib::ext::shared_ptr< ore::data::Market > &market, bool continueOnErr=true)
Definition: xvarunner.cpp:82
const QuantLib::ext::shared_ptr< PostProcess > & postProcess()
Definition: xvarunner.hpp:66
QuantLib::ext::shared_ptr< NPVCube > npvCube() const
Definition: xvarunner.hpp:83
map< string, bool > analytics_
Definition: xvarunner.hpp:145
QuantLib::ext::shared_ptr< ore::data::Portfolio > portfolio_
Definition: xvarunner.hpp:132
QuantLib::ext::shared_ptr< ScenarioGeneratorData > scenarioGeneratorData_
Definition: xvarunner.hpp:139
std::set< std::string > getNettingSetIds(const QuantLib::ext::shared_ptr< Portfolio > &portfolio=nullptr) const
Definition: xvarunner.cpp:279
void generatePostProcessor(const QuantLib::ext::shared_ptr< Market > &market, const QuantLib::ext::shared_ptr< NPVCube > &npvCube, const QuantLib::ext::shared_ptr< NPVCube > &nettingCube, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData, const bool continueOnErr=true, const std::map< std::string, QuantLib::Real > &currentIM=std::map< std::string, QuantLib::Real >())
Definition: xvarunner.cpp:228
void buildCube(const boost::optional< std::set< std::string > > &tradeIds, bool continueOnErr=true)
Definition: xvarunner.cpp:156
QuantLib::Real dimQuantile_
Definition: xvarunner.hpp:143
QuantLib::Handle< AggregationScenarioData > aggregationScenarioData()
Definition: xvarunner.hpp:89
QuantLib::ext::shared_ptr< EngineFactory > simFactory_
Definition: xvarunner.hpp:156
virtual QuantLib::ext::shared_ptr< NPVCube > getNettingSetCube(std::vector< QuantLib::ext::shared_ptr< ValuationCalculator > > &calculators, const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
Definition: xvarunner.hpp:104
virtual void buildSimMarket(const QuantLib::ext::shared_ptr< ore::data::Market > &market, const boost::optional< std::set< std::string > > &currencyFilter=boost::none, const bool continueOnErr=true)
Definition: xvarunner.cpp:122
QuantLib::ext::shared_ptr< ore::data::CrossAssetModelData > crossAssetModelData_
Definition: xvarunner.hpp:140
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > simMarketData_
Definition: xvarunner.hpp:138
IborFallbackConfig iborFallbackConfig_
Definition: xvarunner.hpp:142
QuantLib::ext::shared_ptr< ReferenceDataManager > referenceData_
Definition: xvarunner.hpp:141
QuantLib::ext::shared_ptr< NPVCube > nettingCube() const
Definition: xvarunner.hpp:86
virtual QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > projectSsmData(const std::set< std::string > &currencyFilter) const
Definition: xvarunner.cpp:67
QuantLib::ext::shared_ptr< PostProcess > postProcess_
Definition: xvarunner.hpp:161
virtual QuantLib::ext::shared_ptr< ore::analytics::ScenarioGenerator > getProjectedScenarioGenerator(const boost::optional< std::set< std::string > > &currencyFilter, const QuantLib::ext::shared_ptr< Market > &market, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &projectedSsmData, const QuantLib::ext::shared_ptr< ScenarioFactory > &scenarioFactory, const bool continueOnErr) const
Definition: xvarunner.cpp:72
QuantLib::ext::shared_ptr< InputParameters > inputs_
Definition: xvarunner.hpp:129
QuantLib::ext::shared_ptr< ore::data::NettingSetManager > netting_
Definition: xvarunner.hpp:133
QuantLib::ext::shared_ptr< ore::data::CollateralBalances > collateralBalances_
Definition: xvarunner.hpp:134
QuantLib::ext::shared_ptr< NPVCube > cube_
Definition: xvarunner.hpp:158
virtual QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > getDimCalculator(const QuantLib::ext::shared_ptr< NPVCube > &cube, const QuantLib::ext::shared_ptr< CubeInterpretation > &cubeInterpreter, const QuantLib::ext::shared_ptr< AggregationScenarioData > &scenarioData, const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &model=nullptr, const QuantLib::ext::shared_ptr< NPVCube > &nettingCube=nullptr, const std::map< std::string, QuantLib::Real > &currentIM=std::map< std::string, QuantLib::Real >())
Definition: xvarunner.cpp:260
QuantLib::ext::shared_ptr< NPVCube > nettingCube_
Definition: xvarunner.hpp:158
QuantLib::ext::shared_ptr< ore::data::EngineData > engineData_
Definition: xvarunner.hpp:135
static IborFallbackConfig defaultConfig()
Input Parameters.
Exposure aggregation and XVA calculation.
Scenario generator configuration.
A class to hold Scenario parameters for scenarioSimMarket.
Date asof(14, Jun, 2018)
The counterparty cube calculator interface.
The cube valuation core.