Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
BlackVarianceSurfaceSparse Class Reference

#include <qle/termstructures/blackvariancesurfacesparse.hpp>

+ Inheritance diagram for BlackVarianceSurfaceSparse:
+ Collaboration diagram for BlackVarianceSurfaceSparse:

Public Types

enum class  TimeInterpolationMethod { Linear , Flat }
 

Public Member Functions

 BlackVarianceSurfaceSparse (const QuantLib::Date &referenceDate, const QuantLib::Calendar &cal, const std::vector< QuantLib::Date > &dates, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Volatility > &volatilities, const QuantLib::DayCounter &dayCounter, bool lowerStrikeConstExtrap=true, bool upperStrikeConstExtrap=true, bool timeFlatExtrapolation=false)
 
TermStructure interface
QuantLib::Date maxDate () const override
 
const QuantLib::Date & referenceDate () const override
 
QuantLib::DayCounter dayCounter () const override
 
VolatilityTermStructure interface
QuantLib::Real minStrike () const override
 
QuantLib::Real maxStrike () const override
 
- Public Member Functions inherited from OptionInterpolator2d< QuantLib::Linear, QuantLib::Linear >
 OptionInterpolator2d (const QuantLib::Date &referenceDate, const QuantLib::DayCounter &dayCounter, bool lowerStrikeConstExtrap=true, bool upperStrikeConstExtrap=true, const QuantLib::Linear &interpolatorStrike=QuantLib::Linear(), const QuantLib::Linear &interpolatorExpiry=QuantLib::Linear(), const QuantLib::Date &baseDate=QuantLib::Date())
 OptionInterpolator2d default Constructor. More...
 
 OptionInterpolator2d (const QuantLib::Date &referenceDate, const QuantLib::DayCounter &dayCounter, const std::vector< QuantLib::Date > &dates, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Real > &values, bool lowerStrikeConstExtrap=true, bool upperStrikeConstExtrap=true, const QuantLib::Linear &interpolatorStrike=QuantLib::Linear(), const QuantLib::Linear &interpolatorExpiry=QuantLib::Linear(), const QuantLib::Date &baseDate=QuantLib::Date())
 OptionInterpolator2d Constructor with dates. More...
 
 OptionInterpolator2d (const QuantLib::Date &referenceDate, const QuantLib::Calendar &calendar, const QuantLib::BusinessDayConvention &bdc, const QuantLib::DayCounter &dayCounter, const std::vector< QuantLib::Period > &tenors, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Real > &values, bool lowerStrikeConstExtrap=true, bool upperStrikeConstExtrap=true, const QuantLib::Linear &interpolatorStrike=QuantLib::Linear(), const QuantLib::Linear &interpolatorExpiry=QuantLib::Linear(), const QuantLib::Date &baseDate=QuantLib::Date())
 OptionInterpolator2d Constructor with Tenors. More...
 
 OptionInterpolator2d (const OptionInterpolator2d &)=delete
 
OptionInterpolator2doperator= (const OptionInterpolator2d &)=delete
 
void initialise (const std::vector< QuantLib::Date > &dates, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Real > &values)
 Initialise. More...
 
void initialise (const std::vector< QuantLib::Period > &tenors, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Real > &values, const QuantLib::Calendar &calendar, const QuantLib::BusinessDayConvention &bdc)
 
std::vector< QuantLib::Time > times () const
 
std::vector< QuantLib::Date > expiries () const
 
std::vector< std::vector< QuantLib::Real > > strikes () const
 
std::vector< std::vector< QuantLib::Real > > values () const
 
QuantLib::DayCounter dayCounter () const
 
QuantLib::Real getValue (QuantLib::Time t, QuantLib::Real strike) const override
 virtual access methods More...
 
QuantLib::Real getValue (QuantLib::Date d, QuantLib::Real strike) const override
 
- Public Member Functions inherited from OptionInterpolatorBase
virtual ~OptionInterpolatorBase ()
 
 OptionInterpolatorBase (const QuantLib::Date &referenceDate)
 
virtual QuantLib::Real getValue (QuantLib::Time t, QuantLib::Real strike) const =0
 virtual access methods More...
 
virtual QuantLib::Real getValue (QuantLib::Date d, QuantLib::Real strike) const =0
 
const QuantLib::Date & referenceDate () const
 
std::vector< QuantLib::Time > times () const
 
std::vector< QuantLib::Date > expiries () const
 
std::vector< std::vector< QuantLib::Real > > strikes () const
 
std::vector< std::vector< QuantLib::Real > > values () const
 

Visitability

bool timeFlatExtrapolation_
 
virtual void accept (QuantLib::AcyclicVisitor &) override
 
virtual QuantLib::Real blackVarianceImpl (QuantLib::Time t, QuantLib::Real strike) const override
 

Additional Inherited Members

- Protected Attributes inherited from OptionInterpolator2d< QuantLib::Linear, QuantLib::Linear >
std::vector< QuantLib::Interpolation > interpolations_
 
- Protected Attributes inherited from OptionInterpolatorBase
std::vector< QuantLib::Date > expiries_
 
