20#include <ql/quotes/all.hpp>
29 const Calendar& cal,
const Handle<Quote>& spot,
const std::vector<Time>& times,
const std::vector<Real>& stdDevs,
30 const std::vector<std::vector<Handle<Quote>>>& blackVolMatrix,
const DayCounter& dayCounter,
31 const QuantLib::ext::shared_ptr<EqFxIndexBase>& index,
bool stickyStrike,
bool flatExtrapMoneyness)
33 flatExtrapolateMoneyness_(flatExtrapMoneyness) {
36 vector<Real>::const_iterator it = find(stdDevs.begin(), stdDevs.end(), 0.0);
37 QL_REQUIRE(it != stdDevs.end(),
"atm D is required.");
40 Size atmIndex = distance(stdDevs.begin(), it);
41 for (Size i = 0; i < times.size(); i++) {
42 atmVariances_.push_back(blackVolMatrix[atmIndex][i]->value() * blackVolMatrix[atmIndex][i]->value() * times[i]);
48 QL_REQUIRE(
index_ !=
nullptr,
"index required for vol surface");
51 for (Size i = 0; i <
times_.size(); i++) {
53 Real fwd =
index_->forecastFixing(t);
70 if (strike == Null<Real>() || strike == 0) {
76 fwd =
index_->forecastFixing(t);
77 Real num =
log(strike / fwd);
78 Real denom = atmVolAtT *
sqrt(t);
93 const QuantLib::Handle<QuantLib::BlackVolTermStructure>& termStructre,
94 vector<vector<Handle<Quote>>>& quotesToPopulate,
const std::vector<Real>& times,
95 const std::vector<Real>& stdDevPoints,
const QuantLib::Interpolation& forwardCurve,
96 const QuantLib::Interpolation atmVolCurve) {
100 QL_REQUIRE(quotesToPopulate.size() == stdDevPoints.size(),
101 "BlackVarianceSurfaceStdDevs::populateVolMatrix(): quotesToPopulate size ("
102 << quotesToPopulate.size() <<
") does not match stdDevPoints size (" << stdDevPoints.size() <<
")");
103 for (Size i = 0; i < stdDevPoints.size(); ++i) {
104 QL_REQUIRE(quotesToPopulate[i].size() == times.size(),
105 "BlackVarianceSurfaceStdDevs::populateVolMatrix(): quotesToPopulate["
106 << i <<
"] size (" << quotesToPopulate[i].size() <<
") does not match times size ("
107 << times.size() <<
")");
112 for (Size j = 0; j < times.size(); j++) {
113 for (Size i = 0; i < stdDevPoints.size(); i++) {
114 Real tmpStrike = forwardCurve(times[j]) *
exp(atmVolCurve(times[j]) *
sqrt(times[j]) * stdDevPoints[i]);
115 Volatility vol = termStructre->blackVol(times[j], tmpStrike,
true);
116 QuantLib::ext::shared_ptr<QuantLib::SimpleQuote> q(
new SimpleQuote(vol));
117 quotesToPopulate[i][j] = Handle<Quote>(q);
Black volatility surface modeled as variance surface.
Abstract Black volatility surface based on moneyness (moneyness defined in subclasses)
std::vector< Time > times_
std::vector< QuantLib::Real > moneyness() const
std::vector< Real > moneyness_
BlackVarianceSurfaceStdDevs(const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > ×, const std::vector< Real > &stdDevs, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, const QuantLib::ext::shared_ptr< EqFxIndexBase > &index, bool stickyStrike=false, bool flatExtrapMoneyness=false)
Interpolation atmVarCurve_
QuantLib::ext::shared_ptr< EqFxIndexBase > index_
Interpolation forwardCurve_
std::vector< Time > atmTimes_
std::vector< Real > forwards_
std::vector< Real > atmVariances_
static void populateVolMatrix(const QuantLib::Handle< QuantLib::BlackVolTermStructure > &termStructre, std::vector< std::vector< Handle< QuantLib::Quote > > > "esToPopulate, const std::vector< Real > ×, const std::vector< Real > &stdDevPoints, const QuantLib::Interpolation &forwardCurve, const QuantLib::Interpolation atmVolCurve)
bool flatExtrapolateMoneyness_
RandomVariable sqrt(RandomVariable x)
CompiledFormula exp(CompiledFormula x)
CompiledFormula log(CompiledFormula x)