23#ifndef quantext_cap_floor_term_vol_surface_sparse_hpp
24#define quantext_cap_floor_term_vol_surface_sparse_hpp
27#include <ql/math/interpolations/bicubicsplineinterpolation.hpp>
28#include <ql/math/interpolations/bilinearinterpolation.hpp>
29#include <ql/quotes/simplequote.hpp>
30#include <ql/utilities/dataformatters.hpp>
31#include <ql/patterns/lazyobject.hpp>
32#include <ql/quote.hpp>
34#include <ql/time/daycounters/actual365fixed.hpp>
44template <
class InterpolatorStrike,
class InterpolatorExpiry>
49 CapFloorTermVolSurfaceSparse(
const QuantLib::Date& referenceDate,
const QuantLib::Calendar& calendar,
const QuantLib::BusinessDayConvention& bdc,
50 const QuantLib::DayCounter& dc,
const std::vector<QuantLib::Period>& tenors,
const std::vector<QuantLib::Real>&
strikes,
51 const std::vector<QuantLib::Volatility>& volatilities,
bool lowerStrikeConstExtrap =
true,
52 bool upperStrikeConstExtrap =
true,
bool timeFlatExtrapolation =
false);
55 CapFloorTermVolSurfaceSparse(QuantLib::Natural settlementDays,
const QuantLib::Calendar& calendar,
const QuantLib::BusinessDayConvention& bdc,
56 const QuantLib::DayCounter& dc,
const std::vector<QuantLib::Period>& tenors,
const std::vector<QuantLib::Real>&
strikes,
57 const std::vector<QuantLib::Volatility>& volatilities,
bool lowerStrikeConstExtrap =
true,
58 bool upperStrikeConstExtrap =
true,
bool timeFlatExtrapolation =
false);
62 QuantLib::Date
maxDate()
const override;
66 QuantLib::Real
minStrike()
const override;
67 QuantLib::Real
maxStrike()
const override;
75 QuantLib::Volatility
volatilityImpl(Time t, Rate strike)
const override;
79 mutable QuantLib::ext::shared_ptr<OptionInterpolator2d<InterpolatorStrike, InterpolatorExpiry>>
optionInterpolator_;
89template <
class IS,
class IE>
91 const QuantLib::BusinessDayConvention& bdc,
const QuantLib::DayCounter& dc,
const std::vector<QuantLib::Period>& tenors,
92 const std::vector<QuantLib::Real>&
strikes,
const std::vector<QuantLib::Volatility>& volatilities,
bool lowerStrikeConstExtrap,
93 bool upperStrikeConstExtrap,
bool timeFlatExtrapolation)
95 lowerStrikeConstExtrap_(lowerStrikeConstExtrap), upperStrikeConstExtrap_(upperStrikeConstExtrap) {
100template <
class IS,
class IE>
102 const QuantLib::BusinessDayConvention& bdc,
const QuantLib::DayCounter& dc,
const std::vector<QuantLib::Period>& tenors,
103 const std::vector<QuantLib::Real>&
strikes,
const std::vector<QuantLib::Volatility>& volatilities,
bool lowerStrikeConstExtrap,
104 bool upperStrikeConstExtrap,
bool timeFlatExtrapolation)
106 lowerStrikeConstExtrap_(lowerStrikeConstExtrap), upperStrikeConstExtrap_(upperStrikeConstExtrap) {
111template <
class IS,
class IE>
114 for (
auto t : allTenors_) {
116 auto fnd = find(optionTenors_.begin(), optionTenors_.end(), t);
117 if (fnd == optionTenors_.end()) {
118 optionTenors_.push_back(t);
122 std::sort(optionTenors_.begin(), optionTenors_.end());
124 for (
auto s : allStrikes_) {
125 std::vector<Real>::iterator fnd =
127 if (fnd == strikes_.end()) {
128 strikes_.push_back(s);
132 std::sort(strikes_.begin(), strikes_.end());
135 performCalculations();
138template <
class IS,
class IE>
140 return optionDateFromTenor(optionTenors().back());
143template <
class IS,
class IE>
146template <
class IS,
class IE>
149template <
class IS,
class IE>
151 return optionInterpolator_->getValue(t, strike);
154template <
class IS,
class IE>
156 optionInterpolator_ = QuantLib::ext::make_shared<OptionInterpolator2d<IS, IE>>(referenceDate(), calendar(), businessDayConvention(), dayCounter(),
157 allTenors_, allStrikes_, allVols_, lowerStrikeConstExtrap_, upperStrikeConstExtrap_);
Cap/floor smile volatility surface.
Cap/floor term-volatility surface.
const std::vector< QuantLib::Rate > & strikes() const
Cap/floor smile volatility surface sparse.
void performCalculations() const override
CapFloorTermVolSurfaceSparse(const QuantLib::Date &referenceDate, const QuantLib::Calendar &calendar, const QuantLib::BusinessDayConvention &bdc, const QuantLib::DayCounter &dc, const std::vector< QuantLib::Period > &tenors, const std::vector< QuantLib::Real > &strikes, const std::vector< QuantLib::Volatility > &volatilities, bool lowerStrikeConstExtrap=true, bool upperStrikeConstExtrap=true, bool timeFlatExtrapolation=false)
fixed reference date, fixed market data
bool upperStrikeConstExtrap_
std::vector< QuantLib::Period > allTenors_
void initialiseStrikesTenors()
std::vector< QuantLib::Real > allStrikes_
QuantLib::Real minStrike() const override
std::vector< QuantLib::Volatility > allVols_
QuantLib::Real maxStrike() const override
QuantLib::Date maxDate() const override
QuantLib::ext::shared_ptr< OptionInterpolator2d< InterpolatorStrike, InterpolatorExpiry > > optionInterpolator_
bool lowerStrikeConstExtrap_
QuantLib::Volatility volatilityImpl(Time t, Rate strike) const override