Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
parsensitivityinstrumentbuilder.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 orea/engine/parsensitivityanalysis.hpp
20 \brief Perfrom sensitivity analysis for a given portfolio
21 \ingroup simulation
22*/
23
24#pragma once
25
26#include <map>
32#include <set>
33
34namespace ore {
35namespace analytics {
36
38public:
39 struct Instruments {
40 //! par helpers (all except cap/floors)
41 std::map<ore::analytics::RiskFactorKey, QuantLib::ext::shared_ptr<QuantLib::Instrument>> parHelpers_;
42 //! par helpers: IR cap / floors
43 std::map<ore::analytics::RiskFactorKey, QuantLib::ext::shared_ptr<QuantLib::CapFloor>> parCaps_;
44 std::map<ore::analytics::RiskFactorKey, QuantLib::Handle<QuantLib::YieldTermStructure>> parCapsYts_;
45 std::map<ore::analytics::RiskFactorKey, QuantLib::Handle<QuantLib::OptionletVolatilityStructure>> parCapsVts_;
46 //! par helpers: YoY cap / floors
47 std::map<ore::analytics::RiskFactorKey, QuantLib::Handle<QuantLib::YieldTermStructure>> parYoYCapsYts_;
48 std::map<ore::analytics::RiskFactorKey, QuantLib::Handle<QuantLib::YoYInflationIndex>> parYoYCapsIndex_;
49 std::map<ore::analytics::RiskFactorKey, QuantLib::ext::shared_ptr<QuantLib::YoYInflationCapFloor>> parYoYCaps_;
50 std::map<ore::analytics::RiskFactorKey, QuantLib::Handle<QuantExt::YoYOptionletVolatilitySurface>> parYoYCapsVts_;
51 //! par QuantLib::Instrument pillars
52 std::map<std::string, std::vector<QuantLib::Period>> yieldCurvePillars_, capFloorPillars_, cdsPillars_,
54 //! list of (raw) risk factors on which a par helper depends
55 std::map<ore::analytics::RiskFactorKey, std::set<ore::analytics::RiskFactorKey>> parHelperDependencies_;
56 // ql index names for which we want to remove today's fixing for the purpose of the par sensi calculation
57 std::set<std::string> removeTodaysFixingIndices_;
58 };
59
61
62 //! Create par QuantLib::Instruments
63 void
65 const QuantLib::ext::shared_ptr<ore::analytics::ScenarioSimMarketParameters>& simMarketParams,
66 const ore::analytics::SensitivityScenarioData& sensitivityData,
67 const std::set<ore::analytics::RiskFactorKey::KeyType>& typesDisabled = {},
68 const std::set<ore::analytics::RiskFactorKey::KeyType>& parTypes = {},
69 const std::set<ore::analytics::RiskFactorKey>& relevantRiskFactors = {},
70 const bool continueOnError = false,
71 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration,
72 const QuantLib::ext::shared_ptr<ore::analytics::Market>& simMarket = nullptr) const;
73
74private:
75 //! Create Deposit for implying par rate sensitivity from zero rate sensitivity
76 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
77 makeDeposit(const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy,
78 std::string indexName, std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term,
79 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions,
80 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
81
82 //! Create FRA for implying par rate sensitivity from zero rate sensitivity
83 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
84 makeFRA(const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy,
85 std::string indexName, std::string yieldCurveName, std::string equityForecastCurveName,
86 QuantLib::Period term, const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions,
87 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
88
89 //! Create Swap for implying par rate sensitivity from zero rate sensitivity
90 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
91 makeSwap(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy, std::string indexName,
92 std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term,
93 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions, bool singleCurve,
94 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
95 std::set<std::string>& removeTodaysFixingIndices, const std::string& expDiscountCurve = "",
96 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
97
98 //! Create OIS Swap for implying par rate sensitivity from zero rate sensitivity
99 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
100 makeOIS(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy, std::string indexName,
101 std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term,
102 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions, bool singleCurve,
103 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
104 std::set<std::string>& removeTodaysFixingIndices, const std::string& expDiscountCurve = "",
105 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
106
107 //! Create Basis Swap for implying par rate sensitivity from zero rate sensitivity
108 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
109 makeTenorBasisSwap(const QuantLib::Date& asof, const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy,
110 std::string receiveIndexName, std::string payIndexName, std::string yieldCurveName,
111 std::string equityForecastCurveName, QuantLib::Period term, const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions,
112 const bool singleCurve, std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
113 std::set<std::string>& removeTodaysFixingIndices, const std::string& expDiscountCurve = "",
114 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
115
116 //! Create Cap/Floor QuantLib::Instrument for implying flat vol sensitivity from optionlet vol sensitivity
117 QuantLib::ext::shared_ptr<QuantLib::CapFloor> makeCapFloor(
118 const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string ccy, std::string indexName, QuantLib::Period term, double strike,
119 bool generatePillar, // isAtm ?
120 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies, const std::string& expDiscountCurve = "",
121 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
122
123 //! Create Cross Ccy Basis Swap for implying par rate sensitivity from zero rate sensitivity
124 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
125 makeCrossCcyBasisSwap(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string baseCcy, std::string ccy, QuantLib::Period term,
126 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions,
127 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
128 std::set<std::string>& removeTodaysFixingIndices,
129 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
130
131 //! Create FX Forwrad for implying par rate sensitivity from zero rate sensitivity
132 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
133 makeFxForward(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string baseCcy, std::string ccy, QuantLib::Period term,
134 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions,
135 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
136 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
137
138 //! Create CDS for implying par rate sensitivity from Hazard Rate sensitivity
139 std::pair<QuantLib::ext::shared_ptr<QuantLib::Instrument>, Date>
140 makeCDS(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string name, std::string ccy, QuantLib::Period term,
141 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions,
142 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies, const std::string& expDiscountCurve = "",
143 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
144
145 //! Create Zero Swap for implying par rate sensitivity from zero rate sensitivity
146 QuantLib::ext::shared_ptr<QuantLib::Instrument>
147 makeZeroInflationSwap(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string indexName, QuantLib::Period term,
148 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions, bool singleCurve,
149 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
150 const std::string& expDiscountCurve = "",
151 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
152
153 //! Create YoY Swap for implying par rate sensitivity from yoy rate sensitivity
154 QuantLib::ext::shared_ptr<QuantLib::Instrument>
155 makeYoyInflationSwap(const QuantLib::ext::shared_ptr<ore::data::Market>& market, std::string indexName, QuantLib::Period term,
156 const QuantLib::ext::shared_ptr<ore::data::Convention>& conventions, bool singleCurve, bool fromZero,
157 std::set<ore::analytics::RiskFactorKey>& parHelperDependencies,
158 const std::string& expDiscountCurve = "",
159 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
160
161 //! Create YoY Cap/Floor for implying rate rate sensitivity from yoy optionlet vol sensitivity
162 void makeYoYCapFloor(ParSensitivityInstrumentBuilder::Instruments& instruments,
163 const QuantLib::ext::shared_ptr<Market>& market, std::string indexName, QuantLib::Period term,
164 double strike, const QuantLib::ext::shared_ptr<ore::data::Convention>& convention, bool singleCurve,
165 bool fromZero, const std::string& expDiscountCurve, const ore::analytics::RiskFactorKey& key,
166 const std::string& marketConfiguration = ore::data::Market::defaultConfiguration) const;
167};
168
169} // namespace analytics
170} // namespace ore
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeSwap(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string ccy, std::string indexName, std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, bool singleCurve, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, std::set< std::string > &removeTodaysFixingIndices, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create Swap for implying par rate sensitivity from zero rate sensitivity.
QuantLib::ext::shared_ptr< QuantLib::CapFloor > makeCapFloor(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string ccy, std::string indexName, QuantLib::Period term, double strike, bool generatePillar, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create Cap/Floor QuantLib::Instrument for implying flat vol sensitivity from optionlet vol sensitivit...
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeTenorBasisSwap(const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string ccy, std::string receiveIndexName, std::string payIndexName, std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, const bool singleCurve, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, std::set< std::string > &removeTodaysFixingIndices, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create Basis Swap for implying par rate sensitivity from zero rate sensitivity.
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeCrossCcyBasisSwap(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string baseCcy, std::string ccy, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, std::set< std::string > &removeTodaysFixingIndices, const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create Cross Ccy Basis Swap for implying par rate sensitivity from zero rate sensitivity.
void createParInstruments(ParSensitivityInstrumentBuilder::Instruments &instruments, const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< ore::analytics::ScenarioSimMarketParameters > &simMarketParams, const ore::analytics::SensitivityScenarioData &sensitivityData, const std::set< ore::analytics::RiskFactorKey::KeyType > &typesDisabled={}, const std::set< ore::analytics::RiskFactorKey::KeyType > &parTypes={}, const std::set< ore::analytics::RiskFactorKey > &relevantRiskFactors={}, const bool continueOnError=false, const std::string &marketConfiguration=ore::data::Market::defaultConfiguration, const QuantLib::ext::shared_ptr< ore::analytics::Market > &simMarket=nullptr) const
Create par QuantLib::Instruments.
void makeYoYCapFloor(ParSensitivityInstrumentBuilder::Instruments &instruments, const QuantLib::ext::shared_ptr< Market > &market, std::string indexName, QuantLib::Period term, double strike, const QuantLib::ext::shared_ptr< ore::data::Convention > &convention, bool singleCurve, bool fromZero, const std::string &expDiscountCurve, const ore::analytics::RiskFactorKey &key, const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create YoY Cap/Floor for implying rate rate sensitivity from yoy optionlet vol sensitivity.
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeDeposit(const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string ccy, std::string indexName, std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create Deposit for implying par rate sensitivity from zero rate sensitivity.
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeFRA(const QuantLib::Date &asof, const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string ccy, std::string indexName, std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create FRA for implying par rate sensitivity from zero rate sensitivity.
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeOIS(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string ccy, std::string indexName, std::string yieldCurveName, std::string equityForecastCurveName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, bool singleCurve, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, std::set< std::string > &removeTodaysFixingIndices, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create OIS Swap for implying par rate sensitivity from zero rate sensitivity.
QuantLib::ext::shared_ptr< QuantLib::Instrument > makeYoyInflationSwap(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string indexName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, bool singleCurve, bool fromZero, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create YoY Swap for implying par rate sensitivity from yoy rate sensitivity.
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeFxForward(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string baseCcy, std::string ccy, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create FX Forwrad for implying par rate sensitivity from zero rate sensitivity.
std::pair< QuantLib::ext::shared_ptr< QuantLib::Instrument >, Date > makeCDS(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string name, std::string ccy, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create CDS for implying par rate sensitivity from Hazard Rate sensitivity.
QuantLib::ext::shared_ptr< QuantLib::Instrument > makeZeroInflationSwap(const QuantLib::ext::shared_ptr< ore::data::Market > &market, std::string indexName, QuantLib::Period term, const QuantLib::ext::shared_ptr< ore::data::Convention > &conventions, bool singleCurve, std::set< ore::analytics::RiskFactorKey > &parHelperDependencies, const std::string &expDiscountCurve="", const std::string &marketConfiguration=ore::data::Market::defaultConfiguration) const
Create Zero Swap for implying par rate sensitivity from zero rate sensitivity.
Data types stored in the scenario class.
Definition: scenario.hpp:48
Description of sensitivity shift scenarios.
static const string defaultConfiguration
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.
std::map< ore::analytics::RiskFactorKey, QuantLib::Handle< QuantExt::YoYOptionletVolatilitySurface > > parYoYCapsVts_
std::map< std::string, std::vector< QuantLib::Period > > zeroInflationPillars_
std::map< ore::analytics::RiskFactorKey, QuantLib::Handle< QuantLib::YieldTermStructure > > parYoYCapsYts_
par helpers: YoY cap / floors
std::map< ore::analytics::RiskFactorKey, QuantLib::ext::shared_ptr< QuantLib::Instrument > > parHelpers_
par helpers (all except cap/floors)
std::map< ore::analytics::RiskFactorKey, std::set< ore::analytics::RiskFactorKey > > parHelperDependencies_
list of (raw) risk factors on which a par helper depends
std::map< std::string, std::vector< QuantLib::Period > > yieldCurvePillars_
par QuantLib::Instrument pillars
std::map< std::string, std::vector< QuantLib::Period > > equityForecastCurvePillars_
std::map< ore::analytics::RiskFactorKey, QuantLib::Handle< QuantLib::YieldTermStructure > > parCapsYts_
std::map< ore::analytics::RiskFactorKey, QuantLib::ext::shared_ptr< QuantLib::CapFloor > > parCaps_
par helpers: IR cap / floors
std::map< ore::analytics::RiskFactorKey, QuantLib::Handle< QuantLib::OptionletVolatilityStructure > > parCapsVts_
std::map< ore::analytics::RiskFactorKey, QuantLib::ext::shared_ptr< QuantLib::YoYInflationCapFloor > > parYoYCaps_
std::map< ore::analytics::RiskFactorKey, QuantLib::Handle< QuantLib::YoYInflationIndex > > parYoYCapsIndex_
std::map< std::string, std::vector< QuantLib::Period > > yoyCapFloorPillars_
std::map< std::string, std::vector< QuantLib::Period > > capFloorPillars_
std::map< std::string, std::vector< QuantLib::Period > > cdsPillars_
std::map< std::string, std::vector< QuantLib::Period > > yoyInflationPillars_
Date asof(14, Jun, 2018)