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

Abstract Spreaded Black volatility surface based on moneyness (moneyness defined in subclasses) More...

#include <qle/termstructures/spreadedblackvolatilitysurfacemoneyness.hpp>

+ Inheritance diagram for SpreadedBlackVolatilitySurfaceMoneyness:
+ Collaboration diagram for SpreadedBlackVolatilitySurfaceMoneyness:

Public Member Functions

 SpreadedBlackVolatilitySurfaceMoneyness (const Handle< BlackVolTermStructure > &referenceVol, const Handle< Quote > &movingSpot, const std::vector< Time > &times, const std::vector< Real > &moneyness, const std::vector< std::vector< Handle< Quote > > > &volSpreads, const Handle< Quote > &stickySpot, const Handle< YieldTermStructure > &stickyDividendTs, const Handle< YieldTermStructure > &stickyRiskFreeTs, const Handle< YieldTermStructure > &movingDividendTs, const Handle< YieldTermStructure > &movingRiskFreeTs, bool stickyStrike)
 
Date maxDate () const override
 
const Date & referenceDate () const override
 
Calendar calendar () const override
 
Natural settlementDays () const override
 
Real minStrike () const override
 
Real maxStrike () const override
 
void update () override
 
const std::vector< QuantLib::Real > & moneyness () const
 

Protected Member Functions

virtual Real strikeFromMoneyness (Time t, Real moneyness, const bool stickyReference) const =0
 
virtual Real moneynessFromStrike (Time t, Real strike, const bool stickyReference) const =0
 

Protected Attributes

Handle< BlackVolTermStructurereferenceVol_
 
Handle< Quote > movingSpot_
 
std::vector< Time > times_
 
std::vector< Real > moneyness_
 
std::vector< std::vector< Handle< Quote > > > volSpreads_
 
Handle< Quote > stickySpot_
 
Handle< YieldTermStructure > stickyDividendTs_
 
Handle< YieldTermStructure > stickyRiskFreeTs_
 
Handle< YieldTermStructure > movingDividendTs_
 
Handle< YieldTermStructure > movingRiskFreeTs_
 
bool stickyStrike_
 
Matrix data_
 
Interpolation2D volSpreadSurface_
 

Private Member Functions

void performCalculations () const override
 
Real blackVolImpl (Time t, Real strike) const override
 

Detailed Description

Abstract Spreaded Black volatility surface based on moneyness (moneyness defined in subclasses)

Definition at line 38 of file spreadedblackvolatilitysurfacemoneyness.hpp.

Constructor & Destructor Documentation

◆ SpreadedBlackVolatilitySurfaceMoneyness()

SpreadedBlackVolatilitySurfaceMoneyness ( const Handle< BlackVolTermStructure > &  referenceVol,
const Handle< Quote > &  movingSpot,
const std::vector< Time > &  times,
const std::vector< Real > &  moneyness,
const std::vector< std::vector< Handle< Quote > > > &  volSpreads,
const Handle< Quote > &  stickySpot,
const Handle< YieldTermStructure > &  stickyDividendTs,
const Handle< YieldTermStructure > &  stickyRiskFreeTs,
const Handle< YieldTermStructure > &  movingDividendTs,
const Handle< YieldTermStructure > &  movingRiskFreeTs,
bool  stickyStrike 
)

Definition at line 34 of file spreadedblackvolatilitysurfacemoneyness.cpp.

