18#include <boost/make_shared.hpp>
19#include <ql/math/interpolations/bilinearinterpolation.hpp>
20#include <ql/math/interpolations/linearinterpolation.hpp>
21#include <ql/quotes/simplequote.hpp>
22#include <ql/termstructures/yield/forwardcurve.hpp>
23#include <ql/utilities/dataformatters.hpp>
31 const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
const std::vector<Real>& moneyness,
32 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
const DayCounter& dayCounter,
bool stickyStrike,
33 bool flatExtrapMoneyness)
35 times_(times), moneyness_(moneyness), flatExtrapMoneyness_(flatExtrapMoneyness), quotes_(blackVolMatrix) {
40 const Date& referenceDate,
const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
41 const std::vector<Real>& moneyness,
const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
42 const DayCounter& dayCounter,
bool stickyStrike,
bool flatExtrapMoneyness)
44 times_(times), moneyness_(moneyness), flatExtrapMoneyness_(flatExtrapMoneyness), quotes_(blackVolMatrix) {
49 TermStructure::update();
54 for (Size j = 1; j <
variances_.columns(); j++) {
56 Real vol =
quotes_[i][j - 1]->value();
65 QL_REQUIRE(
times_.size() ==
quotes_.front().size(),
"mismatch between times vector and vol matrix columns");
66 QL_REQUIRE(
moneyness_.size() ==
quotes_.size(),
"mismatch between moneyness vector and vol matrix rows");
68 QL_REQUIRE(
times_[0] > 0,
"The first time must be greater than 0.0.");
72 spot_ = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(
spot_->value()));
82 for (Size j = 1; j <
times_.size(); j++) {
84 QL_REQUIRE(
times_[j] >
times_[j - 1],
"Times must be sorted and unique but found that the "
85 << io::ordinal(j) <<
" time, " <<
times_[j]
86 <<
", is not greater than the " << io::ordinal(j - 1) <<
" time, "
90 registerWith(
quotes_[i][j - 1]);
118 const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
const std::vector<Real>& moneyness,
119 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
const DayCounter& dayCounter,
bool stickyStrike,
120 bool flatExtrapMoneyness)
122 flatExtrapMoneyness) {}
125 const Date& referenceDate,
const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
126 const std::vector<Real>& moneyness,
const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
127 const DayCounter& dayCounter,
bool stickyStrike,
bool flatExtrapMoneyness)
129 stickyStrike, flatExtrapMoneyness) {}
132 if (strike == Null<Real>() || strike == 0) {
148 const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
const std::vector<Real>& moneyness,
149 const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
const DayCounter& dayCounter,
150 const Handle<YieldTermStructure>& forTS,
const Handle<YieldTermStructure>& domTS,
bool stickyStrike,
151 bool flatExtrapMoneyness)
153 flatExtrapMoneyness),
154 forTS_(forTS), domTS_(domTS) {
159 const Date& referenceDate,
const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
160 const std::vector<Real>& moneyness,
const std::vector<std::vector<Handle<Quote> > >& blackVolMatrix,
161 const DayCounter& dayCounter,
const Handle<YieldTermStructure>& forTS,
const Handle<YieldTermStructure>& domTS,
162 bool stickyStrike,
bool flatExtrapMoneyness)
164 stickyStrike, flatExtrapMoneyness),
165 forTS_(forTS), domTS_(domTS) {
172 QL_REQUIRE(!
forTS_.empty(),
"foreign discount curve required for atmf surface");
173 QL_REQUIRE(!
domTS_.empty(),
"domestic discount curve required for atmf surface");
177 for (Size i = 0; i <
times_.size(); i++) {
189 if (strike == Null<Real>() || strike == 0)
196 reqMoneyness = strike / fwd;
200 }
else if ((strike / fwd) >
moneyness_.back()) {
Black volatility surface based on forward moneyness.
Handle< YieldTermStructure > domTS_
std::vector< Real > forwards_
QuantLib::Interpolation forwardCurve_
Handle< YieldTermStructure > forTS_
BlackVarianceSurfaceMoneynessForward(const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > ×, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, const Handle< YieldTermStructure > &forTS, const Handle< YieldTermStructure > &domTS, bool stickyStrike=false, bool flatExtrapMoneyness=false)
Abstract Black volatility surface based on moneyness (moneyness defined in subclasses)
void performCalculations() const override
BlackVarianceSurfaceMoneyness(const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > ×, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, bool stickyStrike, bool flatExtrapMoneyness=false)
Real blackVarianceMoneyness(Time t, Real moneyness) const
bool flatExtrapMoneyness_
std::vector< Time > times_
std::vector< QuantLib::Real > moneyness() const
Interpolation2D varianceSurface_
virtual Real blackVarianceImpl(Time t, Real strike) const override
std::vector< std::vector< Handle< Quote > > > quotes_
std::vector< Real > moneyness_
BlackVarianceSurfaceMoneynessSpot(const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > ×, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, bool stickyStrike=false, bool flatExtrapMoneyness=false)