Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
piecewiseoptionletstripper.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/termstructures/piecewiseoptionletstripper.hpp
20 \brief Strip optionlet volatility surface from cap floor volatility term surface
21*/
22
23#ifndef quantext_piecewiseoptionletstripper_hpp
24#define quantext_piecewiseoptionletstripper_hpp
25
30
31namespace QuantExt {
32
33/*! Helper class to strip optionlet (i.e. caplet/floorlet) volatilities from the cap floor term volatilities of a
34 CapFloorTermVolSurface.
35*/
36template <class Interpolator, template <class> class Bootstrap = QuantExt::IterativeBootstrap>
38
39public:
41
42 PiecewiseOptionletStripper(const QuantLib::ext::shared_ptr<QuantExt::CapFloorTermVolSurface>& capFloorSurface,
43 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index,
44 const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
45 bool flatFirstPeriod = true,
46 const QuantLib::VolatilityType capFloorVolType = QuantLib::ShiftedLognormal,
47 const QuantLib::Real capFloorVolDisplacement = 0.0,
48 const boost::optional<VolatilityType> optionletVolType = boost::none,
49 const boost::optional<QuantLib::Real> optionletVolDisplacement = boost::none,
50 bool interpOnOptionlets = true, const Interpolator& i = Interpolator(),
51 const Bootstrap<optionlet_curve>& bootstrap = Bootstrap<optionlet_curve>(),
52 const Period& rateComputationPeriod = 0 * Days, const Size onCapSettlementDays = 0);
53
54 //! \name Inspectors
55 //@{
56 //! Volatility type for the underlying cap floor matrix
57 QuantLib::VolatilityType capFloorVolType() const { return capFloorVolType_; }
58
59 //! The applicable shift if the underlying cap floor matrix has shifted lognormal volatility
60 QuantLib::Real capFloorVolDisplacement() const { return capFloorVolDisplacement_; }
61
62 //! \name LazyObject interface
63 //@{
64 void performCalculations() const override;
65 //@}
66
67private:
68 //! Flat optionlet volatility before first optionlet fixing date
70
71 //! Volatility type for the underlying cap floor matrix
72 QuantLib::VolatilityType capFloorVolType_;
73
74 //! The applicable shift if the underlying cap floor matrix has shifted lognormal volatility
76
77 //! True to interpolate on optionlet volatilities, false to interpolate on cap floor term volatilities
79
80 //! The interpolator
81 Interpolator interpolator_;
82
83 //! The bootstrapper
84 Bootstrap<optionlet_curve> bootstrap_;
85
86 //! A one-dimensional optionlet curve for each strike in the underlying cap floor matrix
87 mutable std::vector<QuantLib::ext::shared_ptr<optionlet_curve> > strikeCurves_;
88
89 //! Store the vector of helpers for each strike column. The first dimension is strike and second is option tenor.
90 typedef QuantLib::BootstrapHelper<QuantLib::OptionletVolatilityStructure> helper;
91 std::vector<std::vector<QuantLib::ext::shared_ptr<helper> > > helpers_;
92
93 //! Store the cap floor surface quotes. The first dimension is option tenor and second is strike.
94 std::vector<std::vector<QuantLib::ext::shared_ptr<QuantLib::SimpleQuote> > > quotes_;
95};
96
97template <class Interpolator, template <class> class Bootstrap>
99 const QuantLib::ext::shared_ptr<QuantExt::CapFloorTermVolSurface>& capFloorSurface,
100 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& index, const QuantLib::Handle<QuantLib::YieldTermStructure>& discount,
101 bool flatFirstPeriod, const QuantLib::VolatilityType capFloorVolType, const QuantLib::Real capFloorVolDisplacement,
102 const boost::optional<VolatilityType> optionletVolType,
103 const boost::optional<QuantLib::Real> optionletVolDisplacement, bool interpOnOptionlets, const Interpolator& i,
104 const Bootstrap<optionlet_curve>& bootstrap, const Period& rateComputationPeriod, const Size onCapSettlementDays)
105 : OptionletStripper(capFloorSurface, index, discount, optionletVolType ? *optionletVolType : capFloorVolType,
106 optionletVolDisplacement ? *optionletVolDisplacement : 0.0, rateComputationPeriod,
107 onCapSettlementDays),
108 flatFirstPeriod_(flatFirstPeriod), capFloorVolType_(capFloorVolType),
109 capFloorVolDisplacement_(capFloorVolDisplacement), interpOnOptionlets_(interpOnOptionlets), interpolator_(i),
110 bootstrap_(bootstrap), strikeCurves_(nStrikes_), helpers_(nStrikes_) {
111
112 // Readability
113 // typedef QuantLib::BootstrapHelper<QuantLib::OptionletVolatilityStructure> helper;
114 using QuantLib::Handle;
115 using QuantLib::Period;
116 using QuantLib::Quote;
117 using QuantLib::SimpleQuote;
118 using QuantLib::Size;
119 using std::vector;
120
121 vector<Rate> strikes = termVolSurface_->strikes();
122
123 bool isOis = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index) != nullptr;
124
125 // If we interpolate on term volatility surface first and then bootstrap, we have a cap floor helper for every
126 // optionlet maturity.
127 vector<Period> tenors = interpOnOptionlets_ ? termVolSurface_->optionTenors() : capFloorLengths_;
128 quotes_.resize(tenors.size());
129
130 // Initialise the quotes and helpers
131 for (Size j = 0; j < strikes.size(); j++) {
132 for (Size i = 0; i < tenors.size(); i++) {
133 quotes_[i].push_back(QuantLib::ext::make_shared<SimpleQuote>(termVolSurface_->volatility(tenors[i], strikes[j])));
134 if(isOis) {
135 Date effDate = index_->fixingCalendar().advance(
136 index_->fixingCalendar().adjust(capFloorSurface->referenceDate()), onCapSettlementDays_ * Days);
137 helpers_[j].push_back(QuantLib::ext::make_shared<OISCapFloorHelper>(
139 Handle<Quote>(quotes_[i].back()), QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index_), discount_,
141 } else {
142 helpers_[j].push_back(QuantLib::ext::make_shared<CapFloorHelper>(
143 CapFloorHelper::Automatic, tenors[i], strikes[j], Handle<Quote>(quotes_[i].back()), index_,
145 }
146 }
147 }
148}
149
150template <class Interpolator, template <class> class Bootstrap>
152
153 // Some localised typedefs and using declarations to make the code more readable
154 using QuantLib::Period;
155 using QuantLib::Rate;
156 using QuantLib::Size;
157 using std::vector;
158
159 // Update dates
160 populateDates();
161
162 // Readability
163 vector<Rate> strikes = termVolSurface_->strikes();
164 vector<Period> tenors = interpOnOptionlets_ ? termVolSurface_->optionTenors() : capFloorLengths_;
165
166 // Update the quotes from the cap floor term volatility surface
167 for (Size i = 0; i < tenors.size(); i++) {
168 for (Size j = 0; j < strikes.size(); j++) {
169 quotes_[i][j]->setValue(termVolSurface_->volatility(tenors[i], strikes[j]));
170 }
171 }
172
173 // Populate the strike curves
174 for (Size j = 0; j < strikes.size(); j++) {
175 strikeCurves_[j] = QuantLib::ext::make_shared<optionlet_curve>(
176 termVolSurface_->referenceDate(), helpers_[j], termVolSurface_->calendar(),
177 termVolSurface_->businessDayConvention(), termVolSurface_->dayCounter(), volatilityType_, displacement_,
178 flatFirstPeriod_, interpolator_, bootstrap_);
179 }
180
181 // Populate the optionlet volatilities and standard deviations
182 for (Size j = 0; j < strikes.size(); j++) {
183 for (Size i = 0; i < nOptionletTenors_; ++i) {
184 optionletVolatilities_[i][j] = strikeCurves_[j]->volatility(optionletDates_[i], strikes[j]);
185 }
186 }
187}
188
189} // namespace QuantExt
190
191#endif
const Period & rateComputationPeriod() const
std::vector< Period > capFloorLengths_
Handle< YieldTermStructure > discount_
ext::shared_ptr< IborIndex > index() const
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface_
ext::shared_ptr< IborIndex > index_
PiecewiseOptionletCurve< Interpolator, Bootstrap >::this_curve optionlet_curve
std::vector< QuantLib::ext::shared_ptr< optionlet_curve > > strikeCurves_
A one-dimensional optionlet curve for each strike in the underlying cap floor matrix.
PiecewiseOptionletStripper(const QuantLib::ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &capFloorSurface, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &index, const QuantLib::Handle< QuantLib::YieldTermStructure > &discount, bool flatFirstPeriod=true, const QuantLib::VolatilityType capFloorVolType=QuantLib::ShiftedLognormal, const QuantLib::Real capFloorVolDisplacement=0.0, const boost::optional< VolatilityType > optionletVolType=boost::none, const boost::optional< QuantLib::Real > optionletVolDisplacement=boost::none, bool interpOnOptionlets=true, const Interpolator &i=Interpolator(), const Bootstrap< optionlet_curve > &bootstrap=Bootstrap< optionlet_curve >(), const Period &rateComputationPeriod=0 *Days, const Size onCapSettlementDays=0)
QuantLib::VolatilityType capFloorVolType() const
Volatility type for the underlying cap floor matrix.
std::vector< std::vector< QuantLib::ext::shared_ptr< helper > > > helpers_
QuantLib::VolatilityType capFloorVolType_
Volatility type for the underlying cap floor matrix.
QuantLib::Real capFloorVolDisplacement_
The applicable shift if the underlying cap floor matrix has shifted lognormal volatility.
Bootstrap< optionlet_curve > bootstrap_
The bootstrapper.
QuantLib::BootstrapHelper< QuantLib::OptionletVolatilityStructure > helper
Store the vector of helpers for each strike column. The first dimension is strike and second is optio...
bool interpOnOptionlets_
True to interpolate on optionlet volatilities, false to interpolate on cap floor term volatilities.
std::vector< std::vector< QuantLib::ext::shared_ptr< QuantLib::SimpleQuote > > > quotes_
Store the cap floor surface quotes. The first dimension is option tenor and second is strike.
QuantLib::Real capFloorVolDisplacement() const
The applicable shift if the underlying cap floor matrix has shifted lognormal volatility.
bool flatFirstPeriod_
Flat optionlet volatility before first optionlet fixing date.
Straight copy of ql/termstructures/iterativebootstrap.hpp with minor changes.
Helper for bootstrapping optionlet volatilties from ois cap floor volatilities.
optionlet (caplet/floorlet) volatility stripper
One-dimensional curve of bootstrapped optionlet volatilities.
vector< Real > strikes