40 : BlackVolatilityTermStructure(referenceVol->businessDayConvention(), referenceVol->dayCounter()),
41 referenceVol_(referenceVol), movingSpot_(movingSpot), times_(times), moneyness_(moneyness),
42 volSpreads_(volSpreads), stickySpot_(stickySpot), stickyDividendTs_(stickyDividendTs),
43 stickyRiskFreeTs_(stickyRiskFreeTs), movingDividendTs_(movingDividendTs), movingRiskFreeTs_(movingRiskFreeTs),
44 stickyStrike_(stickyStrike) {
45
46 // register with observables
47
48 registerWith(referenceVol_);
49 registerWith(movingSpot_);
50 registerWith(stickySpot_);
51
52 for (auto const& v : volSpreads_)
53 for (auto const& s : v)
54 registerWith(s);
55
56 registerWith(stickyDividendTs_);
57 registerWith(stickyRiskFreeTs_);
58 registerWith(movingDividendTs_);
59 registerWith(movingRiskFreeTs_);
60
61 // check our preconditions on the inputs
62
63 QL_REQUIRE(!times_.empty(), "no times given");
64 QL_REQUIRE(!moneyness_.empty(), "no moneyness values given");
65 QL_REQUIRE(moneyness_.size() == volSpreads_.size(), "mismatch between moneyness vector and vol matrix rows");
66
67 for (auto const& v : volSpreads_) {
68 QL_REQUIRE(times_.size() == v.size(), "mismatch between times vector and vol matrix columns");
69 }
70
71 for (Size j = 1; j < times_.size(); ++j) {
72 QL_REQUIRE(times_[j] > times_[j - 1], "Times must be sorted and unique but found that the "
73 << io::ordinal(j) << " time, " << times_[j]
74 << ", is not greater than the " << io::ordinal(j - 1) << " time, "
75 << times_[j - 1] << ".");
76 }
77
78 // add an artificial time if there is only one to make the interpolation work
79
80 if (times_.size() == 1) {
81 times_.push_back(times_.back() + 1.0);
82 for (auto& v : volSpreads_)
83 v.push_back(v.back());
84 }
85
86 // add an artificial moneyness if there is only one to make the interpolation work
87
88 if (moneyness_.size() == 1) {
89 moneyness_.push_back(moneyness_.back() + 1.0);
90 volSpreads_.push_back(volSpreads_.back());
91 }
92
93 // create data matrix used for interpolation and the interpolation object
94
95 data_ = Matrix(moneyness_.size(), times_.size(), 0.0);
96 volSpreadSurface_ = FlatExtrapolator2D(QuantLib::ext::make_shared<BilinearInterpolation>(
97 times_.begin(), times_.end(), moneyness_.begin(), moneyness_.end(), data_));
98 volSpreadSurface_.enableExtrapolation();
99}

Member Function Documentation

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 101 of file spreadedblackvolatilitysurfacemoneyness.cpp.

101{ return referenceVol_->maxDate(); }

◆ referenceDate()

const Date & referenceDate ( ) const
override

Definition at line 102 of file spreadedblackvolatilitysurfacemoneyness.cpp.

102{ return referenceVol_->referenceDate(); }

◆ calendar()

Calendar calendar ( ) const
override

Definition at line 103 of file spreadedblackvolatilitysurfacemoneyness.cpp.

103{ return referenceVol_->calendar(); }

◆ settlementDays()

Natural settlementDays ( ) const
override

Definition at line 104 of file spreadedblackvolatilitysurfacemoneyness.cpp.

104{ return referenceVol_->settlementDays(); }

◆ minStrike()

Real minStrike ( ) const
override

Definition at line 105 of file spreadedblackvolatilitysurfacemoneyness.cpp.

105{ return referenceVol_->minStrike(); }

◆ maxStrike()

Real maxStrike ( ) const
override

Definition at line 106 of file spreadedblackvolatilitysurfacemoneyness.cpp.

106{ return referenceVol_->maxStrike(); }

◆ update()

void update ( )
override

Definition at line 108 of file spreadedblackvolatilitysurfacemoneyness.cpp.

108 {
109 LazyObject::update();
110 BlackVolatilityTermStructure::update();
111}

◆ moneyness()

const std::vector< QuantLib::Real > & moneyness ( ) const

Definition at line 113 of file spreadedblackvolatilitysurfacemoneyness.cpp.

113{ return moneyness_; }
+ Here is the caller graph for this function:

◆ strikeFromMoneyness()

