Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
hwbuilder.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 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 ored/model/hwbuilder.hpp
20 \brief Build a hw model
21 \ingroup models
22*/
23
24#pragma once
25
26#include <map>
27#include <ostream>
28#include <vector>
29
33
35
36namespace ore {
37namespace data {
38using namespace QuantLib;
41
42//! Builder for a Hull White model or a HW component for the CAM
43/* TODO this has a lot of overlap with LgmBuilder, factor out common logic */
45public:
46 /*! The configuration should refer to the calibration configuration here,
47 alternative discounting curves are then usually set in the pricing
48 engines for swaptions etc. */
49 HwBuilder(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const QuantLib::ext::shared_ptr<HwModelData>& data,
50 const IrModel::Measure measure = IrModel::Measure::BA,
51 const HwModel::Discretization discretization = HwModel::Discretization::Euler,
52 const bool evaluateBankAccount = true, const std::string& configuration = Market::defaultConfiguration,
53 Real bootstrapTolerance = 0.001, const bool continueOnError = false,
54 const std::string& referenceCalibrationGrid = "", const bool setCalibrationInfo = false);
55 //! Return calibration error
56 Real error() const;
57
58 //! \name Inspectors
59 //@{
60 std::string qualifier() { return data_->qualifier(); }
61 std::string ccy() { return currency_; }
62 QuantLib::ext::shared_ptr<QuantExt::HwModel> model() const;
63 QuantLib::ext::shared_ptr<QuantExt::IrHwParametrization> parametrization() const;
64 RelinkableHandle<YieldTermStructure> discountCurve() { return modelDiscountCurve_; }
65 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> swaptionBasket() const;
66 //@}
67
68 //! \name ModelBuilder interface
69 //@{
70 void forceRecalculate() override;
71 bool requiresRecalibration() const override;
72 //@}
73
74private:
75 void performCalculations() const override;
76
77 QuantLib::ext::shared_ptr<ore::data::Market> market_;
78 const std::string configuration_;
79 QuantLib::ext::shared_ptr<HwModelData> data_;
83 // const Real bootstrapTolerance_;
84 // const bool continueOnError_;
85 const std::string referenceCalibrationGrid_;
86 // const bool setCalibrationInfo_;
88 std::string currency_; // derived from data->qualifier()
89
90 mutable Real error_;
91 mutable QuantLib::ext::shared_ptr<QuantExt::HwModel> model_;
92 mutable Array params_;
93 mutable QuantLib::ext::shared_ptr<QuantExt::IrHwParametrization> parametrization_;
94
95 // which swaptions in data->optionExpries() are actually in the basket?
96 mutable std::vector<bool> swaptionActive_;
97 mutable std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> swaptionBasket_;
98 mutable std::vector<Real> swaptionStrike_;
99 mutable std::vector<QuantLib::ext::shared_ptr<SimpleQuote>> swaptionBasketVols_;
100 mutable Array swaptionExpiries_;
101 mutable Array swaptionMaturities_;
103
104 RelinkableHandle<YieldTermStructure> modelDiscountCurve_;
105 Handle<YieldTermStructure> calibrationDiscountCurve_;
106 Handle<QuantLib::SwaptionVolatilityStructure> svts_;
107 Handle<SwapIndex> swapIndex_, shortSwapIndex_;
108
109 // TODO: Move CalibrationErrorType, optimizer and end criteria parameters to data
110 QuantLib::ext::shared_ptr<OptimizationMethod> optimizationMethod_;
111 EndCriteria endCriteria_;
112 // BlackCalibrationHelper::CalibrationErrorType calibrationErrorType_;
113
114 // Cache the swaption volatilities
115 mutable std::vector<QuantLib::Real> swaptionVolCache_;
116
117 bool forceCalibration_ = false;
118
119 // LGM Observer
120 QuantLib::ext::shared_ptr<QuantExt::MarketObserver> marketObserver_;
121};
122} // namespace data
123} // namespace ore
Builder for a Hull White model or a HW component for the CAM.
Definition: hwbuilder.hpp:44
std::vector< bool > swaptionActive_
Definition: hwbuilder.hpp:96
Handle< SwapIndex > swapIndex_
Definition: hwbuilder.hpp:107
QuantLib::ext::shared_ptr< QuantExt::IrHwParametrization > parametrization() const
Definition: hwbuilder.cpp:171
IrModel::Measure measure_
Definition: hwbuilder.hpp:80
const std::string configuration_
Definition: hwbuilder.hpp:78
void forceRecalculate() override
Definition: hwbuilder.cpp:196
void performCalculations() const override
Definition: hwbuilder.cpp:188
QuantLib::ext::shared_ptr< QuantExt::MarketObserver > marketObserver_
Definition: hwbuilder.hpp:120
QuantLib::ext::shared_ptr< QuantExt::HwModel > model_
Definition: hwbuilder.hpp:91
std::string currency_
Definition: hwbuilder.hpp:88
QuantLib::ext::shared_ptr< QuantExt::HwModel > model() const
Definition: hwbuilder.cpp:166
std::vector< QuantLib::ext::shared_ptr< SimpleQuote > > swaptionBasketVols_
Definition: hwbuilder.hpp:99
HwModel::Discretization discretization_
Definition: hwbuilder.hpp:81
QuantLib::ext::shared_ptr< HwModelData > data_
Definition: hwbuilder.hpp:79
bool requiresRecalibration() const override
Definition: hwbuilder.cpp:181
RelinkableHandle< YieldTermStructure > discountCurve()
Definition: hwbuilder.hpp:64
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > swaptionBasket() const
Definition: hwbuilder.cpp:176
Handle< YieldTermStructure > calibrationDiscountCurve_
Definition: hwbuilder.hpp:105
std::vector< QuantLib::Real > swaptionVolCache_
Definition: hwbuilder.hpp:115
EndCriteria endCriteria_
Definition: hwbuilder.hpp:111
std::vector< Real > swaptionStrike_
Definition: hwbuilder.hpp:98
QuantLib::ext::shared_ptr< OptimizationMethod > optimizationMethod_
Definition: hwbuilder.hpp:110
QuantLib::ext::shared_ptr< ore::data::Market > market_
Definition: hwbuilder.hpp:77
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > swaptionBasket_
Definition: hwbuilder.hpp:97
Handle< SwapIndex > shortSwapIndex_
Definition: hwbuilder.hpp:107
const std::string referenceCalibrationGrid_
Definition: hwbuilder.hpp:85
QuantLib::ext::shared_ptr< QuantExt::IrHwParametrization > parametrization_
Definition: hwbuilder.hpp:93
std::string ccy()
Definition: hwbuilder.hpp:61
std::string qualifier()
Definition: hwbuilder.hpp:60
Real error() const
Return calibration error.
Definition: hwbuilder.cpp:161
Handle< QuantLib::SwaptionVolatilityStructure > svts_
Definition: hwbuilder.hpp:106
RelinkableHandle< YieldTermStructure > modelDiscountCurve_
Definition: hwbuilder.hpp:104
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
Hull White model data.
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23