27#include <ql/handle.hpp>
28#include <ql/math/interpolation.hpp>
29#include <ql/patterns/lazyobject.hpp>
30#include <ql/quote.hpp>
31#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
37class CreditVolCurve :
public QuantLib::VolatilityTermStructure,
public QuantLib::LazyObject {
40 CreditVolCurve(QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dc,
41 const std::vector<QuantLib::Period>&
terms,
43 CreditVolCurve(
const QuantLib::Natural settlementDays,
const QuantLib::Calendar& cal,
44 QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dc,
45 const std::vector<QuantLib::Period>&
terms,
47 CreditVolCurve(
const QuantLib::Date& referenceDate,
const QuantLib::Calendar& cal,
48 QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dc,
49 const std::vector<QuantLib::Period>&
terms,
52 QuantLib::Real
volatility(
const QuantLib::Date& exerciseDate,
const QuantLib::Period& underlyingTerm,
53 const QuantLib::Real
strike,
const Type& targetType)
const;
54 virtual QuantLib::Real
volatility(
const QuantLib::Date& exerciseDate,
const QuantLib::Real underlyingLength,
55 const QuantLib::Real
strike,
const Type& targetType)
const = 0;
59 QuantLib::Real
volatility(
const QuantLib::Real exerciseTime,
const QuantLib::Real underlyingLength,
60 const QuantLib::Real
strike,
const Type& targetType)
const;
62 virtual const std::vector<QuantLib::Period>&
terms()
const;
63 virtual const std::vector<QuantLib::Handle<CreditCurve>>&
termCurves()
const;
66 QuantLib::Real
atmStrike(
const QuantLib::Date& expiry,
const QuantLib::Period& term)
const;
67 QuantLib::Real
atmStrike(
const QuantLib::Date& expiry,
const QuantLib::Real underlyingLength)
const;
69 QuantLib::Real
minStrike()
const override;
70 QuantLib::Real
maxStrike()
const override;
71 QuantLib::Date
maxDate()
const override;
75 void update()
override { LazyObject::update(); }
80 std::vector<QuantLib::Period>
terms_;
90 QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dc,
91 const std::vector<QuantLib::Period>&
terms,
92 const std::vector<QuantLib::Handle<CreditCurve>>&
termCurves,
93 const std::map<std::tuple<QuantLib::Date, QuantLib::Period, QuantLib::Real>,
94 QuantLib::Handle<QuantLib::Quote>>& quotes,
97 QuantLib::BusinessDayConvention bdc,
const QuantLib::DayCounter& dc,
98 const std::vector<QuantLib::Period>&
terms,
99 const std::vector<QuantLib::Handle<CreditCurve>>&
termCurves,
100 const std::map<std::tuple<QuantLib::Date, QuantLib::Period, QuantLib::Real>,
101 QuantLib::Handle<QuantLib::Quote>>& quotes,
104 QuantLib::Real
volatility(
const QuantLib::Date& exerciseDate,
const QuantLib::Real underlyingLength,
105 const QuantLib::Real
strike,
const Type& targetType)
const override;
108 using Smile = std::pair<QuantLib::Real, QuantLib::ext::shared_ptr<QuantLib::Interpolation>>;
109 using Key = std::pair<QuantLib::Date, QuantLib::Period>;
113 void createSmile(
const QuantLib::Date& expiry,
const QuantLib::Period& term,
const QuantLib::Date& expiry_m,
114 const QuantLib::Date& expiry_p)
const;
116 std::map<std::tuple<QuantLib::Date, QuantLib::Period, QuantLib::Real>, QuantLib::Handle<QuantLib::Quote>>
quotes_;
123 mutable std::map<Key, std::vector<QuantLib::Real>>
strikes_;
124 mutable std::map<Key, std::vector<QuantLib::Real>>
vols_;
131 ProxyCreditVolCurve(
const QuantLib::Handle<CreditVolCurve>& source,
const std::vector<QuantLib::Period>&
terms = {},
132 const std::vector<QuantLib::Handle<CreditCurve>>&
termCurves = {});
133 QuantLib::Real
volatility(
const QuantLib::Date& exerciseDate,
const QuantLib::Real underlyingLength,
134 const QuantLib::Real
strike,
const Type& targetType)
const override;
146 SpreadedCreditVolCurve(
const QuantLib::Handle<CreditVolCurve> baseCurve,
const std::vector<QuantLib::Date> expiries,
147 const std::vector<QuantLib::Handle<QuantLib::Quote>> spreads,
const bool stickyMoneyness,
148 const std::vector<QuantLib::Period>&
terms = {},
149 const std::vector<QuantLib::Handle<CreditCurve>>&
termCurves = {});
151 QuantLib::Real
volatility(
const QuantLib::Date& exerciseDate,
const QuantLib::Real underlyingLength,
152 const QuantLib::Real
strike,
const Type& targetType)
const override;
161 std::vector<QuantLib::Handle<QuantLib::Quote>>
spreads_;
164 mutable std::vector<QuantLib::Real>
times_;
173 QuantLib::Real
volatility(
const QuantLib::Date& exerciseDate,
const QuantLib::Real underlyingLength,
174 const QuantLib::Real
strike,
const Type& targetType)
const override;
179 QuantLib::Handle<QuantLib::BlackVolTermStructure>
vol_;
185 const QuantLib::Real underlyingLength);
188 QuantLib::Real
minStrike()
const override;
189 QuantLib::Real
maxStrike()
const override;
190 QuantLib::Date
maxDate()
const override;
193 QuantLib::Real
blackVolImpl(QuantLib::Real t, QuantLib::Real strike)
const override;
194 QuantLib::Handle<QuantExt::CreditVolCurve>
vol_;
QuantLib::Handle< QuantExt::CreditVolCurve > vol_
QuantLib::Real blackVolImpl(QuantLib::Real t, QuantLib::Real strike) const override
const QuantLib::Date & referenceDate() const override
QuantLib::Real minStrike() const override
QuantLib::Date maxDate() const override
QuantLib::Real underlyingLength_
QuantLib::Real maxStrike() const override
void performCalculations() const override
QuantLib::Real moneyness(const QuantLib::Real strike, const QuantLib::Real atmStrike) const
QuantLib::Real atmStrike(const QuantLib::Date &expiry, const QuantLib::Real underlyingLength) const
std::map< std::pair< QuantLib::Date, double >, double > atmStrikeCache_
virtual QuantLib::Real volatility(const QuantLib::Date &exerciseDate, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const Type &targetType) const =0
QuantLib::Real atmStrike(const QuantLib::Date &expiry, const QuantLib::Period &term) const
QuantLib::Real minStrike() const override
std::vector< QuantLib::Handle< CreditCurve > > termCurves_
CreditVolCurve(const QuantLib::Natural settlementDays, const QuantLib::Calendar &cal, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc, const std::vector< QuantLib::Period > &terms, const std::vector< QuantLib::Handle< CreditCurve > > &termCurves, const Type &type)
CreditVolCurve(QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc, const std::vector< QuantLib::Period > &terms, const std::vector< QuantLib::Handle< CreditCurve > > &termCurves, const Type &type)
QuantLib::Real volatility(const QuantLib::Date &exerciseDate, const QuantLib::Period &underlyingTerm, const QuantLib::Real strike, const Type &targetType) const
QuantLib::Real strike(const QuantLib::Real moneyness, const QuantLib::Real atmStrike) const
std::vector< QuantLib::Period > terms_
virtual const std::vector< QuantLib::Handle< CreditCurve > > & termCurves() const
QuantLib::Date maxDate() const override
CreditVolCurve(const QuantLib::Date &referenceDate, const QuantLib::Calendar &cal, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc, const std::vector< QuantLib::Period > &terms, const std::vector< QuantLib::Handle< CreditCurve > > &termCurves, const Type &type)
const Type & type() const
QuantLib::Real volatility(const QuantLib::Real exerciseTime, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const Type &targetType) const
QuantLib::Real maxStrike() const override
virtual const std::vector< QuantLib::Period > & terms() const
const QuantLib::Date & referenceDate() const override
QuantLib::Real volatility(const QuantLib::Date &exerciseDate, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const Type &targetType) const override
QuantLib::Handle< QuantLib::BlackVolTermStructure > vol_
std::vector< QuantLib::Date > smileExpiries_
std::map< Key, std::vector< QuantLib::Real > > strikes_
std::map< Key, std::vector< QuantLib::Real > > vols_
void performCalculations() const override
std::pair< QuantLib::Date, QuantLib::Period > Key
std::map< Key, Smile > smiles_
std::pair< QuantLib::Real, QuantLib::ext::shared_ptr< QuantLib::Interpolation > > Smile
QuantLib::Real volatility(const QuantLib::Date &exerciseDate, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const Type &targetType) const override
std::vector< QuantLib::Real > smileTermLengths_
InterpolatingCreditVolCurve(const QuantLib::Natural settlementDays, const QuantLib::Calendar &cal, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc, const std::vector< QuantLib::Period > &terms, const std::vector< QuantLib::Handle< CreditCurve > > &termCurves, const std::map< std::tuple< QuantLib::Date, QuantLib::Period, QuantLib::Real >, QuantLib::Handle< QuantLib::Quote > > "es, const Type &type)
InterpolatingCreditVolCurve(const QuantLib::Date &referenceDate, const QuantLib::Calendar &cal, QuantLib::BusinessDayConvention bdc, const QuantLib::DayCounter &dc, const std::vector< QuantLib::Period > &terms, const std::vector< QuantLib::Handle< CreditCurve > > &termCurves, const std::map< std::tuple< QuantLib::Date, QuantLib::Period, QuantLib::Real >, QuantLib::Handle< QuantLib::Quote > > "es, const Type &type)
std::vector< QuantLib::Real > smileExpiryTimes_
std::map< std::tuple< QuantLib::Date, QuantLib::Period, QuantLib::Real >, QuantLib::Handle< QuantLib::Quote > > quotes_
std::vector< QuantLib::Period > smileTerms_
void createSmile(const QuantLib::Date &expiry, const QuantLib::Period &term, const QuantLib::Date &expiry_m, const QuantLib::Date &expiry_p) const
QuantLib::Real volatility(const QuantLib::Date &exerciseDate, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const Type &targetType) const override
const QuantLib::Date & referenceDate() const override
QuantLib::Handle< CreditVolCurve > source_
void performCalculations() const override
std::vector< QuantLib::Handle< QuantLib::Quote > > spreads_
QuantLib::ext::shared_ptr< QuantLib::Interpolation > interpolatedSpreads_
const QuantLib::Date & referenceDate() const override
QuantLib::Real volatility(const QuantLib::Date &exerciseDate, const QuantLib::Real underlyingLength, const QuantLib::Real strike, const Type &targetType) const override
std::vector< QuantLib::Real > spreadValues_
std::vector< QuantLib::Real > times_
std::vector< QuantLib::Date > expiries_
const bool stickyMoneyness_
QuantLib::Handle< CreditVolCurve > baseCurve_
wrapper for default curves, adding (index) reference data