Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
xvaanalytic.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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/analytic.hpp
20 \brief ORE Analytics Manager
21*/
22
23#pragma once
24
25#include <orea/app/analytic.hpp>
26
27namespace ore {
28namespace analytics {
29
31public:
32 static constexpr const char* LABEL = "XVA";
33
35 const QuantLib::ext::shared_ptr<InputParameters>& inputs,
36 const QuantLib::ext::shared_ptr<Scenario>& offsetScenario = nullptr,
37 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& offsetSimMarketParams = nullptr)
38 : Analytic::Impl(inputs), offsetScenario_(offsetScenario), offsetSimMarketParams_(offsetSimMarketParams) {
39 QL_REQUIRE(!((offsetScenario_ == nullptr) ^ (offsetSimMarketParams_ == nullptr)),
40 "Need offsetScenario and corresponding simMarketParameter");
42 }
43 virtual void runAnalytic(const QuantLib::ext::shared_ptr<ore::data::InMemoryLoader>& loader,
44 const std::set<std::string>& runTypes = {}) override;
45 void setUpConfigurations() override;
46
47 void checkConfigurations(const QuantLib::ext::shared_ptr<Portfolio>& portfolio);
48
49protected:
50 QuantLib::ext::shared_ptr<ore::data::EngineFactory> engineFactory() override;
52 void buildCrossAssetModel(bool continueOnError);
53 void buildScenarioGenerator(bool continueOnError);
54
55 void initCubeDepth();
56 void initCube(QuantLib::ext::shared_ptr<NPVCube>& cube, const std::set<std::string>& ids, Size cubeDepth);
57
58 void initClassicRun(const QuantLib::ext::shared_ptr<Portfolio>& portfolio);
59 void buildClassicCube(const QuantLib::ext::shared_ptr<Portfolio>& portfolio);
60 QuantLib::ext::shared_ptr<Portfolio> classicRun(const QuantLib::ext::shared_ptr<Portfolio>& portfolio);
61
62 QuantLib::ext::shared_ptr<EngineFactory>
63 amcEngineFactory(const QuantLib::ext::shared_ptr<QuantExt::CrossAssetModel>& cam, const std::vector<Date>& grid);
64 void buildAmcPortfolio();
65 void amcRun(bool doClassicRun);
66
67 void runPostProcessor();
68
69 Matrix creditStateCorrelationMatrix() const;
70
71 QuantLib::ext::shared_ptr<ScenarioSimMarket> simMarket_;
72 QuantLib::ext::shared_ptr<ScenarioSimMarket> simMarketCalibration_;
73 QuantLib::ext::shared_ptr<ScenarioSimMarket> offsetSimMarket_;
74 QuantLib::ext::shared_ptr<EngineFactory> engineFactory_;
75 QuantLib::ext::shared_ptr<CrossAssetModel> model_;
76 QuantLib::ext::shared_ptr<ScenarioGenerator> scenarioGenerator_;
77 QuantLib::ext::shared_ptr<Portfolio> amcPortfolio_, classicPortfolio_;
78 QuantLib::ext::shared_ptr<NPVCube> cube_, nettingSetCube_, cptyCube_, amcCube_;
79 QuantLib::RelinkableHandle<AggregationScenarioData> scenarioData_;
80 QuantLib::ext::shared_ptr<CubeInterpretation> cubeInterpreter_;
81 QuantLib::ext::shared_ptr<DynamicInitialMarginCalculator> dimCalculator_;
82 QuantLib::ext::shared_ptr<PostProcess> postProcess_;
83 QuantLib::ext::shared_ptr<Scenario> offsetScenario_;
84 QuantLib::ext::shared_ptr<ScenarioSimMarketParameters> offsetSimMarketParams_;
85 Size cubeDepth_ = 0;
86 QuantLib::ext::shared_ptr<DateGrid> grid_;
87 Size samples_ = 0;
88
89 bool runSimulation_ = false;
90 bool runXva_ = false;
91};
92
93static const std::set<std::string> xvaAnalyticSubAnalytics{"XVA", "EXPOSURE"};
94
95class XvaAnalytic : public Analytic {
96public:
97 explicit XvaAnalytic(const QuantLib::ext::shared_ptr<InputParameters>& inputs,
98 const QuantLib::ext::shared_ptr<Scenario>& offSetScenario = nullptr,
99 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& offsetSimMarketParams = nullptr)
100 : Analytic(std::make_unique<XvaAnalyticImpl>(inputs, offSetScenario, offsetSimMarketParams),
101 xvaAnalyticSubAnalytics, inputs, false, false, false, false) {}
102};
103
104} // namespace analytics
105} // namespace ore
ORE Analytics Manager.
void setLabel(const string &label)
Definition: analytic.hpp:189
const QuantLib::ext::shared_ptr< InputParameters > & inputs() const
Definition: analytic.hpp:116
XvaAnalytic(const QuantLib::ext::shared_ptr< InputParameters > &inputs, const QuantLib::ext::shared_ptr< Scenario > &offSetScenario=nullptr, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &offsetSimMarketParams=nullptr)
Definition: xvaanalytic.hpp:97
void setUpConfigurations() override
Definition: xvaanalytic.cpp:49
void buildClassicCube(const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarketCalibration_
Definition: xvaanalytic.hpp:72
QuantLib::ext::shared_ptr< NPVCube > amcCube_
Definition: xvaanalytic.hpp:78
QuantLib::ext::shared_ptr< CubeInterpretation > cubeInterpreter_
Definition: xvaanalytic.hpp:80
virtual void runAnalytic(const QuantLib::ext::shared_ptr< ore::data::InMemoryLoader > &loader, const std::set< std::string > &runTypes={}) override
void amcRun(bool doClassicRun)
QuantLib::ext::shared_ptr< ScenarioSimMarket > simMarket_
Definition: xvaanalytic.hpp:71
QuantLib::ext::shared_ptr< ScenarioGenerator > scenarioGenerator_
Definition: xvaanalytic.hpp:76
QuantLib::RelinkableHandle< AggregationScenarioData > scenarioData_
Definition: xvaanalytic.hpp:79
QuantLib::ext::shared_ptr< EngineFactory > engineFactory_
Definition: xvaanalytic.hpp:74
QuantLib::ext::shared_ptr< DateGrid > grid_
Definition: xvaanalytic.hpp:86
QuantLib::ext::shared_ptr< CrossAssetModel > model_
Definition: xvaanalytic.hpp:75
QuantLib::ext::shared_ptr< Portfolio > amcPortfolio_
Definition: xvaanalytic.hpp:77
QuantLib::ext::shared_ptr< EngineFactory > amcEngineFactory(const QuantLib::ext::shared_ptr< QuantExt::CrossAssetModel > &cam, const std::vector< Date > &grid)
void checkConfigurations(const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
Definition: xvaanalytic.cpp:57
XvaAnalyticImpl(const QuantLib::ext::shared_ptr< InputParameters > &inputs, const QuantLib::ext::shared_ptr< Scenario > &offsetScenario=nullptr, const QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > &offsetSimMarketParams=nullptr)
Definition: xvaanalytic.hpp:34
QuantLib::ext::shared_ptr< DynamicInitialMarginCalculator > dimCalculator_
Definition: xvaanalytic.hpp:81
void initClassicRun(const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
QuantLib::ext::shared_ptr< Scenario > offsetScenario_
Definition: xvaanalytic.hpp:83
QuantLib::ext::shared_ptr< ScenarioSimMarketParameters > offsetSimMarketParams_
Definition: xvaanalytic.hpp:84
void buildScenarioGenerator(bool continueOnError)
void buildCrossAssetModel(bool continueOnError)
QuantLib::ext::shared_ptr< NPVCube > cptyCube_
Definition: xvaanalytic.hpp:78
QuantLib::ext::shared_ptr< ore::data::EngineFactory > engineFactory() override
build an engine factory
Definition: xvaanalytic.cpp:92
void initCube(QuantLib::ext::shared_ptr< NPVCube > &cube, const std::set< std::string > &ids, Size cubeDepth)
QuantLib::ext::shared_ptr< Portfolio > classicRun(const QuantLib::ext::shared_ptr< Portfolio > &portfolio)
QuantLib::ext::shared_ptr< PostProcess > postProcess_
Definition: xvaanalytic.hpp:82
QuantLib::ext::shared_ptr< Portfolio > classicPortfolio_
Definition: xvaanalytic.hpp:77
static constexpr const char * LABEL
Definition: xvaanalytic.hpp:32
Matrix creditStateCorrelationMatrix() const
QuantLib::ext::shared_ptr< NPVCube > cube_
Definition: xvaanalytic.hpp:78
QuantLib::ext::shared_ptr< ScenarioSimMarket > offsetSimMarket_
Definition: xvaanalytic.hpp:73
QuantLib::ext::shared_ptr< NPVCube > nettingSetCube_
Definition: xvaanalytic.hpp:78