Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
stresstest.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/stresstest.hpp
20 \brief perform a stress testing analysis for a given portfolio.
21 \ingroup simulation
22*/
23
24#pragma once
25
26#include <orea/cube/npvcube.hpp>
34
35#include <map>
36#include <set>
37#include <tuple>
38
39namespace ore {
40namespace analytics {
41
42//! Stress Test Analysis
43/*!
44 This class wraps functionality to perform a stress testing analysis for a given portfolio.
45 It comprises
46 - building the "simulation" market to which sensitivity scenarios are applied
47 - building the portfolio linked to this simulation market
48 - generating sensitivity scenarios
49 - running the scenario "engine" to apply these and compute the NPV impacts of all required shifts
50 - fill result structures that can be queried
51 - write stress test report to a file
52
53 \ingroup simulation
54*/
56public:
57 //! Constructor
58 StressTest(const QuantLib::ext::shared_ptr<ore::data::Portfolio>& portfolio,
59 const QuantLib::ext::shared_ptr<ore::data::Market>& market, const string& marketConfiguration,
60 const QuantLib::ext::shared_ptr<ore::data::EngineData>& engineData,
61 const QuantLib::ext::shared_ptr<ScenarioSimMarketParameters>& simMarketData,
62 const QuantLib::ext::shared_ptr<StressTestScenarioData>& stressData,
65 QuantLib::ext::shared_ptr<ScenarioFactory> scenarioFactory = {},
66 const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceData = nullptr,
67 const IborFallbackConfig& iborFallbackConfig = IborFallbackConfig::defaultConfig(),
68 bool continueOnError = false);
69
70 //! Return set of trades analysed
71 const std::set<std::string>& trades() { return trades_; }
72
73 //! Return unique set of factors shifted
74 const std::set<std::string>& stressTests() { return labels_; }
75
76 //! Return base NPV by trade, before shift
77 const std::map<std::string, Real>& baseNPV() { return baseNPV_; }
78
79 //! Return shifted NPVs by trade and scenario
80 const std::map<std::pair<std::string, std::string>, Real>& shiftedNPV() { return shiftedNPV_; }
81
82 //! Return delta NPV by trade and scenario
83 const std::map<std::pair<std::string, std::string>, Real>& delta() { return delta_; }
84
85 //! Write NPV by trade/scenario to a file (base and shifted NPVs, delta)
86 void writeReport(const QuantLib::ext::shared_ptr<ore::data::Report>& report, Real outputThreshold = 0.0);
87
88private:
89 // base NPV by trade
90 std::map<std::string, Real> baseNPV_;
91 // NPV respectively sensitivity by trade and scenario
92 std::map<std::pair<string, string>, Real> shiftedNPV_, delta_;
93 // scenario labels
94 std::set<std::string> labels_, trades_;
95};
96} // namespace analytics
97} // namespace ore
Stress Test Analysis.
Definition: stresstest.hpp:55
const std::map< std::pair< std::string, std::string >, Real > & shiftedNPV()
Return shifted NPVs by trade and scenario.
Definition: stresstest.hpp:80
std::map< std::pair< string, string >, Real > delta_
Definition: stresstest.hpp:92
void writeReport(const QuantLib::ext::shared_ptr< ore::data::Report > &report, Real outputThreshold=0.0)
Write NPV by trade/scenario to a file (base and shifted NPVs, delta)
Definition: stresstest.cpp:118
const std::map< std::pair< std::string, std::string >, Real > & delta()
Return delta NPV by trade and scenario.
Definition: stresstest.hpp:83
std::map< std::pair< string, string >, Real > shiftedNPV_
Definition: stresstest.hpp:92
std::set< std::string > labels_
Definition: stresstest.hpp:94
const std::set< std::string > & stressTests()
Return unique set of factors shifted.
Definition: stresstest.hpp:74
const std::map< std::string, Real > & baseNPV()
Return base NPV by trade, before shift.
Definition: stresstest.hpp:77
std::map< std::string, Real > baseNPV_
Definition: stresstest.hpp:90
const std::set< std::string > & trades()
Return set of trades analysed.
Definition: stresstest.hpp:71
std::set< std::string > trades_
Definition: stresstest.hpp:94
static IborFallbackConfig defaultConfig()
The base NPV cube class.
A Market class that can be updated by Scenarios.
A class to hold Scenario parameters for scenarioSimMarket.
A class to hold the parametrisation for building sensitivity scenarios.
Stress scenario generation.
vector< string > curveConfigs