54 blackTS_(blackTS), riskFreeTS_(
std::move(riskFreeTS)), dividendTS_(
std::move(dividendTS)),
55 underlying_(
std::move(underlying)) {
67 blackTS_(blackTS), riskFreeTS_(
std::move(riskFreeTS)), dividendTS_(
std::move(dividendTS)),
90 Real strike,
y, dy, strikep, strikem;
91 Real w, wp, wm, dwdy, d2wdy2;
92 strike = underlyingLevel;
93 y = std::log(strike/forwardValue);
94 dy = ((std::fabs(
y) > 0.001) ?
Real(
y*0.0001) : 0.000001);
95 strikep=strike*std::exp(dy);
96 strikem=strike/std::exp(dy);
97 w =
blackTS_->blackVariance(
t, strike,
true);
98 wp =
blackTS_->blackVariance(
t, strikep,
true);
99 wm =
blackTS_->blackVariance(
t, strikem,
true);
100 dwdy = (wp-wm)/(2.0*dy);
101 d2wdy2 = (wp-2.0*w+wm)/(dy*dy);
104 Real dt, wpt, wmt, dwdt;
109 Real strikept = strike*dr*dqpt/(drpt*dq);
111 wpt =
blackTS_->blackVariance(
t+dt, strikept,
true);
113 "decreasing variance at strike " << strike
114 <<
" between time " <<
t <<
" and time " <<
t+dt);
117 dt = std::min<Time>(0.0001,
t/2.0);
123 Real strikept = strike*dr*dqpt/(drpt*dq);
124 Real strikemt = strike*dr*dqmt/(drmt*dq);
126 wpt =
blackTS_->blackVariance(
t+dt, strikept,
true);
127 wmt =
blackTS_->blackVariance(
t-dt, strikemt,
true);
130 "decreasing variance at strike " << strike
131 <<
" between time " <<
t <<
" and time " <<
t+dt);
133 "decreasing variance at strike " << strike
134 <<
" between time " <<
t-dt <<
" and time " <<
t);
136 dwdt = (wpt-wmt)/(2.0*dt);
139 if (dwdy==0.0 && d2wdy2==0.0) {
140 return std::sqrt(dwdt);
142 Real den1 = 1.0 -
y/w*dwdy;
143 Real den2 = 0.25*(-0.25 - 1.0/w +
y*
y/w/w)*dwdy*dwdy;
144 Real den3 = 0.5*d2wdy2;
145 Real den = den1+den2+den3;
146 Real result = dwdt / den;
149 "negative local vol^2 at strike " << strike
151 <<
"; the black vol surface is not smooth enough");
153 return std::sqrt(result);
Black volatility term structure base classes.
degenerate base class for the Acyclic Visitor pattern
Shared handle to an observable.
LocalVolSurface(const Handle< BlackVolTermStructure > &blackTS, Handle< YieldTermStructure > riskFreeTS, Handle< YieldTermStructure > dividendTS, Handle< Quote > underlying)
Handle< Quote > underlying_
Volatility localVolImpl(Time, Real) const override
local vol calculation
const Date & referenceDate() const override
the date at which discount = 1.0 and/or variance = 0.0
Real minStrike() const override
the minimum strike for which the term structure can return vols
void accept(AcyclicVisitor &) override
Handle< BlackVolTermStructure > blackTS_
DayCounter dayCounter() const override
the day counter used for date/time conversion
Handle< YieldTermStructure > riskFreeTS_
Date maxDate() const override
the latest date for which the curve can return values
Handle< YieldTermStructure > dividendTS_
Real maxStrike() const override
the maximum strike for which the term structure can return vols
virtual void accept(AcyclicVisitor &)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
purely virtual base class for market observables
market element returning a stored value
Visitor for a specific class
virtual void visit(T &)=0
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
Real Volatility
volatility
Local volatility surface derived from a Black vol surface.
ext::shared_ptr< BlackVolTermStructure > v
Interest-rate term structure.