Skip to content

Commit d28da25

Browse files
pcaspersjenkins
authored andcommitted
QPR-12325 write sabr calibration results to log
1 parent f5b6883 commit d28da25

4 files changed

Lines changed: 85 additions & 19 deletions

File tree

OREData/ored/marketdata/capfloorvolcurve.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,40 @@ void CapFloorVolCurve::buildCalibrationInfo(const Date& asof, const CurveConfigu
15921592
TLOG("Strike Spread cube arbitrage analysis completed.");
15931593
}
15941594

1595+
// output SABR calibration to log, if SABR was used
1596+
1597+
QuantLib::ext::shared_ptr<QuantExt::SabrParametricVolatility> p;
1598+
if (auto s = QuantLib::ext::dynamic_pointer_cast<SabrStrippedOptionletAdapter<Linear>>(capletVol_))
1599+
p = QuantExt::ext::dynamic_pointer_cast<SabrParametricVolatility>(s->parametricVolatility());
1600+
else if (auto s = QuantLib::ext::dynamic_pointer_cast<SabrStrippedOptionletAdapter<LinearFlat>>(capletVol_))
1601+
p = QuantExt::ext::dynamic_pointer_cast<SabrParametricVolatility>(s->parametricVolatility());
1602+
else if (auto s = QuantLib::ext::dynamic_pointer_cast<SabrStrippedOptionletAdapter<Cubic>>(capletVol_))
1603+
p = QuantExt::ext::dynamic_pointer_cast<SabrParametricVolatility>(s->parametricVolatility());
1604+
else if (auto s = QuantLib::ext::dynamic_pointer_cast<SabrStrippedOptionletAdapter<CubicFlat>>(capletVol_))
1605+
p = QuantExt::ext::dynamic_pointer_cast<SabrParametricVolatility>(s->parametricVolatility());
1606+
else if (auto s = QuantLib::ext::dynamic_pointer_cast<SabrStrippedOptionletAdapter<BackwardFlat>>(capletVol_))
1607+
p = QuantExt::ext::dynamic_pointer_cast<SabrParametricVolatility>(s->parametricVolatility());
1608+
1609+
if (p) {
1610+
DLOG("SABR parameters:");
1611+
DLOG("alpha:");
1612+
DLOGGERSTREAM(p->alpha());
1613+
DLOG("beta:");
1614+
DLOGGERSTREAM(p->beta());
1615+
DLOG("nu:");
1616+
DLOGGERSTREAM(p->nu());
1617+
DLOG("rho:");
1618+
DLOGGERSTREAM(p->rho());
1619+
DLOG("lognormal shift:");
1620+
DLOGGERSTREAM(p->lognormalShift());
1621+
DLOG("calibration attempts:");
1622+
DLOGGERSTREAM(p->numberOfCalibrationAttempts());
1623+
DLOG("calibration error:");
1624+
DLOGGERSTREAM(p->calibrationError());
1625+
DLOG("isInterpolated:");
1626+
DLOGGERSTREAM(p->isInterpolated());
1627+
}
1628+
15951629
DLOG("Building calibration info cap floor vols completed.");
15961630
}
15971631

OREData/ored/marketdata/genericyieldvolcurve.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,33 @@ GenericYieldVolCurve::GenericYieldVolCurve(
578578
}
579579

580580
DLOG("Building calibration info generic yield vols completed.");
581+
582+
// output SABR calibration to log, if SABR was used
583+
584+
if (auto sw = QuantLib::ext::dynamic_pointer_cast<QuantExt::SwaptionVolCubeWithATM>(vol_)) {
585+
if (auto sabr = QuantLib::ext::dynamic_pointer_cast<QuantExt::SwaptionSabrCube>(sw->cube())) {
586+
if (auto p = QuantLib::ext::dynamic_pointer_cast<QuantExt::SabrParametricVolatility>(
587+
sabr->parametricVolatility())) {
588+
DLOG("SABR parameters:");
589+
DLOG("alpha:");
590+
DLOGGERSTREAM(p->alpha());
591+
DLOG("beta:");
592+
DLOGGERSTREAM(p->beta());
593+
DLOG("nu:");
594+
DLOGGERSTREAM(p->nu());
595+
DLOG("rho:");
596+
DLOGGERSTREAM(p->rho());
597+
DLOG("lognormal shift:");
598+
DLOGGERSTREAM(p->lognormalShift());
599+
DLOG("calibration attempts:");
600+
DLOGGERSTREAM(p->numberOfCalibrationAttempts());
601+
DLOG("calibration error:");
602+
DLOGGERSTREAM(p->calibrationError());
603+
DLOG("isInterpolated:");
604+
DLOGGERSTREAM(p->isInterpolated());
605+
}
606+
}
607+
}
581608
}
582609

