Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
DynamicBlackVolTermStructure< mode > Class Template Reference

Takes a BlackVolTermStructure with fixed reference date and turns it into a floating reference date term structure. More...

#include <qle/termstructures/dynamicblackvoltermstructure.hpp>

+ Inheritance diagram for DynamicBlackVolTermStructure< mode >:
+ Collaboration diagram for DynamicBlackVolTermStructure< mode >:

Public Member Functions

 DynamicBlackVolTermStructure (const Handle< BlackVolTermStructure > &source, Natural settlementDays, const Calendar &calendar, ReactionToTimeDecay decayMode=ConstantVariance, Stickyness stickyness=StickyLogMoneyness, const Handle< YieldTermStructure > &riskfree=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &dividend=Handle< YieldTermStructure >(), const Handle< Quote > &spot=Handle< Quote >(), const std::vector< Real > initialForwardGrid=std::vector< Real >())
 
Real atm () const
 
Real minStrike () const override
 
Real maxStrike () const override
 
Date maxDate () const override
 
void update () override
 

Protected Member Functions

Real blackVarianceImpl (Time t, Real strike) const override
 
Volatility blackVolImpl (Time t, Real strike) const override
 
Real blackVarianceImplTag (Time t, Real strike, tag::curve) const
 
Real blackVarianceImplTag (Time t, Real strike, tag::surface) const
 

Private Attributes

const Handle< BlackVolTermStructuresource_
 
ReactionToTimeDecay decayMode_
 
Stickyness stickyness_
 
const Handle< YieldTermStructure > riskfree_
 
const Handle< YieldTermStructure > dividend_
 
const Handle< Quote > spot_
 
const Date originalReferenceDate_
 
const bool atmKnown_
 
std::vector< Real > forwardCurveSampleGrid_
 
std::vector< Real > initialForwards_
 
QuantLib::ext::shared_ptr< Interpolation > initialForwardCurve_
 

Detailed Description

template<typename mode = tag::surface>
class QuantExt::DynamicBlackVolTermStructure< mode >

Takes a BlackVolTermStructure with fixed reference date and turns it into a floating reference date term structure.

This class takes a BlackVolTermStructure with fixed reference date and turns it into a floating reference date term structure. There are different ways of reacting to time decay that can be specified. As an additional feature, the class will return the ATM volatility if a null strike is given (currently, for this extrapolation must be allowed, since there is a check in VolatilityTermStructure we can no extend or bypass). ATM is defined as the forward level here (which is of particular interest for FX term structures).

if curve is specified, a more efficient implementation for variance and volatility is used just passing through the given strike to the source term structure; note that in this case a null strike will not be converted to atm though.

\ingroup termstructures

Definition at line 61 of file dynamicblackvoltermstructure.hpp.

Constructor & Destructor Documentation

◆ DynamicBlackVolTermStructure()

DynamicBlackVolTermStructure ( const Handle< BlackVolTermStructure > &  source,
Natural  settlementDays,
const Calendar &  calendar,
ReactionToTimeDecay  decayMode = ConstantVariance,
Stickyness  stickyness = StickyLogMoneyness,
const Handle< YieldTermStructure > &  riskfree = Handle<YieldTermStructure>(),
const Handle< YieldTermStructure > &  dividend = Handle<YieldTermStructure>(),
const Handle< Quote > &  spot = Handle<Quote>(),
const std::vector< Real >  initialForwardGrid = std::vector<Real>() 
)

Definition at line 112 of file dynamicblackvoltermstructure.hpp.

