21#include <ql/termstructures/volatility/flatsmilesection.hpp>
26 const QuantLib::ext::shared_ptr<SwaptionVolatilityStructure>& source, Natural settlementDays,
const Calendar& calendar,
28 : SwaptionVolatilityStructure(settlementDays, calendar, source->businessDayConvention(), source->dayCounter()),
29 source_(source), decayMode_(decayMode), originalReferenceDate_(source->referenceDate()),
30 volatilityType_(source->volatilityType()) {}
35 Time swapLength)
const {
37 return QuantLib::ext::make_shared<FlatSmileSection>(optionTime,
volatilityImpl(optionTime, swapLength, Null<Real>()),
44 Real tf =
source_->timeFromReference(referenceDate());
45 if (
source_->volatilityType() == ShiftedLognormal) {
47 "DynamicSwaptionVolatilityMatrix: Shift must be constant in option time direction");
49 Real realisedVariance =
50 source_->blackVariance(tf + optionTime, swapLength, strike) -
51 (tf > 0.0 && !
close_enough(tf, 0.0) ?
source_->blackVariance(tf, swapLength, strike) : 0.0);
52 return std::sqrt(std::max(realisedVariance / optionTime, 1E-6));
55 return source_->volatility(optionTime, swapLength, strike);
57 QL_FAIL(
"unexpected decay mode (" <<
decayMode_ <<
")");
61 if (
source_->volatilityType() == Normal) {
65 Real tf =
source_->timeFromReference(referenceDate());
66 return source_->shift(tf + optionTime, swapLength);
69 return source_->shift(optionTime, swapLength);
71 QL_FAIL(
"unexpected decay mode (" <<
decayMode_ <<
")");
83 return Date(std::min(Date::maxDate().serialNumber(), referenceDate().serialNumber() -
85 source_->maxDate().serialNumber()));
87 QL_FAIL(
"unexpected decay mode (" <<
decayMode_ <<
")");
Volatility volatilityImpl(Time optionTime, Time swapLength, Rate strike) const override
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime, Time swapLength) const override
Real minStrike() const override
Real shiftImpl(Time optionTime, Time swapLength) const override
DynamicSwaptionVolatilityMatrix(const QuantLib::ext::shared_ptr< SwaptionVolatilityStructure > &source, Natural settlementDays, const Calendar &calendar, ReactionToTimeDecay decayMode=ConstantVariance)
ReactionToTimeDecay decayMode_
Date maxDate() const override
const Date originalReferenceDate_
const QuantLib::ext::shared_ptr< SwaptionVolatilityStructure > source_
Real maxStrike() const override
const Period & maxSwapTenor() const override
dynamic swaption volatility matrix
ReactionToTimeDecay
Reaction to Time Decay.
Filter close_enough(const RandomVariable &x, const RandomVariable &y)