QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
piecewiseyoyoptionletvolatility.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 Chris Kenyon
5 Copyright (C) 2011 Ferdinando Ametrano
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file piecewiseyoyoptionletvolatility.hpp
22 \brief piecewise yoy inflation volatility term structure
23*/
24
25#ifndef quantlib_piecewise_yoy_optionlet_volatility_hpp
26#define quantlib_piecewise_yoy_optionlet_volatility_hpp
27
31#include <utility>
32
33namespace QuantLib {
34
35 //! traits for inflation-volatility bootstrap
37 public:
39
40 // start of curve data
42 return s->baseDate();
43 }
44 // value at reference date
46 return s->baseLevel(); // REALLLYYYY important because
47 // generally don't have a clue
48 // what this should be - embodies
49 // assumptions on early options
50 // that are _not_ quoted
51 }
52
53 // guesses
54 template <class C>
55 static Real guess(Size i,
56 const C* c,
57 bool validData,
58 Size) // firstAliveHelper
59 {
60 if (validData) // previous iteration value
61 return c->data()[i];
62
63 if (i==1) // first pillar
64 return 0.005;
65
66 // could/should extrapolate
67 return 0.002;
68 }
69
70 // constraints
71 template <class C>
73 const C* c,
74 bool,
75 Size) // firstAliveHelper
76 {
77 return std::max(0.0, c->data()[i-1] - 0.02); // vol cannot be negative
78 }
79 template <class C>
81 const C* c,
82 bool,
83 Size) // firstAliveHelper
84 {
85 return c->data()[i-1] + 0.02;
86 }
87
88 // root-finding update
89 static void updateGuess(std::vector<Real> &vols,
90 Real level,
91 Size i) {
92 vols[i] = level;
93 }
94 // upper bound for convergence loop
95 static Size maxIterations() {return 25;}
96 };
97
98
99 //! Piecewise year-on-year inflation volatility term structure
100 /*! We use a flat smile for bootstrapping at constant K. Happily
101 most of the work has already been done in the bootstrapping
102 classes. We only need to add special attention for the start
103 where there is usually no data, only assumptions.
104 */
105 template <class Interpolator,
106 template <class> class Bootstrap = IterativeBootstrap,
107 class Traits = YoYInflationVolatilityTraits>
109 : public InterpolatedYoYOptionletVolatilityCurve<Interpolator>,
110 public LazyObject {
111 private:
114 typedef PiecewiseYoYOptionletVolatilityCurve<Interpolator,
115 Bootstrap,
116 Traits> this_curve;
117 public:
118 typedef Traits traits_type;
119 typedef Interpolator interpolator_type;
120
123 const Calendar& cal,
125 const DayCounter& dc,
126 const Period& lag,
131 Volatility baseYoYVolatility,
132 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
133 Real accuracy = 1.0e-12,
134 const Interpolator& interpolator = Interpolator())
136 cal,
137 bdc,
138 dc,
139 lag,
140 frequency,
142 minStrike,
143 maxStrike,
144 baseYoYVolatility,
145 interpolator),
146 instruments_(std::move(instruments)), accuracy_(accuracy) {
147 bootstrap_.setup(this);
148 }
149
150 //! \name Inflation interface
151 //@{
152 Date baseDate() const override;
153 Date maxDate() const override;
154 //@
155 //! \name Inspectors
156 //@{
157 const std::vector<Time>& times() const override;
158 const std::vector<Date>& dates() const override;
159 const std::vector<Real>& data() const override;
160 std::vector<std::pair<Date, Real> > nodes() const override;
161 //@}
162 //! \name Observer interface
163 //@{
164 void update() override;
165 //@}
166 private:
167 // methods
168 void performCalculations() const override;
169 // data members
170 std::vector<ext::shared_ptr<typename Traits::helper> > instruments_;
172
173 friend class Bootstrap<this_curve>;
174 friend class BootstrapError<this_curve>;
176 };
177
178
179 // inline and template definitions
180
181 template <class I, template <class> class B, class T>
183 this->calculate();
184 return base_curve::baseDate();
185 }
186
187 template <class I, template <class> class B, class T>
189 this->calculate();
190 return base_curve::maxDate();
191 }
192
193 template <class I, template <class> class B, class T>
194 const std::vector<Time>&
196 calculate();
197 return base_curve::times();
198 }
199
200 template <class I, template <class> class B, class T>
201 const std::vector<Date>&
203 calculate();
204 return base_curve::dates();
205 }
206
207 template <class I, template <class> class B, class T>
208 const std::vector<Real>&
210 calculate();
211 return base_curve::data();
212 }
213
214 template <class I, template <class> class B, class T>
215 std::vector<std::pair<Date, Real> >
217 calculate();
218 return base_curve::nodes();
219 }
220
221 template <class I, template <class> class B, class T>
222 void
224 bootstrap_.calculate();
225 }
226
227 template <class I, template <class> class B, class T>
229 base_curve::update();
231 }
232
233}
234
235#endif
Base helper class for bootstrapping.
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Real minStrike() const override
the minimum strike for which the term structure can return vols
Real maxStrike() const override
the maximum strike for which the term structure can return vols
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
void update() override
Definition: lazyobject.hpp:188
Piecewise year-on-year inflation volatility term structure.
std::vector< std::pair< Date, Real > > nodes() const override
const std::vector< Time > & times() const override
const std::vector< Real > & data() const override
std::vector< ext::shared_ptr< typename Traits::helper > > instruments_
Date maxDate() const override
the latest date for which the curve can return values
PiecewiseYoYOptionletVolatilityCurve(Natural settlementDays, const Calendar &cal, BusinessDayConvention bdc, const DayCounter &dc, const Period &lag, Frequency frequency, bool indexIsInterpolated, Rate minStrike, Rate maxStrike, Volatility baseYoYVolatility, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, Real accuracy=1.0e-12, const Interpolator &interpolator=Interpolator())
PiecewiseYoYOptionletVolatilityCurve< Interpolator, Bootstrap, Traits > this_curve
InterpolatedYoYOptionletVolatilityCurve< Interpolator > base_curve
const std::vector< Date > & dates() const override
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
traits for inflation-volatility bootstrap
static Real maxValueAfter(Size i, const C *c, bool, Size)
static Real guess(Size i, const C *c, bool validData, Size)
static Date initialDate(const YoYOptionletVolatilitySurface *s)
static Real minValueAfter(Size i, const C *c, bool, Size)
static void updateGuess(std::vector< Real > &vols, Real level, Size i)
static Real initialValue(const YoYOptionletVolatilitySurface *s)
BootstrapHelper< YoYOptionletVolatilitySurface > helper
Frequency
Frequency of events.
Definition: frequency.hpp:37
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
universal piecewise-term-structure boostrapper.
framework for calculation on demand and result caching
Definition: any.hpp:35
STL namespace.
experimental yoy inflation volatility structures