119 : BlackVolTermStructure(settlementDays, calendar, source->businessDayConvention(), source->dayCounter()),
120 source_(source), decayMode_(decayMode), stickyness_(stickyness), riskfree_(riskfree), dividend_(dividend),
121 spot_(spot), originalReferenceDate_(source->referenceDate()),
122 atmKnown_(!riskfree.empty() && !dividend.empty() && !spot.empty()),
123 forwardCurveSampleGrid_(forwardCurveSampleGrid) {
124
125 QL_REQUIRE(stickyness == StickyStrike || stickyness == StickyLogMoneyness,
126 "stickiness (" << stickyness << ") not supported");
127 QL_REQUIRE(decayMode == ConstantVariance || decayMode == ForwardForwardVariance,
128 "reaction to time decay (" << decayMode << ") not supported");
129
130 registerWith(source);
131
132 if (stickyness != StickyStrike) {
133 QL_REQUIRE(atmKnown_, "for stickiness other than strike, the term "
134 "structures and spot must be given");
135 QL_REQUIRE(riskfree_->referenceDate() == source_->referenceDate(),
136 "at construction time the reference dates of the volatility "
137 "term structure ("
138 << source->referenceDate() << ") and the risk free yield term structure ("
139 << riskfree_->referenceDate() << ") must be the same");
140 QL_REQUIRE(dividend_->referenceDate() == source_->referenceDate(),
141 "at construction time the reference dates of the volatility "
142 "term structure ("
143 << source->referenceDate() << ") and the dividend term structure (" << riskfree_->referenceDate()
144 << ") must be the same");
145 registerWith(riskfree_);
146 registerWith(dividend_);
147 registerWith(spot_);
148 }
149
150 if (atmKnown_) {
151 if (forwardCurveSampleGrid_.size() == 0) {
152 // use default grid
153 Real tmp[] = { 0.0, 0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
154 8.0, 9.0, 10.0, 12.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0 };
155 forwardCurveSampleGrid_ = std::vector<Real>(tmp, tmp + sizeof(tmp) / sizeof(tmp[0]));
156 }
157 QL_REQUIRE(QuantLib::close_enough(forwardCurveSampleGrid_[0], 0.0),
158 "forward curve sample grid must start at 0 (" << forwardCurveSampleGrid_[0]);
160 for (Size i = 1; i < forwardCurveSampleGrid_.size(); ++i) {
162 "forward curve sample grid must have increasing times (at "
163 << (i - 1) << ", " << i << ": " << forwardCurveSampleGrid_[i - 1] << ", "
165 }
166 for (Size i = 0; i < forwardCurveSampleGrid_.size(); ++i) {
167 Real t = forwardCurveSampleGrid_[i];
168 initialForwards_[i] = spot_->value() / riskfree_->discount(t) * dividend_->discount(t);
169 }
170 initialForwardCurve_ = QuantLib::ext::make_shared<FlatExtrapolation>(QuantLib::ext::make_shared<LinearInterpolation>(
172 initialForwardCurve_->enableExtrapolation();
173 }
174}
QuantLib::ext::shared_ptr< Interpolation > initialForwardCurve_
const Handle< BlackVolTermStructure > source_
@ StickyLogMoneyness
@ ConstantVariance
@ ForwardForwardVariance

Member Function Documentation

◆ atm()

Real atm ( ) const

◆ minStrike()

Real minStrike
override

Definition at line 190 of file dynamicblackvoltermstructure.hpp.

190 {
191 if (stickyness_ == StickyStrike) {
192 return source_->minStrike();
193 }
195 // we do not specify this, since it is maturity dependent
196 // instead we allow for extrapolation when asking the
197 // source for a volatility and are not in sticky strike mode
198 return 0.0;
199 }
200 QL_FAIL("unexpected stickiness (" << stickyness_ << ")");
201}

◆ maxStrike()

Real maxStrike
override

Definition at line 203 of file dynamicblackvoltermstructure.hpp.

203 {
204 if (stickyness_ == StickyStrike) {
205 return source_->maxStrike();
206 }
208 // see above
209 return QL_MAX_REAL;
210 }
211 QL_FAIL("unexpected stickiness (" << stickyness_ << ")");
212}

◆ maxDate()

Date maxDate
override

Definition at line 178 of file dynamicblackvoltermstructure.hpp.

178 {
180 return source_->maxDate();
181 }
183 return Date(std::min(Date::maxDate().serialNumber(), referenceDate().serialNumber() -
184 originalReferenceDate_.serialNumber() +
185 source_->maxDate().serialNumber()));
186 }
187 QL_FAIL("unexpected decay mode (" << decayMode_ << ")");
188}

◆ update()

void update
override

Definition at line 176 of file dynamicblackvoltermstructure.hpp.

176{ BlackVolTermStructure::update(); }

◆ blackVarianceImpl()

