Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
BlackVarianceSurfaceStdDevs Class Reference

#include <qle/termstructures/blackvariancesurfacestddevs.hpp>

+ Inheritance diagram for BlackVarianceSurfaceStdDevs:
+ Collaboration diagram for BlackVarianceSurfaceStdDevs:

Public Member Functions

 BlackVarianceSurfaceStdDevs (const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > &times, 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)
 
- Public Member Functions inherited from BlackVarianceSurfaceMoneyness
 BlackVarianceSurfaceMoneyness (const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > &times, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, bool stickyStrike, bool flatExtrapMoneyness=false)
 
 BlackVarianceSurfaceMoneyness (const Date &referenceDate, const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > &times, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, bool stickyStrike, bool flatExtrapMoneyness=false)
 Moneyness variance surface with a fixed reference date. More...
 
Date maxDate () const override
 
Real minStrike () const override
 
Real maxStrike () const override
 
void update () override
 
void performCalculations () const override
 
virtual void accept (AcyclicVisitor &) override
 
std::vector< QuantLib::Real > moneyness () const
 

Static Public Member Functions

static void populateVolMatrix (const QuantLib::Handle< QuantLib::BlackVolTermStructure > &termStructre, std::vector< std::vector< Handle< QuantLib::Quote > > > &quotesToPopulate, const std::vector< Real > &times, const std::vector< Real > &stdDevPoints, const QuantLib::Interpolation &forwardCurve, const QuantLib::Interpolation atmVolCurve)
 

Private Member Functions

virtual Real moneyness (Time t, Real strike) const override
 

Private Attributes

QuantLib::ext::shared_ptr< EqFxIndexBaseindex_
 
std::vector< Real > forwards_
 
Interpolation forwardCurve_
 
Interpolation atmVarCurve_
 
std::vector< Time > atmTimes_
 
std::vector< Real > atmVariances_
 
bool flatExtrapolateMoneyness_
 

Additional Inherited Members

- Protected Member Functions inherited from BlackVarianceSurfaceMoneyness
- Protected Attributes inherited from BlackVarianceSurfaceMoneyness
bool stickyStrike_
 
Handle< Quote > spot_
 
std::vector< Time > times_
 
std::vector< Real > moneyness_
 
bool flatExtrapMoneyness_
 

Detailed Description

Black volatility surface based on forward moneyness

Definition at line 40 of file blackvariancesurfacestddevs.hpp.

Constructor & Destructor Documentation

◆ BlackVarianceSurfaceStdDevs()

BlackVarianceSurfaceStdDevs ( const Calendar &  cal,
const Handle< Quote > &  spot,
const std::vector< Time > &  times,
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 
)

Definition at line 28 of file blackvariancesurfacestddevs.cpp.

32 : BlackVarianceSurfaceMoneyness(cal, spot, times, stdDevs, blackVolMatrix, dayCounter, stickyStrike), index_(index),
33 flatExtrapolateMoneyness_(flatExtrapMoneyness) {
34
35 // set up atm variance curve - maybe just take ATM vols in
36 vector<Real>::const_iterator it = find(stdDevs.begin(), stdDevs.end(), 0.0);
37 QL_REQUIRE(it != stdDevs.end(), "atm D is required."); // this might fail
38 atmVariances_.push_back(Real(0.0));
39 atmTimes_.push_back(0.0);
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]);
43 atmTimes_.push_back(times[i]);
44 }
45 atmVarCurve_ = Linear().interpolate(atmTimes_.begin(), atmTimes_.end(), atmVariances_.begin());
46
47 if (!stickyStrike) {
48 QL_REQUIRE(index_ != nullptr, "index required for vol surface");
49 registerWith(index_);
50 } else {
51 for (Size i = 0; i < times_.size(); i++) {
52 Time t = times_[i];
53 Real fwd = index_->forecastFixing(t);
54 forwards_.push_back(fwd);
55 }
56 forwardCurve_ = Linear().interpolate(times_.begin(), times_.end(), forwards_.begin());
57 }
58}
BlackVarianceSurfaceMoneyness(const Calendar &cal, const Handle< Quote > &spot, const std::vector< Time > &times, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &blackVolMatrix, const DayCounter &dayCounter, bool stickyStrike, bool flatExtrapMoneyness=false)
QuantLib::ext::shared_ptr< EqFxIndexBase > index_

Member Function Documentation

◆ populateVolMatrix()

void populateVolMatrix ( const QuantLib::Handle< QuantLib::BlackVolTermStructure > &  termStructre,
std::vector< std::vector< Handle< QuantLib::Quote > > > &  quotesToPopulate,
const std::vector< Real > &  times,
const std::vector< Real > &  stdDevPoints,
const QuantLib::Interpolation &  forwardCurve,
const QuantLib::Interpolation  atmVolCurve 
)
static

Definition at line 92 of file blackvariancesurfacestddevs.cpp.

96 {
97
98 // check that quotesToPopulate container has the correct dimensions
99
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() << ")");
108 }
109
110 // populate quotesToPopulate container
111
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);
118 }
119 }
120}
RandomVariable sqrt(RandomVariable x)
CompiledFormula exp(CompiledFormula x)
+ Here is the call graph for this function:

◆ moneyness()

Real moneyness ( Time  t,
Real  strike 
) const
overrideprivatevirtual

Implements BlackVarianceSurfaceMoneyness.

Definition at line 60 of file blackvariancesurfacestddevs.cpp.

60 {
61 Real fwd;
62 Real reqD; // for flat extrapolation
63 Real atmVolAtT;
64 if (t == 0) {
65 atmVolAtT = 0;
66 } else {
67 atmVolAtT = sqrt(atmVarCurve_(t, true) / t);
68 }
69
70 if (strike == Null<Real>() || strike == 0) {
71 return 0.0;
72 } else {
73 if (stickyStrike_)
74 fwd = forwardCurve_(t, true);
75 else
76 fwd = index_->forecastFixing(t);
77 Real num = log(strike / fwd);
78 Real denom = atmVolAtT * sqrt(t);
79 reqD = num / denom;
80
82 if (reqD < moneyness_.front()) {
83 reqD = moneyness_.front();
84 } else if (reqD > moneyness_.back()) {
85 reqD = moneyness_.back();
86 }
87 }
88 return reqD;
89 }
90}
CompiledFormula log(CompiledFormula x)
+ Here is the call graph for this function:

Member Data Documentation

◆ index_

QuantLib::ext::shared_ptr<EqFxIndexBase> index_
private

Definition at line 62 of file blackvariancesurfacestddevs.hpp.

◆ forwards_

std::vector<Real> forwards_
private

Definition at line 63 of file blackvariancesurfacestddevs.hpp.

◆ forwardCurve_

Interpolation forwardCurve_
private

Definition at line 64 of file blackvariancesurfacestddevs.hpp.

◆ atmVarCurve_

Interpolation atmVarCurve_
private

Definition at line 65 of file blackvariancesurfacestddevs.hpp.

◆ atmTimes_

std::vector<Time> atmTimes_
private

Definition at line 66 of file blackvariancesurfacestddevs.hpp.

◆ atmVariances_

std::vector<Real> atmVariances_
private

Definition at line 67 of file blackvariancesurfacestddevs.hpp.

◆ flatExtrapolateMoneyness_

bool flatExtrapolateMoneyness_
private

Definition at line 68 of file blackvariancesurfacestddevs.hpp.