Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
capfloorhelper.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/capfloorhelper.hpp
20 \brief Helper for bootstrapping optionlet volatilities from cap floor volatilities
21 \ingroup termstructures
22*/
23
24#ifndef quantext_cap_floor_helper_hpp
25#define quantext_cap_floor_helper_hpp
26
27#include <ql/instruments/capfloor.hpp>
28#include <ql/termstructures/bootstraphelper.hpp>
29#include <ql/termstructures/volatility/optionlet/optionletvolatilitystructure.hpp>
30
31namespace QuantExt {
32
33/*! Helper for bootstrapping optionlet volatilities from cap floor volatilities. The helper has a date schedule that is
34 relative to the global evaluation date.
35
36 \ingroup termstructures
37*/
38class CapFloorHelper : public QuantLib::RelativeDateBootstrapHelper<QuantLib::OptionletVolatilityStructure> {
39
40public:
41 /*! Enum to indicate whether the instrument underlying the helper is a Cap, a Floor or should be chosen
42 automatically. If Automatic is chosen and the quote type is volatility, the instrument's ATM rate is queried
43 and if it is greater than the strike, the instrument is a Floor otherwise it is a Cap.
44 */
45 enum Type { Cap, Floor, Automatic };
46
47 //! Enum to indicate the type of the quote provided with the CapFloorHelper
49
50 /*! Constructor
51 \param type The CapFloorHelper type as described above
52 \param tenor The underlying cap floor instrument's tenor
53 \param strike The underlying cap floor instrument's strike. Setting this to \c Null<Real>()
54 indicates that the ATM strike for the given \p tenor should be used.
55 \param quote The quoted premium or implied volatility for the underlying cap floor instrument
56 \param iborIndex The IborIndex underlying the cap floor instrument
57 \param discountingCurve The curve used for discounting the cap floor instrument cashflows
58 \param moving If this is \c true, the helper's schedule is relative to the global evaluation date
59 and is updated if the global evaluation date is updated. If \c false, the helper
60 has a fixed schedule relative to the \p effectiveDate that does not change with
61 changes in the global evaluation date.
62 \param effectiveDate The effective date of the underlying cap floor instrument. If this is the empty
63 \c QuantLib::Date(), the effective date is determined from the global evaluation
64 date.
65 \param quoteType The quote type
66 \param quoteVolatilityType If the quote type is \c Volatility, this indicates the volatility type of the quote
67 \param quoteDisplacement If the quote type is \c Volatility and the volatility type is \c ShiftedLognormal,
68 this provides the shift size associated with the quote.
69 \param endOfMonth Whether or not to use end of month adjustment when generating the cap floor schedule
70 \param firstCapletExcluded Whether or not to exclude the first caplet in the underlying cap floor instrument
71 */
72 CapFloorHelper(Type type, const QuantLib::Period& tenor, QuantLib::Rate strike,
73 const QuantLib::Handle<QuantLib::Quote>& quote,
74 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& iborIndex,
75 const QuantLib::Handle<QuantLib::YieldTermStructure>& discountingCurve, bool moving = true,
76 const QuantLib::Date& effectiveDate = QuantLib::Date(), QuoteType quoteType = Premium,
77 QuantLib::VolatilityType quoteVolatilityType = QuantLib::Normal,
78 QuantLib::Real quoteDisplacement = 0.0, bool endOfMonth = false, bool firstCapletExcluded = true);
79
80 //! \name Inspectors
81 //@{
82 //! Return the cap floor instrument underlying the helper
83 QuantLib::ext::shared_ptr<QuantLib::CapFloor> capFloor() const { return capFloor_; }
84 //@}
85
86 //! \name BootstrapHelper interface
87 //@{
88 //! Returns the \p capFloor_ instrument's premium
89 QuantLib::Real impliedQuote() const override;
90
91 //! Sets the helper's OptionletVolatilityStructure to \p ovts and sets up the pricing engine for \c capFloor_
92 void setTermStructure(QuantLib::OptionletVolatilityStructure* ovts) override;
93 //@}
94
95 //! \name Visitability
96 //@{
97 void accept(QuantLib::AcyclicVisitor&) override;
98 //@}
99
100private:
101 //! RelativeDateBootstrapHelper interface
102 void initializeDates() override;
103
104 // Details needed to construct the instrument
106 QuantLib::Period tenor_;
107 QuantLib::Rate strike_;
108 QuantLib::ext::shared_ptr<QuantLib::IborIndex> iborIndex_;
109 QuantLib::Handle<QuantLib::YieldTermStructure> discountHandle_;
111 QuantLib::Date effectiveDate_;
113 QuantLib::VolatilityType quoteVolatilityType_;
114 QuantLib::Real quoteDisplacement_;
117 QuantLib::Handle<QuantLib::Quote> rawQuote_;
119
120 //! The underlying instrument
121 QuantLib::ext::shared_ptr<QuantLib::CapFloor> capFloor_;
122
123 //! The OptionletVolatilityStructure Handle that we link to the \c capFloor_ instrument
124 QuantLib::RelinkableHandle<QuantLib::OptionletVolatilityStructure> ovtsHandle_;
125
126 //! A copy of the underlying instrument that is used in the npv method
127 QuantLib::ext::shared_ptr<QuantLib::CapFloor> capFloorCopy_;
128
129 //! A method to calculate the cap floor premium from a flat cap floor volatility value
130 QuantLib::Real npv(QuantLib::Real quote);
131};
132
133//! In order to convert CapFloorHelper::Type to string
134std::ostream& operator<<(std::ostream& out, CapFloorHelper::Type type);
135
136//! In order to convert CapFloorHelper::QuoteType to string
137std::ostream& operator<<(std::ostream& out, CapFloorHelper::QuoteType type);
138
139} // namespace QuantExt
140
141#endif
QuantLib::Handle< QuantLib::Quote > rawQuote_
QuantLib::Real npv(QuantLib::Real quote)
A method to calculate the cap floor premium from a flat cap floor volatility value.
void accept(QuantLib::AcyclicVisitor &) override
QuantLib::ext::shared_ptr< QuantLib::IborIndex > iborIndex_
QuantLib::Real quoteDisplacement_
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloorCopy_
A copy of the underlying instrument that is used in the npv method.
void initializeDates() override
RelativeDateBootstrapHelper interface.
void setTermStructure(QuantLib::OptionletVolatilityStructure *ovts) override
Sets the helper's OptionletVolatilityStructure to ovts and sets up the pricing engine for capFloor_.
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor_
The underlying instrument.
QuoteType
Enum to indicate the type of the quote provided with the CapFloorHelper.
QuantLib::Real impliedQuote() const override
Returns the capFloor_ instrument's premium.
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor() const
Return the cap floor instrument underlying the helper.
QuantLib::VolatilityType quoteVolatilityType_
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
The OptionletVolatilityStructure Handle that we link to the capFloor_ instrument.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)