Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetmodelbuilder.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/crossassetmodelbuilder.hpp
20 \brief Build a cross asset model
21 \ingroup models
22*/
23
24#pragma once
25
26#include <vector>
27
28#include <ql/types.hpp>
29
35
42
43namespace ore {
44namespace data {
45using namespace QuantLib;
46
47//! Cross Asset Model Builder
48/*!
49 CrossAssetModelBuilder takes a market snapshot, market conventions (the latter two
50 passed to the constructor), and a model configuration (passed to
51 the "build" member function) to build and calibrate a cross asset model.
52
53 \ingroup models
54 */
56public:
57 /*! The market for the calibration can possibly be different from the final market
58 defining the curves attached to the marginal LGM models; for example domestic OIS
59 curves may be used for the in currency swaption calibration while the global model
60 is operated under FX basis consistent discounting curves relative to the collateral
61 OIS curve. */
62 CrossAssetModelBuilder( //! Market object
63 const QuantLib::ext::shared_ptr<Market>& market,
64 //! cam configuration
65 const QuantLib::ext::shared_ptr<CrossAssetModelData>& config,
66 //! Market configuration for interest rate model calibration
67 const std::string& configurationLgmCalibration = Market::defaultConfiguration,
68 //! Market configuration for FX model calibration
69 const std::string& configurationFxCalibration = Market::defaultConfiguration,
70 //! Market configuration for EQ model calibration
71 const std::string& configurationEqCalibration = Market::defaultConfiguration,
72 //! Market configuration for INF model calibration
73 const std::string& configurationInfCalibration = Market::defaultConfiguration,
74 //! Market configuration for CR model calibration
75 const std::string& configurationCrCalibration = Market::defaultConfiguration,
76 //! Market configuration for simulation
77 const std::string& configurationFinalModel = Market::defaultConfiguration,
78 //! calibrate the model?
79 const bool dontCalibrate = false,
80 //! continue if bootstrap error exceeds tolerance
81 const bool continueOnError = false,
82 //! reference calibration grid
83 const std::string& referenceCalibrationGrid_ = "",
84 //! salvaging algorithm to apply to correlation matrix
85 const SalvagingAlgorithm::Type salvaging = SalvagingAlgorithm::None,
86 //! id of the builder
87 const std::string& id = "unknown");
88
89 //! Default destructor
91
92 //! return the model
93 Handle<QuantExt::CrossAssetModel> model() const;
94
95 //! \name Inspectors
96 //@{
97 const std::vector<Real>& swaptionCalibrationErrors();
98 const std::vector<Real>& fxOptionCalibrationErrors();
99 const std::vector<Real>& eqOptionCalibrationErrors();
100 const std::vector<Real>& inflationCalibrationErrors();
101 const std::vector<Real>& comOptionCalibrationErrors();
102 //@}
103
104 //! \name ModelBuilder interface
105 //@{
106 void forceRecalculate() override;
107 bool requiresRecalibration() const override;
108 //@}
109
110private:
111 void performCalculations() const override;
112 void buildModel() const;
113 void resetModelParams(const CrossAssetModel::AssetType t, const Size param, const Size index, const Size i) const;
114 void copyModelParams(const CrossAssetModel::AssetType t0, const Size param0, const Size index0, const Size i0,
115 const CrossAssetModel::AssetType t1, const Size param1, const Size index1, const Size i1,
116 const Real mult) const;
117
118 mutable std::vector<std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>> swaptionBaskets_;
119 mutable std::vector<std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>> fxOptionBaskets_;
120 mutable std::vector<std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>> eqOptionBaskets_;
121 mutable std::vector<std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>> comOptionBaskets_;
122 mutable std::vector<Array> optionExpiries_;
123 mutable std::vector<Array> swaptionMaturities_;
124 mutable std::vector<Array> fxOptionExpiries_;
125 mutable std::vector<Array> eqOptionExpiries_;
126 mutable std::vector<Array> comOptionExpiries_;
127 mutable std::vector<Real> swaptionCalibrationErrors_;
128 mutable std::vector<Real> fxOptionCalibrationErrors_;
129 mutable std::vector<Real> eqOptionCalibrationErrors_;
130 mutable std::vector<Real> inflationCalibrationErrors_;
131 mutable std::vector<Real> comOptionCalibrationErrors_;
132
133 //! Store model builders for each asset under each asset type.
135 std::map<QuantLib::Size, QuantLib::ext::shared_ptr<QuantExt::ModelBuilder>>>
137 mutable Array params_;
138
139 const QuantLib::ext::shared_ptr<ore::data::Market> market_;
140 const QuantLib::ext::shared_ptr<CrossAssetModelData> config_;
143 const bool dontCalibrate_;
145 const std::string referenceCalibrationGrid_;
146 const SalvagingAlgorithm::Type salvaging_;
147 const std::string id_;
148
149 // TODO: Move CalibrationErrorType, optimizer and end criteria parameters to data
150 QuantLib::ext::shared_ptr<OptimizationMethod> optimizationMethod_;
151 EndCriteria endCriteria_;
152
153 // helper flag to process forceRecalculate()
154 bool forceCalibration_ = false;
155
156 // market observer
157 QuantLib::ext::shared_ptr<QuantExt::MarketObserver> marketObserver_;
158
159 // resulting model
160 mutable RelinkableHandle<QuantExt::CrossAssetModel> model_;
161
162 // Calibrate DK inflation model
164 QuantLib::Size modelIdx,
165 const std::vector<QuantLib::ext::shared_ptr<QuantLib::BlackCalibrationHelper>>& calibrationBasket,
166 const QuantLib::ext::shared_ptr<QuantExt::InfDkParametrization>& inflationParam) const;
167
168 // Calibrate JY inflation model
170 QuantLib::Size modelIdx,
171 const QuantLib::ext::shared_ptr<InfJyBuilder>& jyBuilder,
172 const QuantLib::ext::shared_ptr<QuantExt::InfJyParameterization>& inflationParam) const;
173
174 // Attach JY engines to helpers for JY calibration
175 void setJyPricingEngine(QuantLib::Size modelIdx,
176 const std::vector<QuantLib::ext::shared_ptr<QuantLib::CalibrationHelper>>& calibrationBasket,
177 bool indexIsInterpolated) const;
178};
179
180} // namespace data
181} // namespace ore
const SalvagingAlgorithm::Type salvaging_
void setJyPricingEngine(QuantLib::Size modelIdx, const std::vector< QuantLib::ext::shared_ptr< QuantLib::CalibrationHelper > > &calibrationBasket, bool indexIsInterpolated) const
QuantLib::ext::shared_ptr< QuantExt::MarketObserver > marketObserver_
void copyModelParams(const CrossAssetModel::AssetType t0, const Size param0, const Size index0, const Size i0, const CrossAssetModel::AssetType t1, const Size param1, const Size index1, const Size i1, const Real mult) const
void calibrateInflation(const InfJyData &data, QuantLib::Size modelIdx, const QuantLib::ext::shared_ptr< InfJyBuilder > &jyBuilder, const QuantLib::ext::shared_ptr< QuantExt::InfJyParameterization > &inflationParam) const
std::vector< std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > > swaptionBaskets_
void calibrateInflation(const InfDkData &data, QuantLib::Size modelIdx, const std::vector< QuantLib::ext::shared_ptr< QuantLib::BlackCalibrationHelper > > &calibrationBasket, const QuantLib::ext::shared_ptr< QuantExt::InfDkParametrization > &inflationParam) const
std::vector< std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > > comOptionBaskets_
const std::vector< Real > & swaptionCalibrationErrors()
std::vector< std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > > eqOptionBaskets_
Handle< QuantExt::CrossAssetModel > model() const
return the model
std::map< QuantExt::CrossAssetModel::AssetType, std::map< QuantLib::Size, QuantLib::ext::shared_ptr< QuantExt::ModelBuilder > > > subBuilders_
Store model builders for each asset under each asset type.
const std::vector< Real > & eqOptionCalibrationErrors()
RelinkableHandle< QuantExt::CrossAssetModel > model_
const std::vector< Real > & inflationCalibrationErrors()
const QuantLib::ext::shared_ptr< ore::data::Market > market_
std::vector< std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > > fxOptionBaskets_
QuantLib::ext::shared_ptr< OptimizationMethod > optimizationMethod_
void resetModelParams(const CrossAssetModel::AssetType t, const Size param, const Size index, const Size i) const
const std::vector< Real > & fxOptionCalibrationErrors()
const QuantLib::ext::shared_ptr< CrossAssetModelData > config_
const std::vector< Real > & comOptionCalibrationErrors()
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
Cross asset model data.
Dodgson Kainth inflation model component data for the cross asset model.
Builder for a Jarrow Yildrim inflation model component.
Jarrow Yildirim inflation model component data for the cross asset model.
@ data
Definition: log.hpp:77
Base Market class.
Serializable Credit Default Swap.
Definition: namespaces.docs:23
XML utility functions.