31#include <ql/math/optimization/levenbergmarquardt.hpp>
32#include <ql/models/shortrate/calibrationhelpers/swaptionhelper.hpp>
33#include <ql/pricingengines/swaption/blackswaptionengine.hpp>
34#include <ql/quotes/simplequote.hpp>
43HwBuilder::HwBuilder(
const QuantLib::ext::shared_ptr<ore::data::Market>& market,
const QuantLib::ext::shared_ptr<HwModelData>& data,
45 const bool evaluateBankAccount,
const std::string& configuration,
const Real bootstrapTolerance,
46 const bool continueOnError,
const std::string& referenceCalibrationGrid,
47 const bool setCalibrationInfo)
48 : market_(market), configuration_(configuration), data_(
data), measure_(measure), discretization_(discretization),
50 referenceCalibrationGrid_(referenceCalibrationGrid),
52 endCriteria_(EndCriteria(1000, 500, 1E-8, 1E-8, 1E-8))
58 QuantLib::ext::shared_ptr<IborIndex> index;
69 QL_REQUIRE(!
requiresCalibration_,
"HwBuilder: HwModel does not support calibration at the moment.");
90 alwaysForwardNotifications();
98 Array sigmaTimes(
data_->sigmaTimes().begin(),
data_->sigmaTimes().end());
99 Array kappaTimes(
data_->kappaTimes().begin(),
data_->kappaTimes().end());
100 std::vector<Matrix> sigma(
data_->sigmaValues().begin(),
data_->sigmaValues().end());
101 std::vector<Array> kappa(
data_->kappaValues().begin(),
data_->kappaValues().end());
104 "HwBuilder: only constant sigma is supported at the moment");
106 "HwBuilder: only constant sigma is supported at the moment");
109 QL_REQUIRE(
data_->sigmaTimes().size() == 0,
110 "HwBuilder: empty volatility time grid expected for constant parameter type");
111 QL_REQUIRE(
data_->sigmaValues().size() == 1,
112 "HwBuilder: initial volatility values should have size 1 for constant parameter type");
115 if (
data_->sigmaTimes().size() > 0) {
116 DLOG(
"overriding alpha time grid with swaption expiries, set all initial values to first given value");
120 sigma = std::vector<Matrix>(sigmaTimes.size() + 1,
data_->sigmaValues()[0]);
122 QL_REQUIRE(sigma.size() == sigmaTimes.size() + 1,
123 "HwBBuilder: hw volatility time and initial value array sizes do not match");
126 QL_FAIL(
"HwBuilder: volatility parameter type not covered");
130 QL_REQUIRE(
data_->kappaTimes().size() == 0,
131 "HwBuilder: empty reversion time grid expected for constant parameter type");
132 QL_REQUIRE(
data_->kappaValues().size() == 1,
133 "HwBuidler: initial reversion values should have size 1 for constant parameter type");
136 if (
data_->kappaTimes().size() > 0) {
137 DLOG(
"overriding h time grid with swaption underlying maturities, set all initial values to first "
141 kappa = std::vector<Array>(kappaTimes.size() + 1,
data_->kappaValues()[0]);
143 QL_REQUIRE(kappa.size() == kappaTimes.size() + 1,
"HwBuilder:: hw kappa grids do not match");
146 QL_FAIL(
"HwBuilder: reversion parameter type case not covered");
148 DLOGGERSTREAM(
"before calibration: sigma times = " << sigmaTimes);
149 DLOGGERSTREAM(
"before calibration: kappa times = " << kappaTimes);
152 QuantLib::ext::make_shared<QuantExt::IrHwConstantParametrization>(
ccy,
modelDiscountCurve_, sigma[0], kappa[0]);
154 DLOG(
"alpha times size: " << sigmaTimes.size());
155 DLOG(
"lambda times size: " << kappaTimes.size());
190 DLOG(
"Recalibrate HW model for qualifier " <<
data_->qualifier() <<
" currency " <<
currency_);
virtual void forceRecalculate()
std::vector< bool > swaptionActive_
Handle< SwapIndex > swapIndex_
QuantLib::ext::shared_ptr< QuantExt::IrHwParametrization > parametrization() const
IrModel::Measure measure_
const std::string configuration_
void forceRecalculate() override
void performCalculations() const override
QuantLib::ext::shared_ptr< QuantExt::MarketObserver > marketObserver_
QuantLib::ext::shared_ptr< QuantExt::HwModel > model_
bool evaluateBankAccount_
Array swaptionMaturities_
QuantLib::ext::shared_ptr< QuantExt::HwModel > model() const
HwBuilder(const QuantLib::ext::shared_ptr< ore::data::Market > &market, const QuantLib::ext::shared_ptr< HwModelData > &data, const IrModel::Measure measure=IrModel::Measure::BA, const HwModel::Discretization discretization=HwModel::Discretization::Euler, const bool evaluateBankAccount=true, const std::string &configuration=Market::defaultConfiguration, Real bootstrapTolerance=0.001, const bool continueOnError=false, const std::string &referenceCalibrationGrid="", const bool setCalibrationInfo=false)
HwModel::Discretization discretization_
QuantLib::ext::shared_ptr< HwModelData > data_
bool requiresRecalibration() const override
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > swaptionBasket() const
Handle< YieldTermStructure > calibrationDiscountCurve_
QuantLib::ext::shared_ptr< ore::data::Market > market_
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > swaptionBasket_
Handle< SwapIndex > shortSwapIndex_
QuantLib::ext::shared_ptr< QuantExt::IrHwParametrization > parametrization_
bool requiresCalibration_
Real error() const
Return calibration error.
Handle< QuantLib::SwaptionVolatilityStructure > svts_
RelinkableHandle< YieldTermStructure > modelDiscountCurve_
bool tryParseIborIndex(const string &s, QuantLib::ext::shared_ptr< IborIndex > &index)
Try to convert std::string to QuantLib::IborIndex.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
#define LOG(text)
Logging Macro (Level = Notice)
#define DLOG(text)
Logging Macro (Level = Debug)
#define DLOGGERSTREAM(text)
Shared utilities for model building and calibration.
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
Error for model calibration / building.