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

#include <qle/termstructures/parametricvolatility.hpp>

+ Inheritance diagram for ParametricVolatility:
+ Collaboration diagram for ParametricVolatility:

Classes

struct  MarketSmile
 

Public Types

enum class  MarketModelType { Black76 }
 
enum class  MarketQuoteType { Price , NormalVolatility , ShiftedLognormalVolatility }
 

Public Member Functions

virtual ~ParametricVolatility ()
 
 ParametricVolatility (const std::vector< MarketSmile > marketSmiles, const MarketModelType marketModelType, const MarketQuoteType inputMarketQuoteType, const QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve)
 
Real convert (const Real inputQuote, const MarketQuoteType inputMarketQuoteType, const QuantLib::Real inputLognormalShift, const boost::optional< QuantLib::Option::Type > inputOptionType, const QuantLib::Real timeToExpiry, const QuantLib::Real strike, const QuantLib::Real forward, const MarketQuoteType outputMarketQuoteType, const QuantLib::Real outputLognormalShift, const boost::optional< QuantLib::Option::Type > outputOptionType=boost::none) const
 
virtual QuantLib::Real evaluate (const QuantLib::Real timeToExpiry, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const QuantLib::Real forward, const MarketQuoteType outputMarketQuoteType, const QuantLib::Real outputLognormalShift=QuantLib::Null< QuantLib::Real >(), const boost::optional< QuantLib::Option::Type > outputOptionType=boost::none) const =0
 

Protected Attributes

std::vector< MarketSmilemarketSmiles_
 
MarketModelType marketModelType_
 
MarketQuoteType inputMarketQuoteType_
 
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_
 

Detailed Description

Definition at line 36 of file parametricvolatility.hpp.

Member Enumeration Documentation

◆ MarketModelType

enum class MarketModelType
strong
Enumerator
Black76 

Definition at line 38 of file parametricvolatility.hpp.

◆ MarketQuoteType

enum class MarketQuoteType
strong

Constructor & Destructor Documentation

◆ ~ParametricVolatility()

virtual ~ParametricVolatility ( )
virtual

Definition at line 54 of file parametricvolatility.hpp.

54{}

◆ ParametricVolatility()

ParametricVolatility ( const std::vector< MarketSmile marketSmiles,
const MarketModelType  marketModelType,
const MarketQuoteType  inputMarketQuoteType,
const QuantLib::Handle< QuantLib::YieldTermStructure >  discountCurve 
)

Definition at line 28 of file parametricvolatility.cpp.

32 : marketSmiles_(std::move(marketSmiles)), marketModelType_(marketModelType),
33 inputMarketQuoteType_(inputMarketQuoteType), discountCurve_(std::move(discountCurve)) {}
std::vector< MarketSmile > marketSmiles_
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_

Member Function Documentation

◆ convert()

Real convert ( const Real  inputQuote,
const MarketQuoteType  inputMarketQuoteType,
const QuantLib::Real  inputLognormalShift,
const boost::optional< QuantLib::Option::Type >  inputOptionType,
const QuantLib::Real  timeToExpiry,
const QuantLib::Real  strike,
const QuantLib::Real  forward,
const MarketQuoteType  outputMarketQuoteType,
const QuantLib::Real  outputLognormalShift,
const boost::optional< QuantLib::Option::Type >  outputOptionType = boost::none 
) const

Definition at line 35 of file parametricvolatility.cpp.