583610
} catch (std::exception& e) {

QuantExt/qle/termstructures/sabrstrippedoptionletadapter.hpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SabrStrippedOptionletAdapter : public QuantLib::OptionletVolatilityStructu
4646
/*! Constructor that does not take a reference date. The settlement days is derived from \p sob and the term
4747
structure will be a \e moving term structure.
4848
*/
49-
SabrStrippedOptionletAdapter(const boost::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
49+
SabrStrippedOptionletAdapter(const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
5050
const QuantExt::SabrParametricVolatility::ModelVariant modelVariant,
5151
const TimeInterpolator& ti = TimeInterpolator(),
5252
const boost::optional<QuantLib::VolatilityType> outputVolatilityType = boost::none,
@@ -58,7 +58,7 @@ class SabrStrippedOptionletAdapter : public QuantLib::OptionletVolatilityStructu
5858
/*! Constructor taking an explicit \p referenceDate and the term structure will therefore be not \e moving.
5959
*/
6060
SabrStrippedOptionletAdapter(const QuantLib::Date& referenceDate,
61-
const boost::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
61+
const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
6262
const QuantExt::SabrParametricVolatility::ModelVariant modelVariant,
6363
const TimeInterpolator& ti = TimeInterpolator(),
6464
const boost::optional<QuantLib::VolatilityType> outputVolatilityType = boost::none,
@@ -97,19 +97,22 @@ class SabrStrippedOptionletAdapter : public QuantLib::OptionletVolatilityStructu
9797

9898
//! \name Inspectors
9999
//@{
100-
boost::shared_ptr<QuantLib::StrippedOptionletBase> optionletBase() const;
100+
QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase> optionletBase() const;
101+
QuantLib::ext::shared_ptr<QuantExt::ParametricVolatility> parametricVolatility() const {
102+
return parametricVolatility_;
103+
}
101104
//@}
102105

103106
protected:
104107
//! \name OptionletVolatilityStructure interface
105108
//@{
106-
boost::shared_ptr<QuantLib::SmileSection> smileSectionImpl(QuantLib::Time optionTime) const override;
109+
QuantLib::ext::shared_ptr<QuantLib::SmileSection> smileSectionImpl(QuantLib::Time optionTime) const override;
107110
QuantLib::Volatility volatilityImpl(QuantLib::Time length, QuantLib::Rate strike) const override;
108111
//@}
109112

110113
private:
111114
//! Base optionlet object that provides the stripped optionlet volatilities
112-
boost::shared_ptr<QuantLib::StrippedOptionletBase> optionletBase_;
115+
QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase> optionletBase_;
113116

114117
//! The interpolation object in the time direction
115118
TimeInterpolator ti_;
@@ -123,14 +126,14 @@ class SabrStrippedOptionletAdapter : public QuantLib::OptionletVolatilityStructu
123126
QuantLib::Real maxAcceptableError_;
124127

125128
//! State
126-
mutable std::map<Real, boost::shared_ptr<ParametricVolatilitySmileSection>> cache_;
127-
mutable boost::shared_ptr<ParametricVolatility> parametricVolatility_;
129+
mutable std::map<Real, QuantLib::ext::shared_ptr<ParametricVolatilitySmileSection>> cache_;
130+
mutable QuantLib::ext::shared_ptr<ParametricVolatility> parametricVolatility_;
128131
mutable std::unique_ptr<FlatExtrapolation> atmInterpolation_;
129132
};
130133

131134
template <class TimeInterpolator>
132135
SabrStrippedOptionletAdapter<TimeInterpolator>::SabrStrippedOptionletAdapter(
133-
const boost::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
136+
const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
134137
const QuantExt::SabrParametricVolatility::ModelVariant modelVariant, const TimeInterpolator& ti,
135138
const boost::optional<QuantLib::VolatilityType> outputVolatilityType,
136139
const std::vector<std::pair<Real, bool>>& initialModelParameters, const QuantLib::Size maxCalibrationAttempts,
@@ -145,7 +148,7 @@ SabrStrippedOptionletAdapter<TimeInterpolator>::SabrStrippedOptionletAdapter(
145148

146149
template <class TimeInterpolator>
147150
SabrStrippedOptionletAdapter<TimeInterpolator>::SabrStrippedOptionletAdapter(
148-
const QuantLib::Date& referenceDate, const boost::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
151+
const QuantLib::Date& referenceDate, const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
149152
const QuantExt::SabrParametricVolatility::ModelVariant modelVariant, const TimeInterpolator& ti,
150153
const boost::optional<QuantLib::VolatilityType> outputVolatilityType,
151154
const std::vector<std::pair<Real, bool>>& initialModelParameters, const QuantLib::Size maxCalibrationAttempts,
@@ -192,7 +195,7 @@ template <class TimeInterpolator>
192195
inline void SabrStrippedOptionletAdapter<TimeInterpolator>::performCalculations() const {
193196
cache_.clear();
194197

195-
atmInterpolation_ = std::make_unique<FlatExtrapolation>(boost::make_shared<LinearInterpolation>(
198+
atmInterpolation_ = std::make_unique<FlatExtrapolation>(QuantLib::ext::make_shared<LinearInterpolation>(
196199
this->optionletBase()->optionletFixingTimes().begin(), this->optionletBase()->optionletFixingTimes().end(),
197200
this->optionletBase()->atmOptionletRates().begin()));
198201
atmInterpolation_->enableExtrapolation();
@@ -214,7 +217,7 @@ inline void SabrStrippedOptionletAdapter<TimeInterpolator>::performCalculations(
214217
initialModelParameters_;
215218
}
216219

217-
parametricVolatility_ = boost::make_shared<SabrParametricVolatility>(
220+
parametricVolatility_ = QuantLib::ext::make_shared<SabrParametricVolatility>(
218221
modelVariant_, marketSmiles, ParametricVolatility::MarketModelType::Black76,
219222
volatilityType() == QuantLib::Normal ? ParametricVolatility::MarketQuoteType::NormalVolatility
220223
: ParametricVolatility::MarketQuoteType::ShiftedLognormalVolatility,
@@ -228,21 +231,21 @@ template <class TimeInterpolator> inline void SabrStrippedOptionletAdapter<TimeI
228231
}
229232

230233
template <class TimeInterpolator>
231-
inline boost::shared_ptr<QuantLib::StrippedOptionletBase>
234+
inline QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>
232235
SabrStrippedOptionletAdapter<TimeInterpolator>::optionletBase() const {
233236
return optionletBase_;
234237
}
235238

236239
template <class TimeInterpolator>
237-
inline boost::shared_ptr<QuantLib::SmileSection>
240+
inline QuantLib::ext::shared_ptr<QuantLib::SmileSection>
238241
SabrStrippedOptionletAdapter<TimeInterpolator>::smileSectionImpl(QuantLib::Time optionTime) const {
239242
calculate();
240243
if (auto c = cache_.find(optionTime); c != cache_.end()) {
241244
return c->second;
242245
}
243246
Real forward = atmInterpolation_->operator()(optionTime);
244247
QuantLib::VolatilityType outVolType = outputVolatilityType_ ? *outputVolatilityType_ : volatilityType();
245-
auto tmp = boost::make_shared<ParametricVolatilitySmileSection>(
248+
auto tmp = QuantLib::ext::make_shared<ParametricVolatilitySmileSection>(
246249
optionTime, Null<Real>(), forward, parametricVolatility_,
247250
outVolType == QuantLib::Normal ? ParametricVolatility::MarketQuoteType::NormalVolatility
248251
: ParametricVolatility::MarketQuoteType::ShiftedLognormalVolatility);

QuantExt/qle/termstructures/swaptionsabrcube.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ class SwaptionSabrCube : public SwaptionVolatilityCube {
3939
const std::vector<Period>& atmOptionTenors, const std::vector<Period>& atmSwapLengths,
4040
const std::vector<Spread>& strikeSpreads,
4141
const std::vector<std::vector<Handle<Quote>>>& volSpreads,
42-
const boost::shared_ptr<SwapIndex>& swapIndexBase,
43-
const boost::shared_ptr<SwapIndex>& shortSwapIndexBase,
42+
const QuantLib::ext::shared_ptr<SwapIndex>& swapIndexBase,
43+
const QuantLib::ext::shared_ptr<SwapIndex>& shortSwapIndexBase,
4444
const QuantExt::SabrParametricVolatility::ModelVariant modelVariant,
4545
const boost::optional<QuantLib::VolatilityType> outputVolatilityType = boost::none,
4646
const std::vector<std::pair<Real, bool>>& initialModelParameters = {},
4747
const QuantLib::Size maxCalibrationAttempts = 10,
4848
const QuantLib::Real exitEarlyErrorThreshold = 0.005,
4949
const QuantLib::Real maxAcceptableError = 0.05);
5050
void performCalculations() const override;
51-
boost::shared_ptr<SmileSection> smileSectionImpl(Time optionTime, Time swapLength) const override;
51+
QuantLib::ext::shared_ptr<SmileSection> smileSectionImpl(Time optionTime, Time swapLength) const override;
52+
53+
QuantLib::ext::shared_ptr<ParametricVolatility> parametricVolatility() const { return parametricVolatility_; }
5254

5355
private:
54-
mutable std::map<std::pair<Real, Real>, boost::shared_ptr<ParametricVolatilitySmileSection>> cache_;
55-
mutable boost::shared_ptr<ParametricVolatility> parametricVolatility_;
56+
mutable std::map<std::pair<Real, Real>, QuantLib::ext::shared_ptr<ParametricVolatilitySmileSection>> cache_;
57+
mutable QuantLib::ext::shared_ptr<ParametricVolatility> parametricVolatility_;
5658
std::vector<Period> atmOptionTenors_, atmSwapTenors_;
5759
QuantExt::SabrParametricVolatility::ModelVariant modelVariant_;
5860
boost::optional<QuantLib::VolatilityType> outputVolatilityType_;

0 commit comments

Comments
 (0)