Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetmodeldata.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 ored/model/crossassetmodeldata.hpp
20 \brief Cross asset model data
21 \ingroup models
22*/
23
24#pragma once
25
26#include <vector>
27
28#include <ql/time/daycounters/actualactual.hpp>
29#include <ql/types.hpp>
30
32
44
45namespace ore {
46namespace data {
47using namespace QuantLib;
49using std::map;
50using std::pair;
51using std::string;
52using std::vector;
53
54//! InstantaneousCorrelations
55/*! InstantaneousCorrelations is a class to store the correlations required by
56 the CrossAssetModelData class
57 \ingroup models
58*/
60public:
61 //! \name Constructors
62 //@{
63 //! Default constructor
65
66 //! Detailed constructor
67 InstantaneousCorrelations(const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& correlations)
69 //@}
70
71 //! \name Serialisation
72 //@{
73 //! Populate members from XML
74 virtual void fromXML(XMLNode* node) override;
75 //! Write class members to XML
76 virtual XMLNode* toXML(XMLDocument& doc) const override;
77 //@}
78
79 //! \name Getters
80 //@{
81 //!
82 const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& correlations() const { return correlations_; }
83 //@}
84
85 //! Clear all vectors and maps
86 void clear() { correlations_.clear(); }
87
88 //! \name Setters
89 //@{
90 //!
91 void correlations(const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& corrs) {
92 correlations_ = corrs;
93 }
94 //@}
95
96 //! \name Operators
97 //@{
100 //@}
101
102private:
103 std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>> correlations_;
104};
105
106//! Cross Asset Model Parameters
107/*! CrossAssetModelData comprises the specification of how to build and calibrate
108 the CrossAssetModel. It contains
109 - specifications for each currency IR component (IrLgmData)
110 - specifications for each FX component (FxBsData)
111 - the correlation specification between all factors of the model
112 - a tolerance for bootstrap type calibration methods
113 \ingroup models
114 */
116public:
117 //! \name Constructors
118 //@{
119 //! Default constructor
121 correlations_ = QuantLib::ext::make_shared<InstantaneousCorrelations>();
122 }
123
124 //! Detailed constructor (IR/FX only)
125 CrossAssetModelData( //! Vector of IR model specifications
126 const vector<QuantLib::ext::shared_ptr<IrModelData>>& irConfigs,
127 //! Vector of FX model specifications
128 const vector<QuantLib::ext::shared_ptr<FxBsData>>& fxConfigs,
129 //! Correlation map
130 const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& c,
131 //! Bootstrap tolerance used in model calibration
132 Real tolerance = 1e-4,
133 //! Choice of probability measure
134 const std::string& measure = "LGM",
135 //! Choice of discretization
136 const CrossAssetModel::Discretization discretization = CrossAssetModel::Discretization::Exact)
137 : irConfigs_(irConfigs), fxConfigs_(fxConfigs), eqConfigs_(std::vector<QuantLib::ext::shared_ptr<EqBsData>>()),
139 correlations_ = QuantLib::ext::make_shared<InstantaneousCorrelations>(c);
140 domesticCurrency_ = irConfigs_[0]->ccy();
141 currencies_.clear();
142 for (Size i = 0; i < irConfigs_.size(); ++i)
143 currencies_.push_back(irConfigs_[i]->ccy());
144 validate();
145 }
146
147 //! Detailed constructor (IR/FX/EQ only)
148 CrossAssetModelData( //! Vector of IR model specifications
149 const std::vector<QuantLib::ext::shared_ptr<IrModelData>>& irConfigs,
150 //! Vector of FX model specifications
151 const std::vector<QuantLib::ext::shared_ptr<FxBsData>>& fxConfigs,
152 //! Vector of EQ model specifications
153 const std::vector<QuantLib::ext::shared_ptr<EqBsData>>& eqConfigs,
154 //! Correlation map
155 const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& c,
156 //! Bootstrap tolerance used in model calibration
157 Real tolerance = 1e-4,
158 //! Choice of probability measure
159 const std::string& measure = "LGM",
160 //! Choice of discretization
161 const CrossAssetModel::Discretization discretization = CrossAssetModel::Discretization::Exact)
164 correlations_ = QuantLib::ext::make_shared<InstantaneousCorrelations>(c);
165 domesticCurrency_ = irConfigs_[0]->ccy();
166 currencies_.clear();
167 for (Size i = 0; i < irConfigs_.size(); ++i)
168 currencies_.push_back(irConfigs_[i]->ccy());
169 validate();
170 }
171
172 //! Detailed constructor (all asset classes)
173 CrossAssetModelData( //! Vector of IR model specifications
174 const std::vector<QuantLib::ext::shared_ptr<IrModelData>>& irConfigs,
175 //! Vector of FX model specifications
176 const std::vector<QuantLib::ext::shared_ptr<FxBsData>>& fxConfigs,
177 //! Vector of EQ model specifications
178 const std::vector<QuantLib::ext::shared_ptr<EqBsData>>& eqConfigs,
179 //! Vector of INF model specifications
180 const std::vector<QuantLib::ext::shared_ptr<InflationModelData>>& infConfigs,
181 //! Vector of CR LGM model specifications
182 const std::vector<QuantLib::ext::shared_ptr<CrLgmData>>& crLgmConfigs,
183 //! Vector of CR CIR model specifications
184 const std::vector<QuantLib::ext::shared_ptr<CrCirData>>& crCirConfigs,
185 //! Vector of COM Schwartz model specifications
186 const std::vector<QuantLib::ext::shared_ptr<CommoditySchwartzData>>& comConfigs,
187 //! Number of credit states
188 const Size numberOfCreditStates,
189 //! Correlation map
190 const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& c,
191 //! Bootstrap tolerance used in model calibration
192 Real tolerance = 1e-4,
193 //! Choice of probability measure
194 const std::string& measure = "LGM",
195 //! Choice of discretization
196 const CrossAssetModel::Discretization discretization = CrossAssetModel::Discretization::Exact)
201 correlations_ = QuantLib::ext::make_shared<InstantaneousCorrelations>(c);
202 domesticCurrency_ = irConfigs_[0]->ccy();
203 currencies_.clear();
204 for (Size i = 0; i < irConfigs_.size(); ++i)
205 currencies_.push_back(irConfigs_[i]->ccy());
206 validate();
207 }
208 //@}
209
210 //! Clear all vectors and maps
211 void clear();
212
213 //! Check consistency of config vectors
214 void validate();
215
216 //! \name Inspectors
217 //@{
218 const string& domesticCurrency() const { return domesticCurrency_; }
219 const vector<string>& currencies() const { return currencies_; }
220 const vector<string>& equities() const { return equities_; }
221 const vector<string>& infIndices() const { return infindices_; }
222 const vector<string>& creditNames() const { return creditNames_; }
223 const vector<string>& commodities() const { return commodities_; }
224 const vector<QuantLib::ext::shared_ptr<IrModelData>>& irConfigs() const { return irConfigs_; }
225 const vector<QuantLib::ext::shared_ptr<FxBsData>>& fxConfigs() const { return fxConfigs_; }
226 const vector<QuantLib::ext::shared_ptr<EqBsData>>& eqConfigs() const { return eqConfigs_; }
227 const vector<QuantLib::ext::shared_ptr<InflationModelData>>& infConfigs() const { return infConfigs_; }
228 const vector<QuantLib::ext::shared_ptr<CrLgmData>>& crLgmConfigs() const { return crLgmConfigs_; }
229 const vector<QuantLib::ext::shared_ptr<CrCirData>>& crCirConfigs() const { return crCirConfigs_; }
230 const vector<QuantLib::ext::shared_ptr<CommoditySchwartzData>>& comConfigs() const { return comConfigs_; }
232 const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& correlations() const {
233 return correlations_->correlations();
234 }
236 const std::string& measure() const { return measure_; }
238 //@}
239
240 //! \name Setters
241 //@{
243 vector<string>& currencies() { return currencies_; }
244 vector<string>& equities() { return equities_; }
245 vector<string>& infIndices() { return infindices_; }
246 vector<string>& creditNames() { return creditNames_; }
247 vector<string>& commodities() { return commodities_; }
248 vector<QuantLib::ext::shared_ptr<IrModelData>>& irConfigs() { return irConfigs_; }
249 vector<QuantLib::ext::shared_ptr<FxBsData>>& fxConfigs() { return fxConfigs_; }
250 vector<QuantLib::ext::shared_ptr<EqBsData>>& eqConfigs() { return eqConfigs_; }
251 vector<QuantLib::ext::shared_ptr<InflationModelData>>& infConfigs() { return infConfigs_; }
252 vector<QuantLib::ext::shared_ptr<CrLgmData>>& crLgmConfigs() { return crLgmConfigs_; }
253 vector<QuantLib::ext::shared_ptr<CrCirData>>& crCirConfigs() { return crCirConfigs_; }
254 vector<QuantLib::ext::shared_ptr<CommoditySchwartzData>>& comConfigs() { return comConfigs_; }
255 void setCorrelations(const std::map<CorrelationKey, QuantLib::Handle<QuantLib::Quote>>& corrs) {
256 correlations_ = QuantLib::ext::make_shared<InstantaneousCorrelations>(corrs);
257 }
258 void setCorrelations(const QuantLib::ext::shared_ptr<InstantaneousCorrelations>& corrs) { correlations_ = corrs; }
260 std::string& measure() { return measure_; }
262 //@}
263
264 //! \name Serialisation
265 //@{
266 virtual void fromXML(XMLNode* node) override;
267 virtual XMLNode* toXML(XMLDocument& doc) const override;
268 //@}
269
270 //! \name Operators
271 //@{
272 bool operator==(const CrossAssetModelData& rhs);
273 bool operator!=(const CrossAssetModelData& rhs);
274 //@}
275
276 //! helper to convert LGM data, possibly including defaults, into an IR config vector
277 void buildIrConfigs(map<string, QuantLib::ext::shared_ptr<IrModelData>>& irMap);
278 //! helper to convert FX data, possibly including defaults, into an FX config vector
279 void buildFxConfigs(std::map<std::string, QuantLib::ext::shared_ptr<FxBsData>>& fxMap);
280 //! helper to convert EQ data, possibly including defaults, into an EQ config vector
281 void buildEqConfigs(std::map<std::string, QuantLib::ext::shared_ptr<EqBsData>>& eqMap);
282 //! helper to convert INF data, possibly including defaults, into an INF config vector
283 void buildInfConfigs(const std::map<std::string, QuantLib::ext::shared_ptr<InflationModelData>>& mp);
284 //! helper to convert CR LGM data, possibly including defaults, into CR config vectors
285 void buildCrConfigs(std::map<std::string, QuantLib::ext::shared_ptr<CrLgmData>>& crLgmMap,
286 std::map<std::string, QuantLib::ext::shared_ptr<CrCirData>>& crCirMap);
287 //! helper to convert COM data, possibly including defaulta, into a COM config vector
288 void buildComConfigs(std::map<std::string, QuantLib::ext::shared_ptr<CommoditySchwartzData>>& comMap);
289
290private:
291 struct HandleComp {
292 bool operator()(const Handle<Quote>& x, const Handle<Quote>& y) const {
293 return x.currentLink() == y.currentLink();
294 }
295 };
296
298 vector<std::string> currencies_;
299 vector<std::string> equities_;
300 vector<std::string> infindices_;
301 vector<std::string> creditNames_;
302 vector<std::string> commodities_;
303 vector<QuantLib::ext::shared_ptr<IrModelData>> irConfigs_;
304 vector<QuantLib::ext::shared_ptr<FxBsData>> fxConfigs_;
305 vector<QuantLib::ext::shared_ptr<EqBsData>> eqConfigs_;
306 vector<QuantLib::ext::shared_ptr<InflationModelData>> infConfigs_;
307 vector<QuantLib::ext::shared_ptr<CrLgmData>> crLgmConfigs_;
308 vector<QuantLib::ext::shared_ptr<CrCirData>> crCirConfigs_;
309 vector<QuantLib::ext::shared_ptr<CommoditySchwartzData>> comConfigs_;
311
312 QuantLib::ext::shared_ptr<InstantaneousCorrelations> correlations_;
314 std::string measure_;
316};
317
319
320} // namespace data
321} // namespace ore
Cross Asset Model Parameters.
CrossAssetModel::Discretization & discretization()
const std::string & measure() const
const vector< QuantLib::ext::shared_ptr< CrCirData > > & crCirConfigs() const
const vector< string > & equities() const
QuantLib::ext::shared_ptr< InstantaneousCorrelations > correlations_
vector< QuantLib::ext::shared_ptr< InflationModelData > > & infConfigs()
const vector< QuantLib::ext::shared_ptr< EqBsData > > & eqConfigs() const
CrossAssetModelData()
Default constructor.
void setCorrelations(const QuantLib::ext::shared_ptr< InstantaneousCorrelations > &corrs)
const vector< QuantLib::ext::shared_ptr< CrLgmData > > & crLgmConfigs() const
vector< QuantLib::ext::shared_ptr< IrModelData > > irConfigs_
void validate()
Check consistency of config vectors.
void buildCrConfigs(std::map< std::string, QuantLib::ext::shared_ptr< CrLgmData > > &crLgmMap, std::map< std::string, QuantLib::ext::shared_ptr< CrCirData > > &crCirMap)
helper to convert CR LGM data, possibly including defaults, into CR config vectors
CrossAssetModelData(const std::vector< QuantLib::ext::shared_ptr< IrModelData > > &irConfigs, const std::vector< QuantLib::ext::shared_ptr< FxBsData > > &fxConfigs, const std::vector< QuantLib::ext::shared_ptr< EqBsData > > &eqConfigs, const std::vector< QuantLib::ext::shared_ptr< InflationModelData > > &infConfigs, const std::vector< QuantLib::ext::shared_ptr< CrLgmData > > &crLgmConfigs, const std::vector< QuantLib::ext::shared_ptr< CrCirData > > &crCirConfigs, const std::vector< QuantLib::ext::shared_ptr< CommoditySchwartzData > > &comConfigs, const Size numberOfCreditStates, const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &c, Real tolerance=1e-4, const std::string &measure="LGM", const CrossAssetModel::Discretization discretization=CrossAssetModel::Discretization::Exact)
Detailed constructor (all asset classes)
CrossAssetModel::Discretization discretization() const
const vector< string > & infIndices() const
void buildFxConfigs(std::map< std::string, QuantLib::ext::shared_ptr< FxBsData > > &fxMap)
helper to convert FX data, possibly including defaults, into an FX config vector
vector< QuantLib::ext::shared_ptr< FxBsData > > & fxConfigs()
void buildComConfigs(std::map< std::string, QuantLib::ext::shared_ptr< CommoditySchwartzData > > &comMap)
helper to convert COM data, possibly including defaulta, into a COM config vector
vector< QuantLib::ext::shared_ptr< CrLgmData > > & crLgmConfigs()
virtual void fromXML(XMLNode *node) override
const vector< QuantLib::ext::shared_ptr< InflationModelData > > & infConfigs() const
virtual XMLNode * toXML(XMLDocument &doc) const override
const vector< QuantLib::ext::shared_ptr< CommoditySchwartzData > > & comConfigs() const
vector< QuantLib::ext::shared_ptr< EqBsData > > & eqConfigs()
const vector< string > & currencies() const
void buildInfConfigs(const std::map< std::string, QuantLib::ext::shared_ptr< InflationModelData > > &mp)
helper to convert INF data, possibly including defaults, into an INF config vector
void setCorrelations(const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &corrs)
void buildIrConfigs(map< string, QuantLib::ext::shared_ptr< IrModelData > > &irMap)
helper to convert LGM data, possibly including defaults, into an IR config vector
bool operator==(const CrossAssetModelData &rhs)
CrossAssetModelData(const std::vector< QuantLib::ext::shared_ptr< IrModelData > > &irConfigs, const std::vector< QuantLib::ext::shared_ptr< FxBsData > > &fxConfigs, const std::vector< QuantLib::ext::shared_ptr< EqBsData > > &eqConfigs, const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &c, Real tolerance=1e-4, const std::string &measure="LGM", const CrossAssetModel::Discretization discretization=CrossAssetModel::Discretization::Exact)
Detailed constructor (IR/FX/EQ only)
vector< QuantLib::ext::shared_ptr< EqBsData > > eqConfigs_
bool operator!=(const CrossAssetModelData &rhs)
vector< QuantLib::ext::shared_ptr< CommoditySchwartzData > > comConfigs_
const string & domesticCurrency() const
const vector< QuantLib::ext::shared_ptr< IrModelData > > & irConfigs() const
vector< QuantLib::ext::shared_ptr< CommoditySchwartzData > > & comConfigs()
const vector< QuantLib::ext::shared_ptr< FxBsData > > & fxConfigs() const
const vector< string > & creditNames() const
vector< QuantLib::ext::shared_ptr< CrCirData > > & crCirConfigs()
void clear()
Clear all vectors and maps.
vector< QuantLib::ext::shared_ptr< CrLgmData > > crLgmConfigs_
vector< QuantLib::ext::shared_ptr< CrCirData > > crCirConfigs_
vector< QuantLib::ext::shared_ptr< FxBsData > > fxConfigs_
vector< QuantLib::ext::shared_ptr< InflationModelData > > infConfigs_
const vector< string > & commodities() const
const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > & correlations() const
CrossAssetModelData(const vector< QuantLib::ext::shared_ptr< IrModelData > > &irConfigs, const vector< QuantLib::ext::shared_ptr< FxBsData > > &fxConfigs, const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &c, Real tolerance=1e-4, const std::string &measure="LGM", const CrossAssetModel::Discretization discretization=CrossAssetModel::Discretization::Exact)
Detailed constructor (IR/FX only)
vector< QuantLib::ext::shared_ptr< IrModelData > > & irConfigs()
CrossAssetModel::Discretization discretization_
void buildEqConfigs(std::map< std::string, QuantLib::ext::shared_ptr< EqBsData > > &eqMap)
helper to convert EQ data, possibly including defaults, into an EQ config vector
EQ Model Parameters.
Definition: eqbsdata.hpp:50
InstantaneousCorrelations(const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &correlations)
Detailed constructor.
void correlations(const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > &corrs)
virtual void fromXML(XMLNode *node) override
Populate members from XML.
virtual XMLNode * toXML(XMLDocument &doc) const override
Write class members to XML.
std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > correlations_
bool operator==(const InstantaneousCorrelations &rhs)
bool operator!=(const InstantaneousCorrelations &rhs)
void clear()
Clear all vectors and maps.
const std::map< CorrelationKey, QuantLib::Handle< QuantLib::Quote > > & correlations() const
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
COM component data for the cross asset model.
Currency and instrument specific conventions/defaults.
configuration class for building correlation matrices
CIR credit model data.
CR component data for the cross asset model.
EQ component data for the cross asset model.
FX component data for the cross asset model.
base class for holding inflation model data
Generic interest rate model data.
@ data
Definition: log.hpp:77
Base Market class.
QuantExt::CrossAssetModel::Discretization parseDiscretization(const string &s)
std::pair< CorrelationFactor, CorrelationFactor > CorrelationKey
Serializable Credit Default Swap.
Definition: namespaces.docs:23
bool operator()(const Handle< Quote > &x, const Handle< Quote > &y) const
XML utility functions.