40 {
41
42 // determine the input and output option types
43
44 Option::Type otmOptionType = strike < forward ? Option::Put : Option::Call;
45 Option::Type inputOptionType = inputOptionTypeOpt ? *inputOptionTypeOpt : otmOptionType;
46 Option::Type outputOptionType = outputOptionTypeOpt ? *outputOptionTypeOpt : otmOptionType;
47
48 // check if there is nothing to convert
49
50 if (inputMarketQuoteType == outputMarketQuoteType && close_enough(inputLognormalShift, outputLognormalShift) &&
51 inputOptionType == outputOptionType) {
52 return inputQuote;
53 }
54
55 // otherwise compute the forward premium
56
57 Real forwardPremium;
58 switch (marketModelType_) {
60 if (inputMarketQuoteType == MarketQuoteType::Price) {
61 forwardPremium = inputQuote / (discountCurve_.empty() ? 1.0 : discountCurve_->discount(timeToExpiry));
62 } else if (inputMarketQuoteType == MarketQuoteType::NormalVolatility) {
63 forwardPremium =
64 bachelierBlackFormula(inputOptionType, strike, forward, inputQuote * std::sqrt(timeToExpiry));
65 } else if (inputMarketQuoteType == MarketQuoteType::ShiftedLognormalVolatility) {
66 if (strike < -inputLognormalShift)
67 forwardPremium = inputOptionType == Option::Call ? forward - strike : 0.0;
68 else {
69 forwardPremium = blackFormula(inputOptionType, strike, forward, inputQuote * std::sqrt(timeToExpiry),
70 1.0, inputLognormalShift);
71 }
72 } else {
73 QL_FAIL("ParametricVolatility::convert(): MarketQuoteType ("
74 << static_cast<int>(inputMarketQuoteType) << ") not handled. Internal error, contact dev.");
75 }
76 break;
77 default:
78 QL_FAIL("ParametricVolatility::convert(): MarketModelType (" << static_cast<int>(marketModelType_)
79 << ") not handled. Internal error, contact dev.");
80 }
81
82 // ... and compute the result from the forward premium
83
84 switch (marketModelType_) {
86 if (outputMarketQuoteType == MarketQuoteType::Price) {
87 return forwardPremium * (discountCurve_.empty() ? 1.0 : discountCurve_->discount(timeToExpiry));
88 } else if (outputMarketQuoteType == MarketQuoteType::NormalVolatility) {
89 return exactBachelierImpliedVolatility(outputOptionType, strike, forward, timeToExpiry, forwardPremium);
90 } else if (outputMarketQuoteType == MarketQuoteType::ShiftedLognormalVolatility) {
91 if (strike > -outputLognormalShift)
92 return blackFormulaImpliedStdDev(outputOptionType, strike, forward, forwardPremium, 1.0,
93 outputLognormalShift);
94 else
95 return 0.0;
96 } else {
97 QL_FAIL("ParametricVolatility::convert(): MarketQuoteType ("
98 << static_cast<int>(outputMarketQuoteType) << ") not handled. Internal error, contact dev.");
99 }
100 break;
101 }
102 default:
103 QL_FAIL("ParametricVolatility::convert(): MarketModelType (" << static_cast<int>(marketModelType_)
104 << ") not handled. Internal error, contact dev.");
105 }
106}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
Real exactBachelierImpliedVolatility(Option::Type optionType, Real strike, Real forward, Real tte, Real bachelierPrice, Real discount)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ evaluate()

virtual QuantLib::Real evaluate ( const QuantLib::Real  timeToExpiry,
const QuantLib::Real  underlyingLength,
const QuantLib::Real  strike,
const QuantLib::Real  forward,
const MarketQuoteType  outputMarketQuoteType,
const QuantLib::Real  outputLognormalShift = QuantLib::Null< QuantLib::Real >(),
const boost::optional< QuantLib::Option::Type >  outputOptionType = boost::none 
) const
pure virtual

Implemented in SabrParametricVolatility.

Member Data Documentation

◆ marketSmiles_

std::vector<MarketSmile> marketSmiles_
protected

Definition at line 77 of file parametricvolatility.hpp.

◆ marketModelType_

MarketModelType marketModelType_
protected

Definition at line 78 of file parametricvolatility.hpp.

◆ inputMarketQuoteType_

MarketQuoteType inputMarketQuoteType_
protected

Definition at line 79 of file parametricvolatility.hpp.

◆ discountCurve_

QuantLib::Handle<QuantLib::YieldTermStructure> discountCurve_
protected

Definition at line 80 of file parametricvolatility.hpp.