24#ifndef quantext_stripped_optionlet_adapter_h
25#define quantext_stripped_optionlet_adapter_h
28#include <ql/math/interpolation.hpp>
29#include <ql/termstructures/interpolatedcurve.hpp>
30#include <ql/termstructures/volatility/flatsmilesection.hpp>
31#include <ql/termstructures/volatility/interpolatedsmilesection.hpp>
32#include <ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp>
33#include <ql/termstructures/volatility/optionlet/strippedoptionletbase.hpp>
34#include <ql/utilities/dataformatters.hpp>
50template <
class TimeInterpolator,
class SmileInterpolator>
58 const TimeInterpolator& ti = TimeInterpolator(),
59 const SmileInterpolator& si = SmileInterpolator());
64 const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
65 const TimeInterpolator& ti = TimeInterpolator(),
66 const SmileInterpolator& si = SmileInterpolator());
70 QuantLib::Date
maxDate()
const override;
75 QuantLib::Rate
minStrike()
const override;
76 QuantLib::Rate
maxStrike()
const override;
98 QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>
optionletBase()
const;
104 QuantLib::ext::shared_ptr<QuantLib::SmileSection>
smileSectionImpl(QuantLib::Time optionTime)
const override;
105 QuantLib::Volatility
volatilityImpl(QuantLib::Time length, QuantLib::Rate strike)
const override;
130template <
class TimeInterpolator,
class SmileInterpolator>
132 const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
const TimeInterpolator& ti,
133 const SmileInterpolator& si)
134 : OptionletVolatilityStructure(sob->settlementDays(), sob->calendar(), sob->businessDayConvention(),
136 optionletBase_(sob), ti_(ti), si_(si), strikeSections_(optionletBase_->optionletMaturities()) {
141template <
class TimeInterpolator,
class SmileInterpolator>
143 const QuantLib::Date& referenceDate,
const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>& sob,
144 const TimeInterpolator& ti,
const SmileInterpolator& si)
145 : OptionletVolatilityStructure(referenceDate, sob->calendar(), sob->businessDayConvention(), sob->dayCounter()),
146 optionletBase_(sob), ti_(ti), si_(si), strikeSections_(optionletBase_->optionletMaturities()) {
151template <
class TimeInterpolator,
class SmileInterpolator>
153 return optionletBase_->optionletFixingDates().back();
156template <
class TimeInterpolator,
class SmileInterpolator>
161 if (volatilityType() == QuantLib::ShiftedLognormal) {
162 return displacement() > 0.0 ? -displacement() : 0.0;
169 QuantLib::Rate minStrike = optionletBase_->optionletStrikes(0).front();
170 for (QuantLib::Size i = 1; i < optionletBase_->optionletMaturities(); ++i) {
171 minStrike = std::min(optionletBase_->optionletStrikes(i).front(), minStrike);
176template <
class TimeInterpolator,
class SmileInterpolator>
185 QuantLib::Rate maxStrike = optionletBase_->optionletStrikes(0).back();
186 for (QuantLib::Size i = 1; i < optionletBase_->optionletMaturities(); ++i) {
187 maxStrike = std::max(optionletBase_->optionletStrikes(i).back(), maxStrike);
192template <
class TimeInterpolator,
class SmileInterpolator>
194 return optionletBase_->volatilityType();
197template <
class TimeInterpolator,
class SmileInterpolator>
199 return optionletBase_->displacement();
202template <
class TimeInterpolator,
class SmileInterpolator>
207 optionletBase_->update();
209 TermStructure::update();
210 LazyObject::update();
213template <
class TimeInterpolator,
class SmileInterpolator>
217 using QuantLib::Rate;
218 using QuantLib::Size;
219 using QuantLib::Volatility;
227 for (Size i = 0; i < optionletBase_->optionletMaturities(); ++i) {
228 const vector<Rate>&
strikes = optionletBase_->optionletStrikes(i);
229 const vector<Volatility>& vols = optionletBase_->optionletVolatilities(i);
230 strikeSections_[i] = si_.interpolate(
strikes.begin(),
strikes.end(), vols.begin());
232 strikeSections_[i].enableExtrapolation();
236template <
class TimeInterpolator,
class SmileInterpolator>
238 optionletBase_->update();
242template <
class TimeInterpolator,
class SmileInterpolator>
243inline QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase>
245 return optionletBase_;
248template <
class TimeInterpolator,
class SmileInterpolator>
249inline QuantLib::ext::shared_ptr<QuantLib::SmileSection>
253 using QuantLib::Null;
254 using QuantLib::Rate;
255 using QuantLib::Real;
256 using QuantLib::Size;
257 using QuantLib::Volatility;
258 using QuantLib::io::ordinal;
264 Real atmRate = Null<Real>();
268 Volatility vol = volatility(optionTime, optionletBase_->optionletStrikes(0)[0],
true);
269 return QuantLib::ext::make_shared<QuantLib::FlatSmileSection>(optionTime, vol, optionletBase_->dayCounter(), atmRate,
270 volatilityType(), displacement());
276 const vector<Rate>&
strikes = optionletBase_->optionletStrikes(0);
279 vector<Real> stdDevs;
280 for (Size i = 0; i <
strikes.size(); i++) {
281 stdDevs.push_back(
sqrt(blackVariance(optionTime,
strikes[i],
true)));
285 return QuantLib::ext::make_shared<QuantLib::InterpolatedSmileSection<SmileInterpolator> >(
286 optionTime,
strikes, stdDevs, atmRate, si_, optionletBase_->dayCounter(), volatilityType(), displacement());
289template <
class TimeInterpolator,
class SmileInterpolator>
290inline QuantLib::Volatility
292 QuantLib::Rate strike)
const {
295 using QuantLib::Interpolation;
296 using QuantLib::Size;
297 using QuantLib::Time;
298 using QuantLib::Volatility;
303 vector<Volatility> vols(optionletBase_->optionletMaturities());
304 for (Size i = 0; i < optionletBase_->optionletMaturities(); ++i) {
305 vols[i] = oneStrike_ ? optionletBase_->optionletVolatilities(i)[0] : strikeSections_[i](strike);
308 vector<Time> fixingTimes = optionletBase_->optionletFixingTimes();
309 Interpolation ti = ti_.interpolate(fixingTimes.begin(), fixingTimes.end(), vols.begin());
313 ti.enableExtrapolation();
315 return ti(optionTime);
318template <
class TimeInterpolator,
class SmileInterpolator>
321 for (QuantLib::Size i = 0; i < optionletBase_->optionletMaturities(); ++i) {
322 if (optionletBase_->optionletStrikes(i).size() > 1) {
void performCalculations() const override
QuantLib::Real displacement() const override
TimeInterpolator ti_
The interpolation object in the time direction.
StrippedOptionletAdapter(const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &sob, const TimeInterpolator &ti=TimeInterpolator(), const SmileInterpolator &si=SmileInterpolator())
void deepUpdate() override
void populateOneStrike()
Method to populate oneStrike_ on initialisation.
QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase_
Base optionlet object that provides the stripped optionlet volatilities.
QuantLib::VolatilityType volatilityType() const override
bool oneStrike_
Flag that indicates if optionletBase_ has only one strike for all option tenors.
SmileInterpolator si_
The interpolation object in the strike direction.
QuantLib::ext::shared_ptr< QuantLib::SmileSection > smileSectionImpl(QuantLib::Time optionTime) const override
QuantLib::Date maxDate() const override
QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase() const
QuantLib::Rate minStrike() const override
QuantLib::Rate maxStrike() const override
std::vector< QuantLib::Interpolation > strikeSections_
QuantLib::Volatility volatilityImpl(QuantLib::Time length, QuantLib::Rate strike) const override
RandomVariable sqrt(RandomVariable x)