Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
lgmbuilder.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/lgmbuilder.hpp
20 \brief Build an lgm model
21 \ingroup models
22*/
23
24#pragma once
25
26#include <map>
27#include <ostream>
28#include <vector>
29
30#include <qle/models/lgm.hpp>
31
35
36namespace ore {
37namespace data {
38using namespace QuantLib;
39
40//! Builder for a Linear Gauss Markov model component
41/*!
42 This class is a utility that turns a Linear Gauss Markov
43 model description into an interest rate model parametrisation which
44 can be used to instantiate a CrossAssetModel.
45
46 \ingroup models
47 */
49public:
50 /*! The configuration refers to the configuration to read swaption vol and swap index from the market.
51 The discounting curve to price calibrating swaptions is derived from the swap index directly though,
52 i.e. it is not read as a discount curve from the market (except as a fallback in case we do not find
53 the swap index). */
54 LgmBuilder(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const QuantLib::ext::shared_ptr<IrLgmData>& data,
55 const std::string& configuration = Market::defaultConfiguration, Real bootstrapTolerance = 0.001,
56 const bool continueOnError = false, const std::string& referenceCalibrationGrid = "",
57 const bool setCalibrationInfo = false, const std::string& id = "unknwon");
58 //! Return calibration error
59 Real error() const;
60
61 //! \name Inspectors
62 //@{
63 std::string qualifier() { return data_->qualifier(); }
64 std::string ccy() { return currency_; }
65 QuantLib::ext::shared_ptr<QuantExt::LGM> model() const;
66 /* The curve used to build the lgm parametrization. This is initially the swap index discount curve (see ctor). It
67 can be relinked later outside this builder to calibrate fx processes, for which one wants to use a xccy curve
68 instead of the in-ccy curve that is used to calibrate the LGM model within this builder. */
69 RelinkableHandle<YieldTermStructure> discountCurve() { return modelDiscountCurve_; }
70 QuantLib::ext::shared_ptr<QuantExt::IrLgm1fParametrization> parametrization() const;
71 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> swaptionBasket() const;
72 //@}
73
74 //! \name ModelBuilder interface
75 //@{
76 void forceRecalculate() override;
77 bool requiresRecalibration() const override;
78 //@}
79
80private:
81 void performCalculations() const override;
82 void buildSwaptionBasket() const;
83 void updateSwaptionBasketVols() const;
84 std::string getBasketDetails(QuantExt::LgmCalibrationInfo& info) const;
85 // checks whether swaption vols have changed compared to cache and updates the cache if requested
86 bool volSurfaceChanged(const bool updateCache) const;
87 // populate expiry and term
88 void getExpiryAndTerm(const Size j, Period& expiryPb, Period& termPb, Date& expiryDb, Date& termDb, Real& termT,
89 bool& expiryDateBased, bool& termDateBased) const;
90 // get strike for jth option (or Null<Real>() if ATM)
91 Real getStrike(const Size j) const;
92
93 QuantLib::ext::shared_ptr<ore::data::Market> market_;
94 const std::string configuration_;
95 QuantLib::ext::shared_ptr<IrLgmData> data_;
97 const bool continueOnError_;
98 const std::string referenceCalibrationGrid_;
100 const std::string id_;
102 std::string currency_; // derived from data->qualifier()
103
104 mutable Real error_;
105 mutable QuantLib::ext::shared_ptr<QuantExt::LGM> model_;
106 mutable Array params_;
107 mutable QuantLib::ext::shared_ptr<QuantExt::IrLgm1fParametrization> parametrization_;
108
109 // which swaptions in data->optionExpries() are actually in the basket?
110 mutable std::vector<bool> swaptionActive_;
111 mutable std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> swaptionBasket_;
112 mutable std::vector<Real> swaptionStrike_;
113 mutable std::vector<QuantLib::ext::shared_ptr<SimpleQuote>> swaptionBasketVols_;
114 mutable Array swaptionExpiries_;
115 mutable Array swaptionMaturities_;
117
118 Handle<QuantLib::SwaptionVolatilityStructure> svts_;
119 Handle<SwapIndex> swapIndex_, shortSwapIndex_;
120 RelinkableHandle<YieldTermStructure> modelDiscountCurve_;
121 Handle<YieldTermStructure> calibrationDiscountCurve_;
122
123 // TODO: Move CalibrationErrorType, optimizer and end criteria parameters to data
124 QuantLib::ext::shared_ptr<OptimizationMethod> optimizationMethod_;
125 EndCriteria endCriteria_;
126 BlackCalibrationHelper::CalibrationErrorType calibrationErrorType_;
127
128 // Cache the swaption volatilities
129 mutable std::vector<QuantLib::Real> swaptionVolCache_;
130
131 bool forceCalibration_ = false;
132
133 // LGM Observer
134 QuantLib::ext::shared_ptr<QuantExt::MarketObserver> marketObserver_;
135};
136} // namespace data
137} // namespace ore
Builder for a Linear Gauss Markov model component.
Definition: lgmbuilder.hpp:48
std::vector< bool > swaptionActive_
Definition: lgmbuilder.hpp:110
Handle< SwapIndex > swapIndex_
Definition: lgmbuilder.hpp:119
const std::string configuration_
Definition: lgmbuilder.hpp:94
void forceRecalculate() override
Definition: lgmbuilder.cpp:692
BlackCalibrationHelper::CalibrationErrorType calibrationErrorType_
Definition: lgmbuilder.hpp:126
void performCalculations() const override
Definition: lgmbuilder.cpp:325
bool volSurfaceChanged(const bool updateCache) const
Definition: lgmbuilder.cpp:508
std::string getBasketDetails(QuantExt::LgmCalibrationInfo &info) const
Definition: lgmbuilder.cpp:674
QuantLib::ext::shared_ptr< QuantExt::IrLgm1fParametrization > parametrization() const
Definition: lgmbuilder.cpp:310
QuantLib::ext::shared_ptr< QuantExt::MarketObserver > marketObserver_
Definition: lgmbuilder.hpp:134
void updateSwaptionBasketVols() const
Definition: lgmbuilder.cpp:552
const bool continueOnError_
Definition: lgmbuilder.hpp:97
const Real bootstrapTolerance_
Definition: lgmbuilder.hpp:96
std::vector< QuantLib::ext::shared_ptr< SimpleQuote > > swaptionBasketVols_
Definition: lgmbuilder.hpp:113
const std::string id_
Definition: lgmbuilder.hpp:100
QuantLib::ext::shared_ptr< QuantExt::IrLgm1fParametrization > parametrization_
Definition: lgmbuilder.hpp:107
bool requiresRecalibration() const override
Definition: lgmbuilder.cpp:320
RelinkableHandle< YieldTermStructure > discountCurve()
Definition: lgmbuilder.hpp:69
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > swaptionBasket() const
Definition: lgmbuilder.cpp:315
Handle< YieldTermStructure > calibrationDiscountCurve_
Definition: lgmbuilder.hpp:121
std::vector< QuantLib::Real > swaptionVolCache_
Definition: lgmbuilder.hpp:129
EndCriteria endCriteria_
Definition: lgmbuilder.hpp:125
std::vector< Real > swaptionStrike_
Definition: lgmbuilder.hpp:112
QuantLib::ext::shared_ptr< OptimizationMethod > optimizationMethod_
Definition: lgmbuilder.hpp:124
QuantLib::ext::shared_ptr< ore::data::Market > market_
Definition: lgmbuilder.hpp:93
Real getStrike(const Size j) const
Definition: lgmbuilder.cpp:494
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > swaptionBasket_
Definition: lgmbuilder.hpp:111
void buildSwaptionBasket() const
Definition: lgmbuilder.cpp:557
Handle< SwapIndex > shortSwapIndex_
Definition: lgmbuilder.hpp:119
const std::string referenceCalibrationGrid_
Definition: lgmbuilder.hpp:98
std::string ccy()
Definition: lgmbuilder.hpp:64
std::string qualifier()
Definition: lgmbuilder.hpp:63
Real error() const
Return calibration error.
Definition: lgmbuilder.cpp:300
QuantLib::ext::shared_ptr< IrLgmData > data_
Definition: lgmbuilder.hpp:95
void getExpiryAndTerm(const Size j, Period &expiryPb, Period &termPb, Date &expiryDb, Date &termDb, Real &termT, bool &expiryDateBased, bool &termDateBased) const
Definition: lgmbuilder.cpp:467
QuantLib::ext::shared_ptr< QuantExt::LGM > model() const
Definition: lgmbuilder.cpp:305
QuantLib::ext::shared_ptr< QuantExt::LGM > model_
Definition: lgmbuilder.hpp:105
const bool setCalibrationInfo_
Definition: lgmbuilder.hpp:99
Handle< QuantLib::SwaptionVolatilityStructure > svts_
Definition: lgmbuilder.hpp:118
RelinkableHandle< YieldTermStructure > modelDiscountCurve_
Definition: lgmbuilder.hpp:120
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
IR component data for the cross asset model.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23