std::vector< QuantLib::Time > times_
 
std::vector< std::vector< QuantLib::Real > > strikes_
 
std::vector< std::vector< QuantLib::Real > > values_
 
QuantLib::Date referenceDate_
 

Detailed Description

Black volatility surface based on sparse matrix.

Definition at line 35 of file blackvariancesurfacesparse.hpp.

Member Enumeration Documentation

◆ TimeInterpolationMethod

enum class TimeInterpolationMethod
strong

Constructor & Destructor Documentation

◆ BlackVarianceSurfaceSparse()

BlackVarianceSurfaceSparse ( const QuantLib::Date &  referenceDate,
const QuantLib::Calendar &  cal,
const std::vector< QuantLib::Date > &  dates,
const std::vector< QuantLib::Real > &  strikes,
const std::vector< QuantLib::Volatility > &  volatilities,
const QuantLib::DayCounter &  dayCounter,
bool  lowerStrikeConstExtrap = true,
bool  upperStrikeConstExtrap = true,
bool  timeFlatExtrapolation = false 
)

Definition at line 26 of file blackvariancesurfacesparse.cpp.

31 : BlackVarianceTermStructure(referenceDate, cal), OptionInterpolator2d<Linear, Linear>(referenceDate, dayCounter,
32 lowerStrikeConstExtrap,
33 upperStrikeConstExtrap),
34 timeFlatExtrapolation_(timeFlatExtrapolation) {
35
36 QL_REQUIRE((strikes.size() == dates.size()) && (dates.size() == volatilities.size()),
37 "dates, strikes and volatilities vectors not of equal size.");
38
39 // convert volatilities to variance
40 vector<Real> variances(volatilities.size());
41 for (Size i = 0; i < volatilities.size(); i++) {
42 Time t = dayCounter.yearFraction(referenceDate, dates[i]);
43 variances[i] = volatilities[i] * volatilities[i] * t;
44 }
45
46 // variance must be 0 at time 0, add a variance of zero, time 0, for 2 strikes to ensure interpolation
47 vector<Date> modDates(dates.begin(), dates.end());
48 vector<Real> modStrikes(strikes.begin(), strikes.end());
49 vector<Real> tempStrikes;
50 tempStrikes.push_back(1.0);
51 tempStrikes.push_back(100.0);
52 for (Size i = 0; i < tempStrikes.size(); i++) {
53 modDates.push_back(referenceDate);
54 modStrikes.push_back(tempStrikes[i]);
55 variances.push_back(0.0);
56 }
57
58 initialise(modDates, modStrikes, variances);
59}
QuantLib::DayCounter dayCounter() const override
const QuantLib::Date & referenceDate() const override
std::vector< std::vector< QuantLib::Real > > strikes() const
void initialise(const std::vector< QuantLib::Date > &dates, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Real > &values)
Initialise.
+ Here is the call graph for this function:

Member Function Documentation

◆ maxDate()

QuantLib::Date maxDate ( ) const
override

Definition at line 48 of file blackvariancesurfacesparse.hpp.

48{ return QuantLib::Date::maxDate(); }

◆ referenceDate()

const QuantLib::Date & referenceDate ( ) const
override

Definition at line 49 of file blackvariancesurfacesparse.hpp.

const QuantLib::Date & referenceDate() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dayCounter()

QuantLib::DayCounter dayCounter ( ) const
override

Definition at line 50 of file blackvariancesurfacesparse.hpp.

QuantLib::DayCounter dayCounter() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minStrike()

QuantLib::Real minStrike ( ) const
override

Definition at line 54 of file blackvariancesurfacesparse.hpp.

54{ return 0; }

◆ maxStrike()

QuantLib::Real maxStrike ( ) const
override

Definition at line 55 of file blackvariancesurfacesparse.hpp.

55{ return QL_MAX_REAL; }

◆ accept()

void accept ( QuantLib::AcyclicVisitor &  v)
overridevirtual

Definition at line 71 of file blackvariancesurfacesparse.hpp.

71 {
72 QuantLib::Visitor<BlackVarianceSurfaceSparse>* v1 =
73 dynamic_cast<QuantLib::Visitor<BlackVarianceSurfaceSparse>*>(&v);
74 if (v1 != 0)
75 v1->visit(*this);
76 else
77 QuantLib::BlackVarianceTermStructure::accept(v);
78}

◆ blackVarianceImpl()

QuantLib::Real blackVarianceImpl ( QuantLib::Time  t,
QuantLib::Real  strike 
) const
overrideprotectedvirtual

Definition at line 61 of file blackvariancesurfacesparse.cpp.

61 {
62
63 QuantLib::Time tb = times().back();
64 if (timeFlatExtrapolation_ && t > tb) {
65 return getValue(tb, strike) * t / tb;
66 } else {
67 return getValue(t, strike);
68 }
69};
QuantLib::Real getValue(QuantLib::Time t, QuantLib::Real strike) const override
+ Here is the call graph for this function:

Member Data Documentation

◆ timeFlatExtrapolation_

bool timeFlatExtrapolation_
protected

Definition at line 66 of file blackvariancesurfacesparse.hpp.