virtual Real strikeFromMoneyness ( Time  t,
Real  moneyness,
const bool  stickyReference 
) const
protectedpure virtual

◆ moneynessFromStrike()

virtual Real moneynessFromStrike ( Time  t,
Real  strike,
const bool  stickyReference 
) const
protectedpure virtual

◆ performCalculations()

void performCalculations ( ) const
overrideprivate

Definition at line 115 of file spreadedblackvolatilitysurfacemoneyness.cpp.

115 {
116 for (Size j = 0; j < data_.columns(); ++j) {
117 for (Size i = 0; i < data_.rows(); ++i) {
118 data_(i, j) = volSpreads_[i][j]->value();
119 }
120 }
121 volSpreadSurface_.update();
122}

◆ blackVolImpl()

Real blackVolImpl ( Time  t,
Real  strike 
) const
overrideprivate

Definition at line 124 of file spreadedblackvolatilitysurfacemoneyness.cpp.

124 {
125 calculate();
126 QL_REQUIRE(!referenceVol_.empty(), "SpreadedBlackVolatilitySurfaceMoneyness: reference vol is empty");
127 Real m = moneynessFromStrike(t, strike, false);
128 QL_REQUIRE(std::isfinite(m),
129 "SpreadedBlackVolatilitySurfaceMoneyness: got invalid moneyness (dynamic reference) at t = "
130 << t << ", strike = " << strike << ": " << m);
131 Real effStrike;
132 if (stickyStrike_)
133 effStrike = strike;
134 else {
135 effStrike = strikeFromMoneyness(t, m, true);
136 QL_REQUIRE(std::isfinite(effStrike),
137 "SpreadedBlackVolatilitySurfaceMoneyness: got invalid strike from moneyness at t = "
138 << t << ", input strike = " << strike << ", moneyness = " << m);
139 }
140 Real m2 = moneynessFromStrike(t, strike, false);
141 QL_REQUIRE(std::isfinite(m2),
142 "SpreadedBlackVolatilitySurfaceMoneyness: got invalid moneyness (sticky reference) at t = "
143 << t << ", strike = " << strike << ": " << m2);
144 return referenceVol_->blackVol(t, effStrike) + volSpreadSurface_(t, m2);
145}
virtual Real strikeFromMoneyness(Time t, Real moneyness, const bool stickyReference) const =0
virtual Real moneynessFromStrike(Time t, Real strike, const bool stickyReference) const =0
+ Here is the call graph for this function:

Member Data Documentation

◆ referenceVol_

Handle<BlackVolTermStructure> referenceVol_
protected

Definition at line 67 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ movingSpot_

Handle<Quote> movingSpot_
protected

Definition at line 68 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ times_

std::vector<Time> times_
protected

Definition at line 69 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ moneyness_

std::vector<Real> moneyness_
protected

Definition at line 70 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ volSpreads_

std::vector<std::vector<Handle<Quote> > > volSpreads_
protected

Definition at line 71 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ stickySpot_

Handle<Quote> stickySpot_
protected

Definition at line 72 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ stickyDividendTs_

Handle<YieldTermStructure> stickyDividendTs_
protected

Definition at line 73 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ stickyRiskFreeTs_

Handle<YieldTermStructure> stickyRiskFreeTs_
protected

Definition at line 74 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ movingDividendTs_

Handle<YieldTermStructure> movingDividendTs_
protected

Definition at line 75 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ movingRiskFreeTs_

Handle<YieldTermStructure> movingRiskFreeTs_
protected

Definition at line 76 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ stickyStrike_

bool stickyStrike_
protected

Definition at line 77 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ data_

Matrix data_
mutableprotected

Definition at line 79 of file spreadedblackvolatilitysurfacemoneyness.hpp.

◆ volSpreadSurface_

Interpolation2D volSpreadSurface_
mutableprotected

Definition at line 80 of file spreadedblackvolatilitysurfacemoneyness.hpp.