Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossassetmodel.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016-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 models/crossassetmodel.hpp
20 \brief cross asset model
21 \ingroup crossassetmodel
22*/
23
24#ifndef quantext_crossasset_model_hpp
25#define quantext_crossasset_model_hpp
26
40#include <qle/models/lgm.hpp>
41
43
44#include <ql/errors.hpp>
45#include <ql/math/distributions/normaldistribution.hpp>
46#include <ql/math/integrals/integral.hpp>
47#include <ql/math/matrix.hpp>
48#include <ql/models/model.hpp>
49
50#include <boost/enable_shared_from_this.hpp>
51
52namespace QuantExt {
53using namespace QuantLib;
54
55//! Cross Asset Model
56/*! \ingroup crossassetmodel
57 */
59public:
60 enum class AssetType : Size { IR = 0, FX = 1, INF = 2, CR = 3, EQ = 4, COM = 5, CrState = 6 };
61 enum class ModelType { LGM1F, HW, BS, DK, CIRPP, JY, GAB, GENERIC };
62 enum class Discretization { Euler, Exact };
63
64 static constexpr Size numberOfAssetTypes = 7;
65
66 /*! Parametrizations must be given in the following order
67 - IR (first parametrization defines the domestic currency)
68 - FX (for all pairs domestic-ccy defined by the IR models)
69 - INF (optionally, ccy must be a subset of the IR ccys)
70 - CR (optionally, ccy must be a subset of the IR ccys)
71 - EQ (for all names equity currency defined in Parametrization)
72 - COM (for all names commodity currency defined in Parametrization)
73 If the correlation matrix is not given, it is initialized
74 as the unit matrix (and can be customized after
75 construction of the model).
76
77 All IR components must be of type HW _or_ LGM1F, i.e. you can't mix the two types.
78 */
79 CrossAssetModel(const std::vector<QuantLib::ext::shared_ptr<Parametrization>>& parametrizations,
80 const Matrix& correlation = Matrix(), const SalvagingAlgorithm::Type salvaging = SalvagingAlgorithm::None,
83
84 /*! IR-FX model based constructor */
85 CrossAssetModel(const std::vector<QuantLib::ext::shared_ptr<IrModel>>& currencyModels,
86 const std::vector<QuantLib::ext::shared_ptr<FxBsParametrization>>& fxParametrizations,
87 const Matrix& correlation = Matrix(), const SalvagingAlgorithm::Type salvaging = SalvagingAlgorithm::None,
90
91 /*! returns the state process with a given discretization */
92 QuantLib::ext::shared_ptr<CrossAssetStateProcess> stateProcess() const;
93
94 /*! total dimension of model (sum of number of state variables) */
95 Size dimension() const;
96
97 /*! total number of Brownian motions (excluding aux brownians) */
98 Size brownians() const;
99
100 /*! total number of aux Brownian motions */
101 Size auxBrownians() const;
102
103 /*! total number of parameters that can be calibrated */
104 Size totalNumberOfParameters() const;
105
106 /*! number of components for an asset class */
107 Size components(const AssetType t) const;
108
109 /*! number of brownian motions for a component excluding aux Brownians */
110 Size brownians(const AssetType t, const Size i) const;
111
112 /*! number of aux brownian motions for a component */
113 Size auxBrownians(const AssetType t, const Size i) const;
114
115 /*! number of state variables for a component */
116 Size stateVariables(const AssetType t, const Size i) const;
117
118 /*! model type of a component */
119 ModelType modelType(const AssetType t, const Size i) const;
120
121 /*! Choice of probability measure */
123
124 /*! return index for currency (0 = domestic, 1 = first
125 foreign currency and so on) */
126 Size ccyIndex(const Currency& ccy) const;
127
128 /*! return index for equity (0 = first equity) */
129 Size eqIndex(const std::string& eqName) const;
130
131 /*! return index for inflation (0 = first inflation index) */
132 Size infIndex(const std::string& index) const;
133
134 /*! return index for credit (0 = first credit name) */
135 Size crName(const std::string& name) const;
136
137 /*! return index for commodity (0 = first equity) */
138 Size comIndex(const std::string& comName) const;
139
140 /*! observer and linked calibrated model interface */
141 void update() override;
142 void generateArguments() override;
143
144 /*! the vector of parametrizations */
145 const std::vector<QuantLib::ext::shared_ptr<Parametrization>>& parametrizations() const { return p_; }
146
147 /*! components per asset class, see below for specific model type inspectors */
148 const QuantLib::ext::shared_ptr<Parametrization> ir(const Size ccy) const;
149 const QuantLib::ext::shared_ptr<Parametrization> fx(const Size ccy) const;
150 const QuantLib::ext::shared_ptr<Parametrization> inf(const Size i) const;
151 const QuantLib::ext::shared_ptr<Parametrization> cr(const Size i) const;
152 const QuantLib::ext::shared_ptr<Parametrization> eq(const Size i) const;
153 const QuantLib::ext::shared_ptr<Parametrization> com(const Size i) const;
154 const QuantLib::ext::shared_ptr<Parametrization> crstate(const Size i) const;
155
156 /* ir model */
157 const QuantLib::ext::shared_ptr<IrModel> irModel(const Size ccy) const;
158
159 /*! numeraire */
160 QuantLib::Real
161 numeraire(const Size ccy, const QuantLib::Time t, const QuantLib::Array& x,
162 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
163 const QuantLib::Array& aux = Array()) const;
164
165 /*! discount bond */
166 QuantLib::Real discountBond(
167 const Size ccy, const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array& x,
168 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve = Handle<YieldTermStructure>()) const;
169
170 /*! HW components, ccy=0 refers to the domestic currency */
171 const QuantLib::ext::shared_ptr<HwModel> hw(const Size ccy) const;
172 const QuantLib::ext::shared_ptr<IrHwParametrization> irhw(const Size ccy) const;
173
174 /*! LGM1F components, ccy=0 refers to the domestic currency */
175 const QuantLib::ext::shared_ptr<LinearGaussMarkovModel> lgm(const Size ccy) const;
176 const QuantLib::ext::shared_ptr<IrLgm1fParametrization> irlgm1f(const Size ccy) const;
177
178 /*! DEPRECATED LGM measure numeraire */
179 Real numeraire(const Size ccy, const Time t, const Real x,
180 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>()) const;
181
182 /*! DEPRECATED LGM - Bank account measure numeraire B(t) as a function of drifted LGM state variable x and
183 * drift-free auxiliary state variable y */
184 Real bankAccountNumeraire(const Size ccy, const Time t, const Real x, const Real y,
185 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>()) const;
186
187 /*! DEPRECATED LGM specific discountBond */
188 Real discountBond(const Size ccy, const Time t, const Time T, const Real x,
189 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>()) const;
190
191 /*! DEPRECATED LGM specific discountBond */
192 Real reducedDiscountBond(const Size ccy, const Time t, const Time T, const Real x,
193 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>()) const;
194
195 /*! DEPRECATED LGM specific discountBond */
196 Real discountBondOption(const Size ccy, Option::Type type, const Real K, const Time t, const Time S, const Time T,
197 Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>()) const;
198
199 /* fx model */
200 const QuantLib::ext::shared_ptr<FxModel> fxModel(const Size ccy) const;
201
202 /*! FXBS components, ccy=0 referes to the first foreign currency,
203 so it corresponds to ccy+1 if you want to get the corresponding
204 irmgl1f component */
205 const QuantLib::ext::shared_ptr<FxBsParametrization> fxbs(const Size ccy) const;
206
207 /*! INF DK components */
208 const QuantLib::ext::shared_ptr<InfDkParametrization> infdk(const Size i) const;
209
210 //! Inflation JY component
211 const QuantLib::ext::shared_ptr<InfJyParameterization> infjy(const Size i) const;
212
213 /*! CR LGM 1F components */
214 const QuantLib::ext::shared_ptr<CrLgm1fParametrization> crlgm1f(const Size i) const;
215
216 /*! CR CIR++ components */
217 const QuantLib::ext::shared_ptr<CrCirpp> crcirppModel(const Size i) const;
218 const QuantLib::ext::shared_ptr<CrCirppParametrization> crcirpp(const Size i) const;
219
220 /*! EQBS components */
221 const QuantLib::ext::shared_ptr<EqBsParametrization> eqbs(const Size ccy) const;
222
223 /* com model */
224 const QuantLib::ext::shared_ptr<CommodityModel> comModel(const Size com) const;
225
226 /*! COMBS components */
227 const QuantLib::ext::shared_ptr<CommoditySchwartzParametrization> combs(const Size ccy) const;
228
229 /*! CreditState components */
230 const QuantLib::ext::shared_ptr<CrStateParametrization> crstateParam(const Size index) const;
231
232 /* ... add more components here ...*/
233
234 /*! correlation linking the different marginal models, note that
235 the use of asset class pairs specific inspectors is
236 recommended instead of the global matrix directly */
237 const Matrix& correlation() const;
238
239 /*! check if correlation matrix is valid */
240 void checkCorrelationMatrix() const;
241
242 /*! index of component in the parametrization vector */
243 Size idx(const AssetType t, const Size i) const;
244
245 /*! index of component in the correlation matrix, by offset */
246 Size cIdx(const AssetType t, const Size i, const Size offset = 0) const;
247
248 /*! index of component in the Brownian vector (including aux brownians), by offset
249 this is checked to be equal to cIdx for Euler discretization and pIdx for exact discretization
250 as an internal assertion */
251 Size wIdx(const AssetType t, const Size i, const Size offset = 0) const;
252
253 /*! index of component in the stochastic process array, by offset */
254 Size pIdx(const AssetType t, const Size i, const Size offset = 0) const;
255
256 /*! correlation between two components */
257 Real correlation(const AssetType s, const Size i, const AssetType t, const Size j, const Size iOffset = 0,
258 const Size jOffset = 0) const;
259 /*! set correlation */
260 void setCorrelation(const AssetType s, const Size i, const AssetType t, const Size j, const Real value,
261 const Size iOffset = 0, const Size jOffset = 0);
262
263 /*! get discretization */
265
266 /*! get salvaging algorithm */
267 SalvagingAlgorithm::Type salvagingAlgorithm() const { return salvaging_; }
268
269 /*! analytical moments require numerical integration,
270 which can be customized here */
271 void setIntegrationPolicy(const QuantLib::ext::shared_ptr<Integrator> integrator,
272 const bool usePiecewiseIntegration = true) const;
273 const QuantLib::ext::shared_ptr<Integrator> integrator() const;
274
275 /*! return (V(t), V^tilde(t,T)) in the notation of the book */
276 std::pair<Real, Real> infdkV(const Size i, const Time t, const Time T);
277
278 /*! return (I(t), I^tilde(t,T)) in the notation of the book, note that
279 I(0) is normalized to 1 here, i.e. you have to multiply the result
280 with the index value (as of the base date of the inflation ts) */
281 std::pair<Real, Real> infdkI(const Size i, const Time t, const Time T, const Real z, const Real y);
282
283 /*! return YoYIIS(t) in the notation of the book, the year on year
284 swaplet price from S to T, at time t */
285 Real infdkYY(const Size i, const Time t, const Time S, const Time T, const Real z, const Real y, const Real irz);
286
287 /*! returns (S(t), S^tilde(t,T)) in the notation of the book */
288 std::pair<Real, Real> crlgm1fS(const Size i, const Size ccy, const Time t, const Time T, const Real z,
289 const Real y) const;
290
291 /*! returns (S(t), S^tilde(t,T)) in the notation of the book */
292 std::pair<Real, Real> crcirppS(const Size i, const Time t, const Time T, const Real y, const Real s) const;
293
294 /*! tentative: more generic interface that is agnostic of the model type - so far only for CR */
295 virtual Handle<DefaultProbabilityTermStructure> crTs(const Size i) const;
296 virtual std::pair<Real, Real> crS(const Size i, const Size ccy, const Time t, const Time T, const Real z,
297 const Real y) const;
298
299 /*! calibration procedures */
300
301 /*! calibrate irlgm1f volatilities to a sequence of ir options with
302 expiry times equal to step times in the parametrization */
303 void calibrateIrLgm1fVolatilitiesIterative(const Size ccy,
304 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
305 OptimizationMethod& method, const EndCriteria& endCriteria,
307 const std::vector<Real>& weights = std::vector<Real>());
308
309 /*! calibrate irlgm1f reversion to a sequence of ir options with
310 maturities equal to step times in the parametrization */
311 void calibrateIrLgm1fReversionsIterative(const Size ccy,
312 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
313 OptimizationMethod& method, const EndCriteria& endCriteria,
315 const std::vector<Real>& weights = std::vector<Real>());
316
317 /*! calibrate irlgm1f parameters for one ccy globally to a set
318 of ir options */
319 void calibrateIrLgm1fGlobal(const Size ccy, const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
320 OptimizationMethod& method, const EndCriteria& endCriteria,
322 const std::vector<Real>& weights = std::vector<Real>());
323
324 /*! calibrate eq or fx volatilities to a sequence of options with
325 expiry times equal to step times in the parametrization */
326 void calibrateBsVolatilitiesIterative(const AssetType& assetType, const Size aIdx,
327 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
328 OptimizationMethod& method, const EndCriteria& endCriteria,
330 const std::vector<Real>& weights = std::vector<Real>());
331
332 /*! calibrate eq/fx/com volatilities globally to a set of eq/fx/com options */
333 void calibrateBsVolatilitiesGlobal(const AssetType& assetType, const Size aIdx,
334 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
335 OptimizationMethod& method, const EndCriteria& endCriteria,
337 const std::vector<Real>& weights = std::vector<Real>());
338
339 /*! calibrate infdk volatilities to a sequence of cpi options with
340 expiry times equal to step times in the parametrization */
341 void calibrateInfDkVolatilitiesIterative(const Size index,
342 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
343 OptimizationMethod& method, const EndCriteria& endCriteria,
345 const std::vector<Real>& weights = std::vector<Real>());
346
347 /*! calibrate infdk reversions to a sequence of cpi options with
348 maturity times equal to step times in the parametrization */
349 void calibrateInfDkReversionsIterative(const Size index,
350 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
351 OptimizationMethod& method, const EndCriteria& endCriteria,
353 const std::vector<Real>& weights = std::vector<Real>());
354
355 /*! calibrate infdk volatilities globally to a sequence of cpi cap/floors */
356 void calibrateInfDkVolatilitiesGlobal(const Size index,
357 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
358 OptimizationMethod& method, const EndCriteria& endCriteria,
360 const std::vector<Real>& weights = std::vector<Real>());
361
362 /*! calibrate infdk reversions globally to a sequence of cpi cap/floors */
363 void calibrateInfDkReversionsGlobal(const Size index,
364 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
365 OptimizationMethod& method, const EndCriteria& endCriteria,
367 const std::vector<Real>& weights = std::vector<Real>());
368
369 /*! Calibrate JY inflation parameters globally.
370
371 The parameter \p toCalibrate indicates which parameters of the JY inflation model that we want to calibrate.
372 The map key should be in {0, 1, 2} where 0 indicates the real rate volatility, 1 indicates the real rate
373 reversion and 2 indicates the inflation index volatility. The value is \c true if we wish to calibrate
374 the parameter and \p false if we do not want to calibrate it.
375 */
376 void calibrateInfJyGlobal(QuantLib::Size index,
377 const std::vector<QuantLib::ext::shared_ptr<QuantLib::CalibrationHelper>>& helpers,
378 QuantLib::OptimizationMethod& method, const QuantLib::EndCriteria& endCriteria,
379 const std::map<QuantLib::Size, bool>& toCalibrate,
380 const QuantLib::Constraint& constraint = QuantLib::Constraint(),
381 const std::vector<QuantLib::Real>& weights = std::vector<QuantLib::Real>());
382
383 /*! Calibrate a single JY inflation parameter iteratively.
384
385 Calibrate one of real rate volatility, real rate reversion or inflation index volatility. The
386 \p parameterIndex indicates the parameter that should be calibrated where 0 indicates the real rate
387 volatility, 1 indicates the real rate reversion and 2 indicates the inflation index volatility.
388 */
389 void calibrateInfJyIterative(QuantLib::Size inflationModelIndex, QuantLib::Size parameterIndex,
390 const std::vector<QuantLib::ext::shared_ptr<QuantLib::CalibrationHelper>>& helpers,
391 QuantLib::OptimizationMethod& method, const QuantLib::EndCriteria& endCriteria,
392 const QuantLib::Constraint& constraint = QuantLib::Constraint(),
393 const std::vector<QuantLib::Real>& weights = std::vector<QuantLib::Real>());
394
395 /*! calibrate crlgm1f volatilities to a sequence of cds options with
396 expiry times equal to step times in the parametrization */
397 void calibrateCrLgm1fVolatilitiesIterative(const Size index,
398 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
399 OptimizationMethod& method, const EndCriteria& endCriteria,
401 const std::vector<Real>& weights = std::vector<Real>());
402
403 /*! calibrate crlgm1f reversions to a sequence of cds options with
404 maturity times equal to step times in the parametrization */
405 void calibrateCrLgm1fReversionsIterative(const Size index,
406 const std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>>& helpers,
407 OptimizationMethod& method, const EndCriteria& endCriteria,
409 const std::vector<Real>& weights = std::vector<Real>());
410
411 /* ... add more calibration procedures here ... */
412
413 /* calibration constraints */
414 /* move
415 - parameter "param" (e.g. vol, reversion, or all if null)
416 - of asset type component t / index
417 - at step i (or at all steps if i is null) */
418 std::vector<bool> MoveParameter(const AssetType t, const Size param, const Size index, const Size i);
419
420protected:
421 /* ctor to be used in extensions, initialize is not called */
422 CrossAssetModel(const std::vector<QuantLib::ext::shared_ptr<Parametrization>>& parametrizations, const Matrix& correlation,
423 SalvagingAlgorithm::Type salvaging, IrModel::Measure measure, const Discretization discretization, const bool)
425 }
426
427 /*! number of arguments for a component */
428 Size arguments(const AssetType t, const Size i) const;
429
430 /*! index of component in the arguments vector, by offset */
431 Size aIdx(const AssetType t, const Size i, const Size offset = 0) const;
432
433 /*! asset and model type for given parametrization */
434 virtual std::pair<AssetType, ModelType> getComponentType(const Size i) const;
435 /*! number of parameters for given parametrization */
436 virtual Size getNumberOfParameters(const Size i) const;
437 /*! number of brownians (excluding aux brownians) for given parametrization */
438 virtual Size getNumberOfBrownians(const Size i) const;
439 /*! number of aux brownians for given parametrization */
440 virtual Size getNumberOfAuxBrownians(const Size i) const;
441 /*! number of state variables for given parametrization */
442 virtual Size getNumberOfStateVariables(const Size i) const;
443 /*! helper function to init component indices */
444 void updateIndices(const AssetType& t, const Size i, const Size cIdx, const Size wIdx, const Size pIdx,
445 const Size aIdx);
446 /* init methods */
447 virtual void initialize();
448 virtual void initializeParametrizations();
449 virtual void initializeCorrelation();
450 virtual void initializeArguments();
451 virtual void finalizeArguments();
452 virtual void checkModelConsistency() const;
453 virtual void initDefaultIntegrator();
454
455 /* helper function for infdkI, crlgm1fS */
456 Real infV(const Size idx, const Size ccy, const Time t, const Time T) const;
457 Real crV(const Size idx, const Size ccy, const Time t, const Time T) const;
458
459 // cache for infdkI, crlgm1fS method
460 struct cache_key {
461 Size i, ccy;
462 double t, T;
463 bool operator==(const cache_key& o) const { return (i == o.i) && (ccy == o.ccy) && (t == o.t) && (T == o.T); }
464 };
465
467 std::size_t operator()(cache_key const& x) const {
468 std::size_t seed = 0;
469 boost::hash_combine(seed, x.i);
470 boost::hash_combine(seed, x.ccy);
471 boost::hash_combine(seed, x.t);
472 boost::hash_combine(seed, x.T);
473 return seed;
474 }
475 };
476
477 mutable boost::unordered_map<cache_key, std::pair<Real, Real>, cache_hasher> cache_crlgm1fS_, cache_infdkI_;
478
479 /* members */
480
481 // components per asset type
482 std::vector<Size> components_;
483 // indices per asset type and component number within asset type
484 std::vector<std::vector<Size>> idx_, cIdx_, wIdx_, pIdx_, aIdx_, brownians_, auxBrownians_, stateVariables_,
486 // counter
488 // model type per asset type and component number within asset type
489 std::vector<std::vector<ModelType>> modelType_;
490 // parametrizations, models
491 std::vector<QuantLib::ext::shared_ptr<Parametrization>> p_;
492 std::vector<QuantLib::ext::shared_ptr<IrModel>> irModels_; // HwModel or LGM1F
493 std::vector<QuantLib::ext::shared_ptr<FxModel>> fxModels_; // FxBsModel
494 std::vector<QuantLib::ext::shared_ptr<CrCirpp>> crcirppModel_;
495 std::vector<QuantLib::ext::shared_ptr<CommodityModel>> comModels_;
496 Matrix rho_;
497 SalvagingAlgorithm::Type salvaging_;
500 mutable QuantLib::ext::shared_ptr<Integrator> integrator_;
501 mutable QuantLib::ext::shared_ptr<CrossAssetStateProcess> stateProcess_;
502
503 void appendToFixedParameterVector(const AssetType t, const AssetType v, const Size param, const Size index,
504 const Size i, std::vector<bool>& res);
505};
506
507//! Utility function to return a handle to the inflation term structure given the inflation index.
508QuantLib::Handle<QuantLib::ZeroInflationTermStructure>
509inflationTermStructure(const QuantLib::ext::shared_ptr<CrossAssetModel>& model, QuantLib::Size index);
510
511// inline
512
513inline Size CrossAssetModel::dimension() const { return totalDimension_; }
514
516
518
520
521inline const QuantLib::ext::shared_ptr<Parametrization> CrossAssetModel::ir(const Size ccy) const {
523}
524
525inline const QuantLib::ext::shared_ptr<Parametrization> CrossAssetModel::fx(const Size ccy) const {
527}
528
529inline const QuantLib::ext::shared_ptr<Parametrization> CrossAssetModel::inf(const Size i) const {
531}
532
533inline const QuantLib::ext::shared_ptr<Parametrization> CrossAssetModel::cr(const Size i) const {
535}
536
537inline const QuantLib::ext::shared_ptr<Parametrization> CrossAssetModel::eq(const Size i) const {
538 return QuantLib::ext::static_pointer_cast<Parametrization>(p_[idx(CrossAssetModel::AssetType::EQ, i)]);
539}
540
541inline const QuantLib::ext::shared_ptr<Parametrization> CrossAssetModel::com(const Size i) const {
542 return QuantLib::ext::static_pointer_cast<Parametrization>(p_[idx(CrossAssetModel::AssetType::COM, i)]);
543}
544
545inline const QuantLib::ext::shared_ptr<IrModel> CrossAssetModel::irModel(const Size ccy) const {
546 return irModels_[ccy];
547}
548
549inline const QuantLib::ext::shared_ptr<FxModel> CrossAssetModel::fxModel(const Size ccy) const {
550 return fxModels_[ccy];
551}
552
553inline const QuantLib::ext::shared_ptr<CommodityModel> CrossAssetModel::comModel(const Size com) const {
554 return comModels_[com];
555}
556
557inline const QuantLib::ext::shared_ptr<HwModel> CrossAssetModel::hw(const Size ccy) const {
558 auto tmp = QuantLib::ext::dynamic_pointer_cast<HwModel>(irModels_[idx(CrossAssetModel::AssetType::IR, ccy)]);
559 QL_REQUIRE(tmp, "model at " << ccy << " is not IR-HW");
560 return tmp;
561}
562
563inline const QuantLib::ext::shared_ptr<IrHwParametrization> CrossAssetModel::irhw(const Size ccy) const {
564 return hw(ccy)->parametrization();
565}
566
567inline const QuantLib::ext::shared_ptr<LinearGaussMarkovModel> CrossAssetModel::lgm(const Size ccy) const {
568 auto tmp = QuantLib::ext::dynamic_pointer_cast<LinearGaussMarkovModel>(irModels_[idx(CrossAssetModel::AssetType::IR, ccy)]);
569 QL_REQUIRE(tmp, "model at " << ccy << " is not IR-LGM1F");
570 return tmp;
571}
572
573inline const QuantLib::ext::shared_ptr<IrLgm1fParametrization> CrossAssetModel::irlgm1f(const Size ccy) const {
574 return lgm(ccy)->parametrization();
575}
576
577inline const QuantLib::ext::shared_ptr<InfDkParametrization> CrossAssetModel::infdk(const Size i) const {
578 QuantLib::ext::shared_ptr<InfDkParametrization> tmp =
579 QuantLib::ext::dynamic_pointer_cast<InfDkParametrization>(p_[idx(CrossAssetModel::AssetType::INF, i)]);
580 QL_REQUIRE(tmp, "model at " << i << " is not INF-DK");
581 return tmp;
582}
583
584inline const QuantLib::ext::shared_ptr<InfJyParameterization> CrossAssetModel::infjy(const Size i) const {
585 auto tmp = QuantLib::ext::dynamic_pointer_cast<InfJyParameterization>(p_[idx(CrossAssetModel::AssetType::INF, i)]);
586 QL_REQUIRE(tmp, "model at " << i << " is not INF-JY");
587 return tmp;
588}
589
590inline const QuantLib::ext::shared_ptr<CrLgm1fParametrization> CrossAssetModel::crlgm1f(const Size i) const {
591 QuantLib::ext::shared_ptr<CrLgm1fParametrization> tmp =
592 QuantLib::ext::dynamic_pointer_cast<CrLgm1fParametrization>(p_[idx(CrossAssetModel::AssetType::CR, i)]);
593 QL_REQUIRE(tmp, "model at " << i << " is not CR-LGM");
594 return tmp;
595}
596
597inline const QuantLib::ext::shared_ptr<CrCirpp> CrossAssetModel::crcirppModel(const Size i) const {
598 QuantLib::ext::shared_ptr<CrCirpp> tmp = crcirppModel_[i];
599 QL_REQUIRE(tmp, "model at " << i << " is not CR-CIRPP");
600 return tmp;
601}
602
603inline const QuantLib::ext::shared_ptr<CrCirppParametrization> CrossAssetModel::crcirpp(const Size i) const {
604 QuantLib::ext::shared_ptr<CrCirppParametrization> tmp =
605 QuantLib::ext::dynamic_pointer_cast<CrCirppParametrization>(p_[idx(CrossAssetModel::AssetType::CR, i)]);
606 QL_REQUIRE(tmp, "model at " << i << " is not CR-CIRPP");
607 return tmp;
608}
609
610inline const QuantLib::ext::shared_ptr<EqBsParametrization> CrossAssetModel::eqbs(const Size name) const {
611 QuantLib::ext::shared_ptr<EqBsParametrization> tmp =
612 QuantLib::ext::dynamic_pointer_cast<EqBsParametrization>(p_[idx(CrossAssetModel::AssetType::EQ, name)]);
613 QL_REQUIRE(tmp, "model at " << name << " is not EQ-BS");
614 return tmp;
615}
616
617inline const QuantLib::ext::shared_ptr<CommoditySchwartzParametrization> CrossAssetModel::combs(const Size name) const {
618 QuantLib::ext::shared_ptr<CommoditySchwartzParametrization> tmp =
619 QuantLib::ext::dynamic_pointer_cast<CommoditySchwartzParametrization>(p_[idx(CrossAssetModel::AssetType::COM, name)]);
620 QL_REQUIRE(tmp, "model at " << name << " is not COM-BS");
621 return tmp;
622}
623
624inline const QuantLib::ext::shared_ptr<CrStateParametrization> CrossAssetModel::crstateParam(const Size i) const {
625 return QuantLib::ext::static_pointer_cast<CrStateParametrization>(p_[idx(CrossAssetModel::AssetType::CrState, i)]);
626}
627
628inline QuantLib::Real CrossAssetModel::numeraire(const Size ccy, const QuantLib::Time t, const QuantLib::Array& x,
629 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountCurve,
630 const QuantLib::Array& aux) const {
631 return irModel(ccy)->numeraire(t, x, discountCurve, aux);
632}
633
634inline Real CrossAssetModel::numeraire(const Size ccy, const Time t, const Real x,
635 Handle<YieldTermStructure> discountCurve) const {
636 return lgm(ccy)->numeraire(t, x, discountCurve);
637}
638
639inline Real CrossAssetModel::bankAccountNumeraire(const Size ccy, const Time t, const Real x, const Real y,
640 Handle<YieldTermStructure> discountCurve) const {
641 return lgm(ccy)->bankAccountNumeraire(t, x, y, discountCurve);
642}
643
644inline Real CrossAssetModel::discountBond(const Size ccy, const Time t, const Time T, const Real x,
645 Handle<YieldTermStructure> discountCurve) const {
646 return lgm(ccy)->discountBond(t, T, x, discountCurve);
647}
648
649inline Real CrossAssetModel::reducedDiscountBond(const Size ccy, const Time t, const Time T, const Real x,
650 Handle<YieldTermStructure> discountCurve) const {
651 return lgm(ccy)->reducedDiscountBond(t, T, x, discountCurve);
652}
653
654inline Real CrossAssetModel::discountBondOption(const Size ccy, Option::Type type, const Real K, const Time t,
655 const Time S, const Time T,
656 Handle<YieldTermStructure> discountCurve) const {
657 return lgm(ccy)->discountBondOption(type, K, t, S, T, discountCurve);
658}
659
660inline const QuantLib::ext::shared_ptr<FxBsParametrization> CrossAssetModel::fxbs(const Size ccy) const {
661 QuantLib::ext::shared_ptr<FxBsParametrization> tmp =
662 QuantLib::ext::dynamic_pointer_cast<FxBsParametrization>(p_[idx(CrossAssetModel::AssetType::FX, ccy)]);
663 QL_REQUIRE(tmp, "model at " << ccy << " is not FX-BS");
664 return tmp;
665}
666
667inline const Matrix& CrossAssetModel::correlation() const { return rho_; }
668
669inline const QuantLib::ext::shared_ptr<Integrator> CrossAssetModel::integrator() const { return integrator_; }
670
671inline Handle<DefaultProbabilityTermStructure> CrossAssetModel::crTs(const Size i) const {
673 return crlgm1f(i)->termStructure();
675 return crcirpp(i)->termStructure();
676 QL_FAIL("model at " << i << " is not CR-*");
677}
678
679inline std::pair<Real, Real> CrossAssetModel::crS(const Size i, const Size ccy, const Time t, const Time T,
680 const Real z, const Real y) const {
682 return crlgm1fS(i, ccy, t, T, z, y);
684 QL_REQUIRE(ccy == 0, "CrossAssetModelPlus::crS() only implemented for ccy=0, got " << ccy);
685 return crcirppS(i, t, T, z, y);
686 }
687 QL_FAIL("model at " << i << " is not CR-*");
688}
689
690std::ostream& operator<<(std::ostream& out, const CrossAssetModel::AssetType& type);
691
692} // namespace QuantExt
693
694#endif
CIR ++ parametrisation.
virtual void initializeParametrizations()
const QuantLib::ext::shared_ptr< Parametrization > eq(const Size i) const
virtual void checkModelConsistency() const
Size pIdx(const AssetType t, const Size i, const Size offset=0) const
std::vector< std::vector< Size > > auxBrownians_
const QuantLib::ext::shared_ptr< InfDkParametrization > infdk(const Size i) const
static constexpr Size numberOfAssetTypes
virtual Size getNumberOfStateVariables(const Size i) const
virtual Handle< DefaultProbabilityTermStructure > crTs(const Size i) const
Size cIdx(const AssetType t, const Size i, const Size offset=0) const
const QuantLib::ext::shared_ptr< Parametrization > com(const Size i) const
Size comIndex(const std::string &comName) const
Size arguments(const AssetType t, const Size i) const
std::vector< std::vector< Size > > numArguments_
void setCorrelation(const AssetType s, const Size i, const AssetType t, const Size j, const Real value, const Size iOffset=0, const Size jOffset=0)
void calibrateInfDkVolatilitiesIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Real discountBondOption(const Size ccy, Option::Type type, const Real K, const Time t, const Time S, const Time T, Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
void calibrateInfDkReversionsGlobal(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
QuantLib::Real discountBond(const Size ccy, const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >()) const
void calibrateInfJyGlobal(QuantLib::Size index, const std::vector< QuantLib::ext::shared_ptr< QuantLib::CalibrationHelper > > &helpers, QuantLib::OptimizationMethod &method, const QuantLib::EndCriteria &endCriteria, const std::map< QuantLib::Size, bool > &toCalibrate, const QuantLib::Constraint &constraint=QuantLib::Constraint(), const std::vector< QuantLib::Real > &weights=std::vector< QuantLib::Real >())
virtual Size getNumberOfAuxBrownians(const Size i) const
std::vector< std::vector< Size > > cIdx_
Discretization discretization() const
std::pair< Real, Real > infdkV(const Size i, const Time t, const Time T)
virtual Size getNumberOfBrownians(const Size i) const
Real bankAccountNumeraire(const Size ccy, const Time t, const Real x, const Real y, Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
const QuantLib::ext::shared_ptr< Integrator > integrator() const
QuantLib::ext::shared_ptr< CrossAssetStateProcess > stateProcess() const
const QuantLib::ext::shared_ptr< IrLgm1fParametrization > irlgm1f(const Size ccy) const
const QuantLib::ext::shared_ptr< EqBsParametrization > eqbs(const Size ccy) const
const QuantLib::ext::shared_ptr< InfJyParameterization > infjy(const Size i) const
Inflation JY component.
void calibrateBsVolatilitiesIterative(const AssetType &assetType, const Size aIdx, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
virtual void initializeCorrelation()
Size crName(const std::string &name) const
void calibrateIrLgm1fVolatilitiesIterative(const Size ccy, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
void calibrateInfDkVolatilitiesGlobal(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
void calibrateCrLgm1fReversionsIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size infIndex(const std::string &index) const
std::pair< Real, Real > crlgm1fS(const Size i, const Size ccy, const Time t, const Time T, const Real z, const Real y) const
void setIntegrationPolicy(const QuantLib::ext::shared_ptr< Integrator > integrator, const bool usePiecewiseIntegration=true) const
Size ccyIndex(const Currency &ccy) const
virtual Size getNumberOfParameters(const Size i) const
std::vector< std::vector< ModelType > > modelType_
std::pair< Real, Real > crcirppS(const Size i, const Time t, const Time T, const Real y, const Real s) const
virtual void initializeArguments()
QuantLib::ext::shared_ptr< CrossAssetStateProcess > stateProcess_
boost::unordered_map< cache_key, std::pair< Real, Real >, cache_hasher > cache_crlgm1fS_
const QuantLib::ext::shared_ptr< CrStateParametrization > crstateParam(const Size index) const
const QuantLib::ext::shared_ptr< CrLgm1fParametrization > crlgm1f(const Size i) const
virtual std::pair< AssetType, ModelType > getComponentType(const Size i) const
void generateArguments() override
std::vector< std::vector< Size > > pIdx_
std::vector< bool > MoveParameter(const AssetType t, const Size param, const Size index, const Size i)
const QuantLib::ext::shared_ptr< CrCirppParametrization > crcirpp(const Size i) const
virtual void initDefaultIntegrator()
const QuantLib::ext::shared_ptr< CrCirpp > crcirppModel(const Size i) const
virtual std::pair< Real, Real > crS(const Size i, const Size ccy, const Time t, const Time T, const Real z, const Real y) const
const std::vector< QuantLib::ext::shared_ptr< Parametrization > > & parametrizations() const
Real infdkYY(const Size i, const Time t, const Time S, const Time T, const Real z, const Real y, const Real irz)
std::vector< Size > components_
const QuantLib::ext::shared_ptr< FxModel > fxModel(const Size ccy) const
std::vector< QuantLib::ext::shared_ptr< Parametrization > > p_
std::vector< QuantLib::ext::shared_ptr< CrCirpp > > crcirppModel_
const QuantLib::ext::shared_ptr< Parametrization > fx(const Size ccy) const
void calibrateCrLgm1fVolatilitiesIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size eqIndex(const std::string &eqName) const
SalvagingAlgorithm::Type salvaging_
std::vector< QuantLib::ext::shared_ptr< IrModel > > irModels_
std::pair< Real, Real > infdkI(const Size i, const Time t, const Time T, const Real z, const Real y)
void updateIndices(const AssetType &t, const Size i, const Size cIdx, const Size wIdx, const Size pIdx, const Size aIdx)
const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > combs(const Size ccy) const
Real infV(const Size idx, const Size ccy, const Time t, const Time T) const
std::vector< std::vector< Size > > brownians_
void calibrateInfDkReversionsIterative(const Size index, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
Size aIdx(const AssetType t, const Size i, const Size offset=0) const
std::vector< std::vector< Size > > idx_
Size wIdx(const AssetType t, const Size i, const Size offset=0) const
QuantLib::Real numeraire(const Size ccy, const QuantLib::Time t, const QuantLib::Array &x, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const QuantLib::Array &aux=Array()) const
void calibrateIrLgm1fReversionsIterative(const Size ccy, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
void calibrateInfJyIterative(QuantLib::Size inflationModelIndex, QuantLib::Size parameterIndex, const std::vector< QuantLib::ext::shared_ptr< QuantLib::CalibrationHelper > > &helpers, QuantLib::OptimizationMethod &method, const QuantLib::EndCriteria &endCriteria, const QuantLib::Constraint &constraint=QuantLib::Constraint(), const std::vector< QuantLib::Real > &weights=std::vector< QuantLib::Real >())
Real crV(const Size idx, const Size ccy, const Time t, const Time T) const
Size idx(const AssetType t, const Size i) const
boost::unordered_map< cache_key, std::pair< Real, Real >, cache_hasher > cache_infdkI_
CrossAssetModel(const std::vector< QuantLib::ext::shared_ptr< Parametrization > > &parametrizations, const Matrix &correlation, SalvagingAlgorithm::Type salvaging, IrModel::Measure measure, const Discretization discretization, const bool)
void calibrateBsVolatilitiesGlobal(const AssetType &assetType, const Size aIdx, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
QuantLib::ext::shared_ptr< Integrator > integrator_
ModelType modelType(const AssetType t, const Size i) const
std::vector< QuantLib::ext::shared_ptr< FxModel > > fxModels_
std::vector< std::vector< Size > > stateVariables_
void appendToFixedParameterVector(const AssetType t, const AssetType v, const Size param, const Size index, const Size i, std::vector< bool > &res)
const QuantLib::ext::shared_ptr< IrHwParametrization > irhw(const Size ccy) const
const QuantLib::ext::shared_ptr< Parametrization > cr(const Size i) const
const QuantLib::ext::shared_ptr< CommodityModel > comModel(const Size com) const
std::vector< std::vector< Size > > aIdx_
Size components(const AssetType t) const
Size stateVariables(const AssetType t, const Size i) const
std::vector< QuantLib::ext::shared_ptr< CommodityModel > > comModels_
std::vector< std::vector< Size > > wIdx_
const QuantLib::ext::shared_ptr< LinearGaussMarkovModel > lgm(const Size ccy) const
const QuantLib::ext::shared_ptr< IrModel > irModel(const Size ccy) const
const QuantLib::ext::shared_ptr< Parametrization > inf(const Size i) const
const QuantLib::ext::shared_ptr< Parametrization > ir(const Size ccy) const
Real reducedDiscountBond(const Size ccy, const Time t, const Time T, const Real x, Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
const QuantLib::ext::shared_ptr< Parametrization > crstate(const Size i) const
const QuantLib::ext::shared_ptr< FxBsParametrization > fxbs(const Size ccy) const
const Matrix & correlation() const
SalvagingAlgorithm::Type salvagingAlgorithm() const
void calibrateIrLgm1fGlobal(const Size ccy, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &helpers, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >())
IrModel::Measure measure() const
const QuantLib::ext::shared_ptr< HwModel > hw(const Size ccy) const
Calibrated model class with linkable parameters.
const QuantLib::ext::shared_ptr< Constraint > & constraint() const
EndCriteria::Type endCriteria() const
Returns end criteria result.
Real value(const Array &params, const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &)
Commodity model base class.
Schwartz (1997) one-factor model of the commodity price termstructure.
Schwartz commodity model parametrization.
CIR++ credit model class.
Credit Linear Gaussian Markov 1 factor parametrization.
crossasset model state process
credit state parametrization
EQ Black Scholes parametrization.
fx black scholes model
FX Black Scholes parametrization.
hull white n Factor model class
Inflation Dodgson Kainth parametrization.
Jarrow Yildrim inflation parameterization.
lgm model class
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
Handle< ZeroInflationTermStructure > inflationTermStructure(const QuantLib::ext::shared_ptr< CrossAssetModel > &model, Size index)
std::size_t operator()(cache_key const &x) const
bool operator==(const cache_key &o) const