Real blackVarianceImpl ( Time  t,
Real  strike 
) const
overrideprotected

Definition at line 219 of file dynamicblackvoltermstructure.hpp.

219 {
220 return blackVarianceImplTag(t, strike, mode());
221}
Real blackVarianceImplTag(Time t, Real strike, tag::curve) const

◆ blackVolImpl()

Volatility blackVolImpl ( Time  t,
Real  strike 
) const
overrideprotected

Definition at line 214 of file dynamicblackvoltermstructure.hpp.

214 {
215 Real tmp = std::max(1.0E-6, t);
216 return std::sqrt(blackVarianceImpl(tmp, strike) / tmp);
217}
Real blackVarianceImpl(Time t, Real strike) const override

◆ blackVarianceImplTag() [1/2]

Real blackVarianceImplTag ( Time  t,
Real  strike,
tag::curve   
) const
protected

Definition at line 246 of file dynamicblackvoltermstructure.hpp.

246 {
248 Real scenarioT0 = source_->timeFromReference(referenceDate());
249 Real scenarioT1 = scenarioT0 + t;
250 return std::max(0.0, source_->blackVariance(scenarioT1, strike, true) - source_->blackVariance(scenarioT0, strike, true));
251 } else {
252 return source_->blackVariance(t, strike, true);
253 }
254}

◆ blackVarianceImplTag() [2/2]

Real blackVarianceImplTag ( Time  t,
Real  strike,
tag::surface   
) const
protected

Definition at line 224 of file dynamicblackvoltermstructure.hpp.

224 {
225 if (strike == Null<Real>()) {
226 QL_REQUIRE(atmKnown_, "can not calculate atm level (null strike is "
227 "given) because a curve or the spot is missing");
228 strike = spot_->value() / riskfree_->discount(t) * dividend_->discount(t);
229 }
230 Real scenarioT0 = 0.0, scenarioT1 = t;
231 Real scenarioStrike0 = strike, scenarioStrike1 = strike;
233 scenarioT0 = source_->timeFromReference(referenceDate());
234 scenarioT1 = scenarioT0 + t;
235 }
237 Real forward = spot_->value() / riskfree_->discount(t) * dividend_->discount(t);
238 scenarioStrike1 = initialForwardCurve_->operator()(scenarioT1) / forward * strike;
239 scenarioStrike0 = initialForwardCurve_->operator()(scenarioT0) / spot_->value() * strike;
240 }
241 return std::max(0.0, source_->blackVariance(scenarioT1, scenarioStrike1, true) -
242 source_->blackVariance(scenarioT0, scenarioStrike0, true));
243}

Member Data Documentation

◆ source_

const Handle<BlackVolTermStructure> source_
private

Definition at line 100 of file dynamicblackvoltermstructure.hpp.

◆ decayMode_

ReactionToTimeDecay decayMode_
private

Definition at line 101 of file dynamicblackvoltermstructure.hpp.

◆ stickyness_

Stickyness stickyness_
private

Definition at line 102 of file dynamicblackvoltermstructure.hpp.

◆ riskfree_

const Handle<YieldTermStructure> riskfree_
private

Definition at line 103 of file dynamicblackvoltermstructure.hpp.

◆ dividend_

const Handle<YieldTermStructure> dividend_
private

Definition at line 103 of file dynamicblackvoltermstructure.hpp.

◆ spot_

const Handle<Quote> spot_
private

Definition at line 104 of file dynamicblackvoltermstructure.hpp.

◆ originalReferenceDate_

const Date originalReferenceDate_
private

Definition at line 105 of file dynamicblackvoltermstructure.hpp.

◆ atmKnown_

const bool atmKnown_
private

Definition at line 106 of file dynamicblackvoltermstructure.hpp.

◆ forwardCurveSampleGrid_

std::vector<Real> forwardCurveSampleGrid_
private

Definition at line 107 of file dynamicblackvoltermstructure.hpp.

◆ initialForwards_

std::vector<Real> initialForwards_
private

Definition at line 107 of file dynamicblackvoltermstructure.hpp.

◆ initialForwardCurve_

QuantLib::ext::shared_ptr<Interpolation> initialForwardCurve_
private

Definition at line 108 of file dynamicblackvoltermstructure.hpp.